42#include "MagickCore/studio.h"
43#include "MagickCore/animate.h"
44#include "MagickCore/artifact.h"
45#include "MagickCore/blob.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/client.h"
48#include "MagickCore/color.h"
49#include "MagickCore/color-private.h"
50#include "MagickCore/colormap.h"
51#include "MagickCore/composite.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/display.h"
54#include "MagickCore/distort.h"
55#include "MagickCore/exception.h"
56#include "MagickCore/exception-private.h"
57#include "MagickCore/geometry.h"
58#include "MagickCore/identify.h"
59#include "MagickCore/image.h"
60#include "MagickCore/image-private.h"
61#include "MagickCore/list.h"
62#include "MagickCore/locale_.h"
63#include "MagickCore/log.h"
64#include "MagickCore/magick.h"
65#include "MagickCore/memory_.h"
66#include "MagickCore/memory-private.h"
67#include "MagickCore/monitor.h"
68#include "MagickCore/nt-base-private.h"
69#include "MagickCore/option.h"
70#include "MagickCore/pixel-accessor.h"
71#include "MagickCore/quantize.h"
72#include "MagickCore/quantum.h"
73#include "MagickCore/quantum-private.h"
74#include "MagickCore/resource_.h"
75#include "MagickCore/resize.h"
76#include "MagickCore/statistic.h"
77#include "MagickCore/string_.h"
78#include "MagickCore/string-private.h"
79#include "MagickCore/transform.h"
80#include "MagickCore/transform-private.h"
81#include "MagickCore/token.h"
82#include "MagickCore/utility.h"
83#include "MagickCore/utility-private.h"
84#include "MagickCore/widget.h"
85#include "MagickCore/widget-private.h"
86#include "MagickCore/xwindow.h"
87#include "MagickCore/xwindow-private.h"
88#include "MagickCore/version.h"
92#if defined(MAGICKCORE_X11_DELEGATE)
93#include <X11/Xproto.h>
94#include <X11/Xlocale.h>
95#if defined(MAGICK_HAVE_POLL)
98#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
99#if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
100# include <machine/param.h>
104#include <X11/extensions/XShm.h>
106#if defined(MAGICKCORE_HAVE_SHAPE)
107#include <X11/extensions/shape.h>
113#define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
114 (color) : ((pow((QuantumScale*(double) (color)),1.0* \
115 PerceptibleReciprocal((double) blue_gamma))*(double) QuantumRange)))
116#define XGammaPacket(map,color) (size_t) (map->base_pixel+ \
117 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
119 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
121 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
123#define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \
124 ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
126 ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
128 ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
130#define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
131 (color) : ((pow((QuantumScale*(double) (color)),1.0* \
132 PerceptibleReciprocal((double) green_gamma))*(double) QuantumRange)))
133#define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
134 (color) : ((pow((QuantumScale*(double) (color)),1.0* \
135 PerceptibleReciprocal((double) red_gamma))*(double) QuantumRange)))
136#define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
137 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
138 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
139 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
141#define AccentuateModulate ScaleCharToQuantum(80)
142#define HighlightModulate ScaleCharToQuantum(125)
143#define ShadowModulate ScaleCharToQuantum(135)
144#define DepthModulate ScaleCharToQuantum(185)
145#define TroughModulate ScaleCharToQuantum(110)
147#define XLIB_ILLEGAL_ACCESS 1
149#undef NorthWestGravity
151#undef NorthEastGravity
155#undef SouthWestGravity
157#undef SouthEastGravity
164#define XFD_SET fd_set
184typedef struct _DiversityPacket
201static MagickBooleanType
202 xerror_alert = MagickFalse;
208 *XVisualClassName(
const int);
215static MagickBooleanType
216 XMakePixmap(Display *,
const XResourceInfo *,XWindowInfo *);
219 XMakeImageLSBFirst(
const XResourceInfo *,
const XWindowInfo *,
Image *,
221 XMakeImageMSBFirst(
const XResourceInfo *,
const XWindowInfo *,
Image *,
247MagickExport
void DestroyXResources(
void)
256 *magick_windows[MaxXWindows];
262 windows=XSetWindows((XWindows *) ~0);
263 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
266 magick_windows[number_windows++]=(&windows->context);
267 magick_windows[number_windows++]=(&windows->group_leader);
268 magick_windows[number_windows++]=(&windows->backdrop);
269 magick_windows[number_windows++]=(&windows->icon);
270 magick_windows[number_windows++]=(&windows->image);
271 magick_windows[number_windows++]=(&windows->info);
272 magick_windows[number_windows++]=(&windows->magnify);
273 magick_windows[number_windows++]=(&windows->pan);
274 magick_windows[number_windows++]=(&windows->command);
275 magick_windows[number_windows++]=(&windows->widget);
276 magick_windows[number_windows++]=(&windows->popup);
277 for (i=0; i < (int) number_windows; i++)
279 if (magick_windows[i]->mapped != MagickFalse)
281 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
282 magick_windows[i]->screen);
283 magick_windows[i]->mapped=MagickFalse;
285 if (magick_windows[i]->name != (
char *) NULL)
286 magick_windows[i]->name=(
char *)
287 RelinquishMagickMemory(magick_windows[i]->name);
288 if (magick_windows[i]->icon_name != (
char *) NULL)
289 magick_windows[i]->icon_name=(
char *)
290 RelinquishMagickMemory(magick_windows[i]->icon_name);
291 if (magick_windows[i]->cursor != (Cursor) NULL)
293 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
294 magick_windows[i]->cursor=(Cursor) NULL;
296 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
298 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
299 magick_windows[i]->busy_cursor=(Cursor) NULL;
301 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
303 (void) XFreePixmap(windows->display,
304 magick_windows[i]->highlight_stipple);
305 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
307 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
309 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
310 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
312 if (magick_windows[i]->matte_image != (XImage *) NULL)
314 XDestroyImage(magick_windows[i]->matte_image);
315 magick_windows[i]->matte_image=(XImage *) NULL;
317 if (magick_windows[i]->ximage != (XImage *) NULL)
319 XDestroyImage(magick_windows[i]->ximage);
320 magick_windows[i]->ximage=(XImage *) NULL;
322 if (magick_windows[i]->pixmap != (Pixmap) NULL)
324 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
325 magick_windows[i]->pixmap=(Pixmap) NULL;
327 if (magick_windows[i]->
id != (Window) NULL)
329 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
330 magick_windows[i]->id=(Window) NULL;
332 if (magick_windows[i]->destroy != MagickFalse)
334 if (magick_windows[i]->image != (
Image *) NULL)
336 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
337 magick_windows[i]->image=NewImageList();
339 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
341 (void) XFreePixmap(windows->display,
342 magick_windows[i]->matte_pixmap);
343 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
346 if (magick_windows[i]->segment_info != (
void *) NULL)
348#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
352 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
353 if (segment_info != (XShmSegmentInfo *) NULL)
354 if (segment_info[0].shmid >= 0)
356 if (segment_info[0].shmaddr != NULL)
357 (void) shmdt(segment_info[0].shmaddr);
358 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
359 segment_info[0].shmaddr=NULL;
360 segment_info[0].shmid=(-1);
363 magick_windows[i]->segment_info=(
void *)
364 RelinquishMagickMemory(magick_windows[i]->segment_info);
367 windows->icon_resources=(XResourceInfo *)
368 RelinquishMagickMemory(windows->icon_resources);
369 if (windows->icon_pixel != (XPixelInfo *) NULL)
371 if (windows->icon_pixel->pixels != (
unsigned long *) NULL)
372 windows->icon_pixel->pixels=(
unsigned long *)
373 RelinquishMagickMemory(windows->icon_pixel->pixels);
374 if (windows->icon_pixel->annotate_context != (GC) NULL)
375 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
376 windows->icon_pixel=(XPixelInfo *)
377 RelinquishMagickMemory(windows->icon_pixel);
379 if (windows->pixel_info != (XPixelInfo *) NULL)
381 if (windows->pixel_info->pixels != (
unsigned long *) NULL)
382 windows->pixel_info->pixels=(
unsigned long *)
383 RelinquishMagickMemory(windows->pixel_info->pixels);
384 if (windows->pixel_info->annotate_context != (GC) NULL)
385 XFreeGC(windows->display,windows->pixel_info->annotate_context);
386 if (windows->pixel_info->widget_context != (GC) NULL)
387 XFreeGC(windows->display,windows->pixel_info->widget_context);
388 if (windows->pixel_info->highlight_context != (GC) NULL)
389 XFreeGC(windows->display,windows->pixel_info->highlight_context);
390 windows->pixel_info=(XPixelInfo *)
391 RelinquishMagickMemory(windows->pixel_info);
393 if (windows->font_info != (XFontStruct *) NULL)
395 XFreeFont(windows->display,windows->font_info);
396 windows->font_info=(XFontStruct *) NULL;
398 if (windows->class_hints != (XClassHint *) NULL)
400 if (windows->class_hints->res_name != (
char *) NULL)
401 windows->class_hints->res_name=DestroyString(
402 windows->class_hints->res_name);
403 if (windows->class_hints->res_class != (
char *) NULL)
404 windows->class_hints->res_class=DestroyString(
405 windows->class_hints->res_class);
406 XFree(windows->class_hints);
407 windows->class_hints=(XClassHint *) NULL;
409 if (windows->manager_hints != (XWMHints *) NULL)
411 XFree(windows->manager_hints);
412 windows->manager_hints=(XWMHints *) NULL;
414 if (windows->map_info != (XStandardColormap *) NULL)
416 XFree(windows->map_info);
417 windows->map_info=(XStandardColormap *) NULL;
419 if (windows->icon_map != (XStandardColormap *) NULL)
421 XFree(windows->icon_map);
422 windows->icon_map=(XStandardColormap *) NULL;
424 if (windows->visual_info != (XVisualInfo *) NULL)
426 XFree(windows->visual_info);
427 windows->visual_info=(XVisualInfo *) NULL;
429 if (windows->icon_visual != (XVisualInfo *) NULL)
431 XFree(windows->icon_visual);
432 windows->icon_visual=(XVisualInfo *) NULL;
469MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
470 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,
Image *image,
509 assert(display != (Display *) NULL);
510 assert(pixel != (XPixelInfo *) NULL);
511 assert(annotate_info != (XAnnotateInfo *) NULL);
512 assert(image != (
Image *) NULL);
513 if (IsEventLogging() != MagickFalse)
514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
518 root_window=XRootWindow(display,XDefaultScreen(display));
519 depth=(
unsigned int) XDefaultDepth(display,XDefaultScreen(display));
520 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
521 annotate_info->height,depth);
522 if (annotate_pixmap == (Pixmap) NULL)
527 context_values.background=0;
528 context_values.foreground=(size_t) (~0);
529 context_values.font=annotate_info->font_info->fid;
530 annotate_context=XCreateGC(display,root_window,(
unsigned long)
531 (GCBackground | GCFont | GCForeground),&context_values);
532 if (annotate_context == (GC) NULL)
537 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
538 (
int) annotate_info->font_info->ascent,annotate_info->text,
539 (int) strlen(annotate_info->text));
540 (void) XFreeGC(display,annotate_context);
544 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
545 annotate_info->height,AllPlanes,ZPixmap);
546 if (annotate_ximage == (XImage *) NULL)
548 (void) XFreePixmap(display,annotate_pixmap);
552 annotate_image=AcquireImage((
ImageInfo *) NULL,exception);
553 if (annotate_image == (
Image *) NULL)
555 annotate_image->columns=annotate_info->width;
556 annotate_image->rows=annotate_info->height;
560 width=(
unsigned int) image->columns;
561 height=(
unsigned int) image->rows;
564 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
565 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
566 (ssize_t) y,&annotate_image->background_color,exception);
567 if (annotate_info->stencil == ForegroundStencil)
568 annotate_image->alpha_trait=BlendPixelTrait;
569 annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
570 for (y=0; y < (int) annotate_image->rows; y++)
578 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
579 annotate_image->columns,1,exception);
580 if (q == (Quantum *) NULL)
582 for (x=0; x < (int) annotate_image->columns; x++)
584 SetPixelAlpha(annotate_image,OpaqueAlpha,q);
585 if (XGetPixel(annotate_ximage,x,y) == 0)
590 SetPixelRed(annotate_image,ScaleShortToQuantum(
591 pixel->box_color.red),q);
592 SetPixelGreen(annotate_image,ScaleShortToQuantum(
593 pixel->box_color.green),q);
594 SetPixelBlue(annotate_image,ScaleShortToQuantum(
595 pixel->box_color.blue),q);
596 if ((annotate_info->stencil == ForegroundStencil) ||
597 (annotate_info->stencil == OpaqueStencil))
598 SetPixelAlpha(annotate_image,TransparentAlpha,q);
605 SetPixelRed(annotate_image,ScaleShortToQuantum(
606 pixel->pen_color.red),q);
607 SetPixelGreen(annotate_image,ScaleShortToQuantum(
608 pixel->pen_color.green),q);
609 SetPixelBlue(annotate_image,ScaleShortToQuantum(
610 pixel->pen_color.blue),q);
611 if (annotate_info->stencil == BackgroundStencil)
612 SetPixelAlpha(annotate_image,TransparentAlpha,q);
614 q+=GetPixelChannels(annotate_image);
616 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
619 annotate_view=DestroyCacheView(annotate_view);
620 XDestroyImage(annotate_ximage);
624 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
625 if ((width != (
unsigned int) annotate_image->columns) ||
626 (height != (
unsigned int) annotate_image->rows))
629 image_geometry[MagickPathExtent];
634 (void) FormatLocaleString(image_geometry,MagickPathExtent,
"%ux%u",
636 (void) TransformImage(&annotate_image,(
char *) NULL,image_geometry,
639 if (annotate_info->degrees != 0.0)
653 rotate_image=RotateImage(annotate_image,annotate_info->degrees,exception);
654 if (rotate_image == (
Image *) NULL)
656 annotate_image=DestroyImage(annotate_image);
657 annotate_image=rotate_image;
661 normalized_degrees=annotate_info->degrees;
662 while (normalized_degrees < -45.0)
663 normalized_degrees+=360.0;
664 for (rotations=0; normalized_degrees > 45.0; rotations++)
665 normalized_degrees-=90.0;
666 switch (rotations % 4)
676 x-=(int) annotate_image->columns/2;
677 y+=(int) annotate_image->columns/2;
685 x=x-(int) annotate_image->columns;
693 x=x-(int) annotate_image->columns/2;
694 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
702 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
703 alpha_trait=image->alpha_trait;
704 (void) CompositeImage(image,annotate_image,
705 annotate_image->alpha_trait != UndefinedPixelTrait ? OverCompositeOp :
706 CopyCompositeOp,MagickTrue,(ssize_t) x,(ssize_t) y,exception);
707 image->alpha_trait=alpha_trait;
708 annotate_image=DestroyImage(annotate_image);
745static char **FontToList(
char *font)
760 if (font == (
char *) NULL)
761 return((
char **) NULL);
766 for (p=font; *p !=
'\0'; p++)
767 if ((*p ==
':') || (*p ==
';') || (*p ==
','))
769 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts+1UL,
sizeof(*fontlist));
770 if (fontlist == (
char **) NULL)
772 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",font);
773 return((
char **) NULL);
776 for (i=0; i < (int) fonts; i++)
778 for (q=p; *q !=
'\0'; q++)
779 if ((*q ==
':') || (*q ==
';') || (*q ==
','))
781 fontlist[i]=(
char *) AcquireQuantumMemory((
size_t) (q-p)+1UL,
782 sizeof(*fontlist[i]));
783 if (fontlist[i] == (
char *) NULL)
785 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",font);
786 return((
char **) NULL);
788 (void) CopyMagickString(fontlist[i],p,(
size_t) (q-p+1));
791 fontlist[i]=(
char *) NULL;
795MagickPrivate XFontStruct *XBestFont(Display *display,
796 const XResourceInfo *resource_info,
const MagickBooleanType text_font)
801 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
802 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
803 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
804 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
805 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
806 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
813 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
814 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
815 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
829 font_info=(XFontStruct *) NULL;
830 font_name=resource_info->font;
831 if (text_font != MagickFalse)
832 font_name=resource_info->text_font;
833 if ((font_name != (
char *) NULL) && (*font_name !=
'\0'))
844 fontlist=FontToList(font_name);
845 if (fontlist != (
char **) NULL)
847 for (i=0; fontlist[i] != (
char *) NULL; i++)
849 if (font_info == (XFontStruct *) NULL)
850 font_info=XLoadQueryFont(display,fontlist[i]);
851 fontlist[i]=DestroyString(fontlist[i]);
853 fontlist=(
char **) RelinquishMagickMemory(fontlist);
855 if (font_info == (XFontStruct *) NULL)
856 ThrowXWindowException(XServerError,
"UnableToLoadFont",font_name);
862 if (text_font != MagickFalse)
864 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
866 while (*p != (
char *) NULL)
868 if (font_info != (XFontStruct *) NULL)
870 font_info=XLoadQueryFont(display,(
char *) *p);
903MagickPrivate
void XBestIconSize(Display *display,XWindowInfo *window,
929 assert(display != (Display *) NULL);
930 assert(window != (XWindowInfo *) NULL);
931 assert(image != (
Image *) NULL);
932 if (IsEventLogging() != MagickFalse)
933 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
934 window->width=MaxIconSize;
935 window->height=MaxIconSize;
936 icon_size=(XIconSize *) NULL;
938 root_window=XRootWindow(display,window->screen);
939 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
940 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
942 if (icon_size == (XIconSize *) NULL)
947 icon_size=XAllocIconSize();
948 if (icon_size == (XIconSize *) NULL)
950 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
954 icon_size->min_width=1;
955 icon_size->max_width=MaxIconSize;
956 icon_size->min_height=1;
957 icon_size->max_height=MaxIconSize;
958 icon_size->width_inc=1;
959 icon_size->height_inc=1;
964 width=(
unsigned int) image->columns;
965 height=(
unsigned int) image->rows;
967 if (window->crop_geometry)
968 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
972 scale_factor=(double) icon_size->max_width/width;
973 if (scale_factor > ((
double) icon_size->max_height/height))
974 scale_factor=(double) icon_size->max_height/height;
975 icon_width=(
unsigned int) icon_size->min_width;
976 while ((
int) icon_width < icon_size->max_width)
978 if (icon_width >= (
unsigned int) (scale_factor*width+0.5))
980 icon_width+=(
unsigned int) icon_size->width_inc;
982 icon_height=(
unsigned int) icon_size->min_height;
983 while ((
int) icon_height < icon_size->max_height)
985 if (icon_height >= (
unsigned int) (scale_factor*height+0.5))
987 icon_height+=(
unsigned int) icon_size->height_inc;
989 (void) XFree((
void *) icon_size);
990 window->width=icon_width;
991 window->height=icon_height;
1032MagickPrivate
void XBestPixel(Display *display,
const Colormap colormap,
1033 XColor *colors,
unsigned int number_colors,XColor *color)
1057 assert(display != (Display *) NULL);
1058 assert(color != (XColor *) NULL);
1059 if (IsEventLogging() != MagickFalse)
1060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1061 status=XAllocColor(display,colormap,color);
1062 if (status != False)
1064 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1065 if (query_server != MagickFalse)
1070 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
1071 if (colors == (XColor *) NULL)
1073 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
1077 for (i=0; i < (int) number_colors; i++)
1078 colors[i].pixel=(
size_t) i;
1079 if (number_colors > 256)
1081 (void) XQueryColors(display,colormap,colors,(
int) number_colors);
1083 min_distance=3.0*((double) QuantumRange+1.0)*((double)
1086 for (i=0; i < (int) number_colors; i++)
1088 pixel.red=colors[i].red-(double) color->red;
1089 distance=pixel.red*pixel.red;
1090 if (distance > min_distance)
1092 pixel.green=colors[i].green-(double) color->green;
1093 distance+=pixel.green*pixel.green;
1094 if (distance > min_distance)
1096 pixel.blue=colors[i].blue-(double) color->blue;
1097 distance+=pixel.blue*pixel.blue;
1098 if (distance > min_distance)
1100 min_distance=distance;
1101 color->pixel=colors[i].pixel;
1104 (void) XAllocColor(display,colormap,&colors[j]);
1105 if (query_server != MagickFalse)
1106 colors=(XColor *) RelinquishMagickMemory(colors);
1154MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
1155 XStandardColormap *map_info,XResourceInfo *resource_info)
1157#define MaxStandardColormaps 7
1158#define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1159 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1160 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1161 (unsigned long) visual_info->colormap_size),1UL << visual_info->depth)
1189 assert(display != (Display *) NULL);
1190 assert(map_info != (XStandardColormap *) NULL);
1191 assert(resource_info != (XResourceInfo *) NULL);
1192 if (IsEventLogging() != MagickFalse)
1193 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1194 map_type=resource_info->map_type;
1195 visual_type=resource_info->visual_type;
1196 visual_mask=VisualScreenMask;
1197 visual_template.screen=XDefaultScreen(display);
1198 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1200 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1201 if (resource_info->colors <= (one << (
size_t) visual_template.depth))
1202 visual_mask|=VisualDepthMask;
1203 if (visual_type != (
char *) NULL)
1208 if (LocaleCompare(
"staticgray",visual_type) == 0)
1210 visual_mask|=VisualClassMask;
1211 visual_template.klass=StaticGray;
1214 if (LocaleCompare(
"grayscale",visual_type) == 0)
1216 visual_mask|=VisualClassMask;
1217 visual_template.klass=GrayScale;
1220 if (LocaleCompare(
"staticcolor",visual_type) == 0)
1222 visual_mask|=VisualClassMask;
1223 visual_template.klass=StaticColor;
1226 if (LocaleCompare(
"pseudocolor",visual_type) == 0)
1228 visual_mask|=VisualClassMask;
1229 visual_template.klass=PseudoColor;
1232 if (LocaleCompare(
"truecolor",visual_type) == 0)
1234 visual_mask|=VisualClassMask;
1235 visual_template.klass=TrueColor;
1238 if (LocaleCompare(
"directcolor",visual_type) == 0)
1240 visual_mask|=VisualClassMask;
1241 visual_template.klass=DirectColor;
1244 if (LocaleCompare(
"default",visual_type) == 0)
1246 visual_mask|=VisualIDMask;
1247 visual_template.visualid=XVisualIDFromVisual(
1248 XDefaultVisual(display,XDefaultScreen(display)));
1251 if (isdigit((
int) ((
unsigned char) *visual_type)) != 0)
1253 visual_mask|=VisualIDMask;
1254 visual_template.visualid=(size_t)
1255 strtol(visual_type,(
char **) NULL,0);
1258 ThrowXWindowException(XServerError,
1259 "UnrecognizedVisualSpecifier",visual_type);
1265 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1267 visual_mask=VisualScreenMask | VisualIDMask;
1268 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1273 ThrowXWindowException(XServerWarning,
"UnableToGetVisual",visual_type);
1274 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1275 XDefaultScreen(display)));
1276 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1278 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1279 return((XVisualInfo *) NULL);
1280 ThrowXWindowException(XServerWarning,
"UsingDefaultVisual",
1281 XVisualClassName(visual_list->klass));
1283 resource_info->color_recovery=MagickFalse;
1284 if ((map_info != (XStandardColormap *) NULL) && (map_type != (
char *) NULL))
1290 map_name[MagickPathExtent];
1308 root_window=XRootWindow(display,XDefaultScreen(display));
1311 if (LocaleCompare(map_type,
"list") != 0)
1316 (void) FormatLocaleString((
char *) map_name,MagickPathExtent,
1317 "RGB_%s_MAP",map_type);
1318 LocaleUpper(map_name);
1319 map_property=XInternAtom(display,(
char *) map_name,MagickTrue);
1320 if (map_property != (Atom) NULL)
1321 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1327 *colormap[MaxStandardColormaps]=
1329 "_HP_RGB_SMOOTH_MAP_LIST",
1341 for (i=0; i < MaxStandardColormaps; i++)
1343 map_property=XInternAtom(display,(
char *) colormap[i],MagickTrue);
1344 if (map_property == (Atom) NULL)
1346 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1348 if (status != False)
1351 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1353 if (status == False)
1355 ThrowXWindowException(XServerError,
"UnableToGetStandardColormap",
1357 return((XVisualInfo *) NULL);
1362 *map_info=map_list[0];
1363#if !defined(PRE_R4_ICCCM)
1364 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1365 for (i=0; i < number_maps; i++)
1366 for (j=0; j < number_visuals; j++)
1367 if (map_list[i].visualid ==
1368 XVisualIDFromVisual(visual_list[j].visual))
1370 *map_info=map_list[i];
1371 visual_template.visualid=XVisualIDFromVisual(
1372 visual_list[j].visual);
1375 if (map_info->visualid != visual_template.visualid)
1377 ThrowXWindowException(XServerError,
1378 "UnableToMatchVisualToStandardColormap",map_type);
1379 return((XVisualInfo *) NULL);
1382 if (map_info->colormap == (Colormap) NULL)
1384 ThrowXWindowException(XServerError,
"StandardColormapIsNotInitialized",
1386 return((XVisualInfo *) NULL);
1388 (void) XFree((
void *) map_list);
1392 static const unsigned int
1409 visual_info=visual_list;
1411 for (i=1; i < number_visuals; i++)
1414 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1417 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1418 if (rank[p->klass] > rank[visual_info->klass])
1421 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1423 (void) XFree((
void *) visual_list);
1427 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1429 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1430 return((XVisualInfo *) NULL);
1431 return(visual_info);
1461MagickPrivate
int XCheckDefineCursor(Display *display,Window window,
1464 assert(display != (Display *) NULL);
1465 if (IsEventLogging() != MagickFalse)
1466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1467 if (window == XRootWindow(display,XDefaultScreen(display)))
1469 return(XDefineCursor(display,window,cursor));
1498MagickPrivate
void XCheckRefreshWindows(Display *display,XWindows *windows)
1506 assert(display != (Display *) NULL);
1507 assert(windows != (XWindows *) NULL);
1508 if (IsEventLogging() != MagickFalse)
1509 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1510 XDelay(display,SuspendTime);
1511 id=windows->command.id;
1512 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1513 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1514 id=windows->image.id;
1515 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1516 XRefreshWindow(display,&windows->image,&event);
1517 XDelay(display,SuspendTime << 1);
1518 id=windows->command.id;
1519 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1520 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1521 id=windows->image.id;
1522 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1523 XRefreshWindow(display,&windows->image,&event);
1558MagickPrivate
void XClientMessage(Display *display,
const Window window,
1559 const Atom protocol,
const Atom reason,
const Time timestamp)
1564 assert(display != (Display *) NULL);
1565 (void) memset(&client_event,0,
sizeof(client_event));
1566 client_event.type=ClientMessage;
1567 client_event.window=window;
1568 client_event.message_type=protocol;
1569 client_event.format=32;
1570 client_event.data.l[0]=(long) reason;
1571 client_event.data.l[1]=(long) timestamp;
1572 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *)
1607static Window XClientWindow(Display *display,Window target_window)
1629 assert(display != (Display *) NULL);
1630 if (IsEventLogging() != MagickFalse)
1631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1632 state=XInternAtom(display,
"WM_STATE",MagickTrue);
1633 if (state == (Atom) NULL)
1634 return(target_window);
1636 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1637 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1638 if ((status == Success) && (type != (Atom) NULL))
1639 return(target_window);
1640 client_window=XWindowByProperty(display,target_window,state);
1641 if (client_window == (Window) NULL)
1642 return(target_window);
1643 return(client_window);
1664MagickPrivate
void XComponentTerminus(
void)
1666 DestroyXResources();
1702MagickPrivate
void XConfigureImageColormap(Display *display,
1703 XResourceInfo *resource_info,XWindows *windows,
Image *image,
1712 XSetCursorState(display,windows,MagickTrue);
1713 XCheckRefreshWindows(display,windows);
1714 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1715 windows->map_info,windows->pixel_info,exception);
1716 colormap=windows->map_info->colormap;
1717 (void) XSetWindowColormap(display,windows->image.id,colormap);
1718 (void) XSetWindowColormap(display,windows->command.id,colormap);
1719 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1720 if (windows->magnify.mapped != MagickFalse)
1721 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1722 if (windows->pan.mapped != MagickFalse)
1723 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1724 XSetCursorState(display,windows,MagickFalse);
1725 XClientMessage(display,windows->image.id,windows->im_protocols,
1726 windows->im_update_colormap,CurrentTime);
1755MagickPrivate
void XConstrainWindowPosition(Display *display,
1756 XWindowInfo *window_info)
1761 assert(display != (Display *) NULL);
1762 assert(window_info != (XWindowInfo *) NULL);
1763 if (IsEventLogging() != MagickFalse)
1764 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1765 limit=XDisplayWidth(display,window_info->screen)-(int) window_info->width;
1766 if (window_info->x < 0)
1769 if (window_info->x > (
int) limit)
1770 window_info->x=(int) limit;
1771 limit=XDisplayHeight(display,window_info->screen)-(int) window_info->height;
1772 if (window_info->y < 0)
1775 if (window_info->y > limit)
1776 window_info->y=limit;
1806MagickPrivate
void XDelay(Display *display,
const size_t milliseconds)
1808 assert(display != (Display *) NULL);
1809 (void) XFlush(display);
1810 MagickDelay(milliseconds);
1836MagickExport
void XDestroyResourceInfo(XResourceInfo *resource_info)
1838 if (resource_info->image_geometry != (
char *) NULL)
1839 resource_info->image_geometry=(
char *)
1840 RelinquishMagickMemory(resource_info->image_geometry);
1841 if (resource_info->quantize_info != (
QuantizeInfo *) NULL)
1842 resource_info->quantize_info=DestroyQuantizeInfo(
1843 resource_info->quantize_info);
1844 if (resource_info->client_name != (
char *) NULL)
1845 resource_info->client_name=(
char *)
1846 RelinquishMagickMemory(resource_info->client_name);
1847 if (resource_info->name != (
char *) NULL)
1848 resource_info->name=DestroyString(resource_info->name);
1849 (void) memset(resource_info,0,
sizeof(*resource_info));
1850 (void) XSetWindows((XWindows *) NULL);
1879MagickPrivate
void XDestroyWindowColors(Display *display,Window window)
1901 assert(display != (Display *) NULL);
1902 if (IsEventLogging() != MagickFalse)
1903 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1904 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
1905 if (property == (Atom) NULL)
1907 ThrowXWindowException(XServerError,
"UnableToCreateProperty",
1911 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1912 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1913 if (status != Success)
1915 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1917 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1918 (void) XDeleteProperty(display,window,property);
1921 (void) XFree((
void *) data);
1959MagickPrivate
void XDisplayImageInfo(Display *display,
1960 const XResourceInfo *resource_info,XWindows *windows,
Image *undo_image,
1964 filename[MagickPathExtent],
1989 assert(display != (Display *) NULL);
1990 assert(resource_info != (XResourceInfo *) NULL);
1991 assert(windows != (XWindows *) NULL);
1992 assert(image != (
Image *) NULL);
1993 if (IsEventLogging() != MagickFalse)
1994 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1996 unique_file=AcquireUniqueFileResource(filename);
1997 if (unique_file != -1)
1998 file=fdopen(unique_file,
"w");
1999 if ((unique_file == -1) || (file == (FILE *) NULL))
2001 XNoticeWidget(display,windows,
"Unable to display image info",filename);
2004 if (resource_info->gamma_correct != MagickFalse)
2005 if (resource_info->display_gamma != (
char *) NULL)
2006 (void) FormatLocaleFile(file,
"Display\n gamma: %s\n\n",
2007 resource_info->display_gamma);
2011 (void) FormatLocaleFile(file,
"X\n visual: %s\n",
2012 XVisualClassName((
int) windows->image.storage_class));
2013 (void) FormatLocaleFile(file,
" depth: %d\n",windows->image.ximage->depth);
2014 if (windows->visual_info->colormap_size != 0)
2015 (void) FormatLocaleFile(file,
" colormap size: %d\n",
2016 windows->visual_info->colormap_size);
2017 if (resource_info->colormap== SharedColormap)
2018 (void) FormatLocaleFile(file,
" colormap type: Shared\n");
2020 (
void) FormatLocaleFile(file,
" colormap type: Private\n");
2021 (void) FormatLocaleFile(file,
" geometry: %dx%d\n",
2022 windows->image.ximage->width,windows->image.ximage->height);
2023 if (windows->image.crop_geometry != (
char *) NULL)
2024 (
void) FormatLocaleFile(file,
" crop geometry: %s\n",
2025 windows->image.crop_geometry);
2026 if (windows->image.pixmap == (Pixmap) NULL)
2027 (void) FormatLocaleFile(file,
" type: X Image\n");
2029 (
void) FormatLocaleFile(file,
" type: Pixmap\n");
2030 if (windows->image.shape != MagickFalse)
2031 (void) FormatLocaleFile(file,
" non-rectangular shape: True\n");
2033 (
void) FormatLocaleFile(file,
" non-rectangular shape: False\n");
2034 if (windows->image.shared_memory != MagickFalse)
2035 (void) FormatLocaleFile(file,
" shared memory: True\n");
2037 (
void) FormatLocaleFile(file,
" shared memory: False\n");
2038 (void) FormatLocaleFile(file,
"\n");
2039 if (resource_info->font != (
char *) NULL)
2040 (
void) FormatLocaleFile(file,
"Font: %s\n\n",resource_info->font);
2041 if (resource_info->text_font != (
char *) NULL)
2042 (void) FormatLocaleFile(file,
"Text font: %s\n\n",resource_info->text_font);
2047 for (levels=0; undo_image != (
Image *) NULL; levels++)
2049 number_pixels=undo_image->list->columns*undo_image->list->rows;
2050 bytes+=(ssize_t) (number_pixels*
sizeof(
PixelInfo));
2051 undo_image=GetPreviousImageInList(undo_image);
2053 (void) FormatLocaleFile(file,
"Undo Edit Cache\n levels: %u\n",levels);
2054 (void) FormatLocaleFile(file,
" bytes: %.20gmb\n",(
double)
2055 ((bytes+(1 << 19)) >> 20));
2056 (void) FormatLocaleFile(file,
" limit: %.20gmb\n\n",(
double)
2057 resource_info->undo_cache);
2061 (void) IdentifyImage(image,file,MagickTrue,exception);
2062 (void) fclose(file);
2063 text=FileToString(filename,~0UL,exception);
2064 (void) RelinquishUniqueFileResource(filename);
2065 if (text == (
char *) NULL)
2067 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
2068 "UnableToDisplayImageInfo");
2071 textlist=StringToList(text);
2072 if (textlist != (
char **) NULL)
2075 title[MagickPathExtent];
2080 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2081 (void) FormatLocaleString(title,MagickPathExtent,
"Image Info: %s",
2083 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2084 (
char const **) textlist);
2085 for (i=0; textlist[i] != (
char *) NULL; i++)
2086 textlist[i]=DestroyString(textlist[i]);
2087 textlist=(
char **) RelinquishMagickMemory(textlist);
2089 text=DestroyString(text);
2124 static const short int
2127 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2128 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2130 dither_green[2][16]=
2132 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2133 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2137 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2138 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2174 for (i=0; i < 2; i++)
2175 for (j=0; j < 16; j++)
2177 red_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2179 green_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2180 sizeof(*green_map));
2181 blue_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2187 for (i=0; i < 2; i++)
2188 for (j=0; j < 16; j++)
2189 for (x=0; x < 256; x++)
2194 value+=dither_red[i][j];
2195 red_map[i][j][x]=(
unsigned char)
2196 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2200 value+=dither_green[i][j];
2201 green_map[i][j][x]=(
unsigned char)
2202 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2206 value+=(int) (dither_blue[i][j] << 1);
2207 blue_map[i][j][x]=(
unsigned char)
2208 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2213 scanline_pad=(
unsigned int) (ximage->bytes_per_line-(
int)
2214 ((ximage->width*ximage->bits_per_pixel) >> 3));
2218 image_view=AcquireVirtualCacheView(image,exception);
2219 for (y=0; y < (int) image->rows; y++)
2221 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2223 if (p == (
const Quantum *) NULL)
2225 for (x=0; x < (int) image->columns; x++)
2227 color.red=(double) ClampToQuantum((
double) (red_map[i][j][
2228 (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2229 color.green=(double) ClampToQuantum((
double) (green_map[i][j][
2230 (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2231 color.blue=(double) ClampToQuantum((
double) (blue_map[i][j][
2232 (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2233 pixel=(size_t) (((
size_t) color.red & 0xe0) |
2234 (((
size_t) color.green & 0xe0) >> 3) |
2235 (((size_t) color.blue & 0xc0) >> 6));
2237 p+=GetPixelChannels(image);
2247 image_view=DestroyCacheView(image_view);
2251 for (i=0; i < 2; i++)
2252 for (j=0; j < 16; j++)
2254 green_map[i][j]=(
unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2255 blue_map[i][j]=(
unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2256 red_map[i][j]=(
unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2292MagickPrivate MagickBooleanType XDrawImage(Display *display,
2293 const XPixelInfo *pixel,XDrawInfo *draw_info,
Image *image,
2332 assert(display != (Display *) NULL);
2333 assert(pixel != (XPixelInfo *) NULL);
2334 assert(draw_info != (XDrawInfo *) NULL);
2335 assert(image != (
Image *) NULL);
2336 if (IsEventLogging() != MagickFalse)
2337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2341 root_window=XRootWindow(display,XDefaultScreen(display));
2342 depth=(
unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2343 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2344 draw_info->height,depth);
2345 if (draw_pixmap == (Pixmap) NULL)
2346 return(MagickFalse);
2350 context_values.background=(size_t) (~0);
2351 context_values.foreground=0;
2352 context_values.line_width=(int) draw_info->line_width;
2353 draw_context=XCreateGC(display,root_window,(
size_t)
2354 (GCBackground | GCForeground | GCLineWidth),&context_values);
2355 if (draw_context == (GC) NULL)
2356 return(MagickFalse);
2360 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2365 (void) XSetBackground(display,draw_context,0);
2366 (void) XSetForeground(display,draw_context,(
size_t) (~0));
2367 if (draw_info->stipple != (Pixmap) NULL)
2369 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2370 (void) XSetStipple(display,draw_context,draw_info->stipple);
2372 switch (draw_info->element)
2377 (void) XDrawLines(display,draw_pixmap,draw_context,
2378 draw_info->coordinate_info,(
int) draw_info->number_coordinates,
2384 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2385 draw_info->line_info.y1,draw_info->line_info.x2,
2386 draw_info->line_info.y2);
2389 case RectangleElement:
2391 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2392 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2393 (
unsigned int) draw_info->rectangle_info.width,
2394 (
unsigned int) draw_info->rectangle_info.height);
2397 case FillRectangleElement:
2399 (void) XFillRectangle(display,draw_pixmap,draw_context,
2400 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2401 (
unsigned int) draw_info->rectangle_info.width,
2402 (
unsigned int) draw_info->rectangle_info.height);
2406 case EllipseElement:
2408 (void) XDrawArc(display,draw_pixmap,draw_context,
2409 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2410 (
unsigned int) draw_info->rectangle_info.width,
2411 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2414 case FillCircleElement:
2415 case FillEllipseElement:
2417 (void) XFillArc(display,draw_pixmap,draw_context,
2418 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2419 (
unsigned int) draw_info->rectangle_info.width,
2420 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2423 case PolygonElement:
2428 coordinate_info=draw_info->coordinate_info;
2429 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2430 (
int) draw_info->number_coordinates,CoordModeOrigin);
2431 (void) XDrawLine(display,draw_pixmap,draw_context,
2432 coordinate_info[draw_info->number_coordinates-1].x,
2433 coordinate_info[draw_info->number_coordinates-1].y,
2434 coordinate_info[0].x,coordinate_info[0].y);
2437 case FillPolygonElement:
2439 (void) XFillPolygon(display,draw_pixmap,draw_context,
2440 draw_info->coordinate_info,(
int) draw_info->number_coordinates,Complex,
2445 (void) XFreeGC(display,draw_context);
2449 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2450 draw_info->height,AllPlanes,ZPixmap);
2451 if (draw_ximage == (XImage *) NULL)
2452 return(MagickFalse);
2453 (void) XFreePixmap(display,draw_pixmap);
2457 draw_image=AcquireImage((
ImageInfo *) NULL,exception);
2458 if (draw_image == (
Image *) NULL)
2459 return(MagickFalse);
2460 draw_image->columns=draw_info->width;
2461 draw_image->rows=draw_info->height;
2465 width=(
unsigned int) image->columns;
2466 height=(
unsigned int) image->rows;
2469 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2470 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
2471 (ssize_t) y,&draw_image->background_color,exception);
2472 if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
2473 return(MagickFalse);
2474 draw_image->alpha_trait=BlendPixelTrait;
2475 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2476 for (y=0; y < (int) draw_image->rows; y++)
2484 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2486 if (q == (Quantum *) NULL)
2488 for (x=0; x < (int) draw_image->columns; x++)
2490 if (XGetPixel(draw_ximage,x,y) == 0)
2495 SetPixelViaPixelInfo(draw_image,&draw_image->background_color,q);
2496 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2497 OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
2504 SetPixelRed(draw_image,ScaleShortToQuantum(
2505 pixel->pen_color.red),q);
2506 SetPixelGreen(draw_image,ScaleShortToQuantum(
2507 pixel->pen_color.green),q);
2508 SetPixelBlue(draw_image,ScaleShortToQuantum(
2509 pixel->pen_color.blue),q);
2510 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2511 OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
2513 q+=GetPixelChannels(draw_image);
2515 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2518 draw_view=DestroyCacheView(draw_view);
2519 XDestroyImage(draw_ximage);
2523 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2524 if ((width != (
unsigned int) draw_image->columns) ||
2525 (height != (
unsigned int) draw_image->rows))
2528 image_geometry[MagickPathExtent];
2533 (void) FormatLocaleString(image_geometry,MagickPathExtent,
"%ux%u",
2535 (void) TransformImage(&draw_image,(
char *) NULL,image_geometry,
2538 if (draw_info->degrees != 0.0)
2552 rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
2553 if (rotate_image == (
Image *) NULL)
2554 return(MagickFalse);
2555 draw_image=DestroyImage(draw_image);
2556 draw_image=rotate_image;
2560 normalized_degrees=draw_info->degrees;
2561 while (normalized_degrees < -45.0)
2562 normalized_degrees+=360.0;
2563 for (rotations=0; normalized_degrees > 45.0; rotations++)
2564 normalized_degrees-=90.0;
2565 switch (rotations % 4)
2575 x=x-(int) draw_image->columns/2;
2576 y=y+(int) draw_image->columns/2;
2584 x=x-(int) draw_image->columns;
2592 x=x-(int) draw_image->columns/2;
2593 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2601 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2602 for (y=0; y < (int) draw_image->rows; y++)
2610 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2612 if (q == (Quantum *) NULL)
2614 for (x=0; x < (int) draw_image->columns; x++)
2616 if (GetPixelAlpha(image,q) != TransparentAlpha)
2617 SetPixelAlpha(draw_image,OpaqueAlpha,q);
2618 q+=GetPixelChannels(draw_image);
2620 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2623 draw_view=DestroyCacheView(draw_view);
2624 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2625 if (draw_info->stencil == TransparentStencil)
2626 (void) CompositeImage(image,draw_image,CopyAlphaCompositeOp,MagickTrue,
2627 (ssize_t) x,(ssize_t) y,exception);
2630 alpha_trait=image->alpha_trait;
2631 (void) CompositeImage(image,draw_image,OverCompositeOp,MagickTrue,
2632 (ssize_t) x,(ssize_t) y,exception);
2633 image->alpha_trait=alpha_trait;
2635 draw_image=DestroyImage(draw_image);
2668#if defined(__cplusplus) || defined(c_plusplus)
2672MagickExport
int XError(Display *display,XErrorEvent *error)
2674 assert(display != (Display *) NULL);
2675 assert(error != (XErrorEvent *) NULL);
2676 if (IsEventLogging() != MagickFalse)
2677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2678 xerror_alert=MagickTrue;
2679 switch (error->request_code)
2683 if ((
int) error->error_code == BadDrawable)
2684 return(MagickFalse);
2687 case X_GetWindowAttributes:
2690 if ((
int) error->error_code == BadWindow)
2691 return(MagickFalse);
2696 if ((
int) error->error_code == BadValue)
2697 return(MagickFalse);
2704#if defined(__cplusplus) || defined(c_plusplus)
2748MagickPrivate
void XFreeResources(Display *display,XVisualInfo *visual_info,
2749 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2750 XResourceInfo *resource_info,XWindowInfo *window_info)
2752 assert(display != (Display *) NULL);
2753 assert(resource_info != (XResourceInfo *) NULL);
2754 if (IsEventLogging() != MagickFalse)
2755 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2756 if (window_info != (XWindowInfo *) NULL)
2761 if (window_info->ximage != (XImage *) NULL)
2762 XDestroyImage(window_info->ximage);
2763 if (window_info->id != (Window) NULL)
2768 if (window_info->id != XRootWindow(display,visual_info->screen))
2769 (
void) XDestroyWindow(display,window_info->id);
2770 if (window_info->annotate_context != (GC) NULL)
2771 (void) XFreeGC(display,window_info->annotate_context);
2772 if (window_info->highlight_context != (GC) NULL)
2773 (
void) XFreeGC(display,window_info->highlight_context);
2774 if (window_info->widget_context != (GC) NULL)
2775 (void) XFreeGC(display,window_info->widget_context);
2776 if (window_info->cursor != (Cursor) NULL)
2777 (
void) XFreeCursor(display,window_info->cursor);
2778 window_info->cursor=(Cursor) NULL;
2779 if (window_info->busy_cursor != (Cursor) NULL)
2780 (
void) XFreeCursor(display,window_info->busy_cursor);
2781 window_info->busy_cursor=(Cursor) NULL;
2787 if (font_info != (XFontStruct *) NULL)
2789 (void) XFreeFont(display,font_info);
2790 font_info=(XFontStruct *) NULL;
2792 if (map_info != (XStandardColormap *) NULL)
2797 if (resource_info->map_type == (
char *) NULL)
2798 (
void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2799 (void) XFree((
void *) map_info);
2804 if (visual_info != (XVisualInfo *) NULL)
2805 (
void) XFree((
void *) visual_info);
2806 if (resource_info->close_server != MagickFalse)
2807 (void) XCloseDisplay(display);
2843MagickPrivate
void XFreeStandardColormap(Display *display,
2844 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2849 assert(display != (Display *) NULL);
2850 assert(visual_info != (XVisualInfo *) NULL);
2851 assert(map_info != (XStandardColormap *) NULL);
2852 if (IsEventLogging() != MagickFalse)
2853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2854 (void) XFlush(display);
2855 if (map_info->colormap != (Colormap) NULL)
2857 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2858 (
void) XFreeColormap(display,map_info->colormap);
2860 if (pixel != (XPixelInfo *) NULL)
2861 if ((visual_info->klass != TrueColor) &&
2862 (visual_info->klass != DirectColor))
2863 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2864 (
int) pixel->colors,0);
2866 map_info->colormap=(Colormap) NULL;
2867 if (pixel != (XPixelInfo *) NULL)
2869 if (pixel->pixels != (
unsigned long *) NULL)
2870 pixel->pixels=(
unsigned long *) RelinquishMagickMemory(pixel->pixels);
2871 pixel->pixels=(
unsigned long *) NULL;
2897MagickPrivate
void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2902 assert(annotate_info != (XAnnotateInfo *) NULL);
2903 if (IsEventLogging() != MagickFalse)
2904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2907 annotate_info->width=0;
2908 annotate_info->height=0;
2909 annotate_info->stencil=ForegroundStencil;
2910 annotate_info->degrees=0.0;
2911 annotate_info->font_info=(XFontStruct *) NULL;
2912 annotate_info->text=(
char *) NULL;
2913 *annotate_info->geometry=
'\0';
2914 annotate_info->previous=(XAnnotateInfo *) NULL;
2915 annotate_info->next=(XAnnotateInfo *) NULL;
2916 (void) XSupportsLocale();
2917 (void) XSetLocaleModifiers(
"");
2948MagickPrivate
void XGetMapInfo(
const XVisualInfo *visual_info,
2949 const Colormap colormap,XStandardColormap *map_info)
2954 assert(visual_info != (XVisualInfo *) NULL);
2955 assert(map_info != (XStandardColormap *) NULL);
2956 if (IsEventLogging() != MagickFalse)
2957 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2958 map_info->colormap=colormap;
2959 map_info->red_max=visual_info->red_mask;
2960 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2961 if (map_info->red_max != 0)
2962 while ((map_info->red_max & 0x01) == 0)
2964 map_info->red_max>>=1;
2965 map_info->red_mult<<=1;
2967 map_info->green_max=visual_info->green_mask;
2968 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2969 if (map_info->green_max != 0)
2970 while ((map_info->green_max & 0x01) == 0)
2972 map_info->green_max>>=1;
2973 map_info->green_mult<<=1;
2975 map_info->blue_max=visual_info->blue_mask;
2976 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2977 if (map_info->blue_max != 0)
2978 while ((map_info->blue_max & 0x01) == 0)
2980 map_info->blue_max>>=1;
2981 map_info->blue_mult<<=1;
2983 map_info->base_pixel=0;
3024MagickPrivate
void XGetPixelInfo(Display *display,
3025 const XVisualInfo *visual_info,
const XStandardColormap *map_info,
3026 const XResourceInfo *resource_info,
Image *image,XPixelInfo *pixel)
3029 *PenColors[MaxNumberPens]=
3059 assert(display != (Display *) NULL);
3060 assert(visual_info != (XVisualInfo *) NULL);
3061 assert(map_info != (XStandardColormap *) NULL);
3062 assert(resource_info != (XResourceInfo *) NULL);
3063 assert(pixel != (XPixelInfo *) NULL);
3064 if (IsEventLogging() != MagickFalse)
3065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3067 if (image != (
Image *) NULL)
3068 if (image->storage_class == PseudoClass)
3069 pixel->colors=(ssize_t) image->colors;
3070 packets=(
unsigned int)
3071 MagickMax((
int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3072 if (pixel->pixels != (
unsigned long *) NULL)
3073 pixel->pixels=(
unsigned long *) RelinquishMagickMemory(pixel->pixels);
3074 pixel->pixels=(
unsigned long *) AcquireQuantumMemory(packets,
3075 sizeof(*pixel->pixels));
3076 if (pixel->pixels == (
unsigned long *) NULL)
3077 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToGetPixelInfo",
3082 colormap=map_info->colormap;
3083 (void) XParseColor(display,colormap,(
char *) ForegroundColor,
3084 &pixel->foreground_color);
3085 status=XParseColor(display,colormap,resource_info->foreground_color,
3086 &pixel->foreground_color);
3087 if (status == False)
3088 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3089 resource_info->foreground_color);
3090 pixel->foreground_color.pixel=
3091 XStandardPixel(map_info,&pixel->foreground_color);
3092 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3096 (void) XParseColor(display,colormap,
"#d6d6d6d6d6d6",&pixel->background_color);
3097 status=XParseColor(display,colormap,resource_info->background_color,
3098 &pixel->background_color);
3099 if (status == False)
3100 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3101 resource_info->background_color);
3102 pixel->background_color.pixel=
3103 XStandardPixel(map_info,&pixel->background_color);
3104 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3108 (void) XParseColor(display,colormap,(
char *) BorderColor,
3109 &pixel->border_color);
3110 status=XParseColor(display,colormap,resource_info->border_color,
3111 &pixel->border_color);
3112 if (status == False)
3113 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3114 resource_info->border_color);
3115 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3116 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3120 pixel->matte_color=pixel->background_color;
3121 if (resource_info->matte_color != (
char *) NULL)
3126 status=XParseColor(display,colormap,resource_info->matte_color,
3127 &pixel->matte_color);
3128 if (status == False)
3129 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3130 resource_info->matte_color);
3131 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3132 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3137 pixel->highlight_color.red=(
unsigned short) (((
double)
3138 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3139 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3140 pixel->highlight_color.green=(
unsigned short) (((
double)
3141 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3142 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3143 pixel->highlight_color.blue=(
unsigned short) (((
double)
3144 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3145 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3146 pixel->highlight_color.pixel=XStandardPixel(map_info,&pixel->highlight_color);
3147 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3151 pixel->shadow_color.red=(
unsigned short) (((
double)
3152 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3153 pixel->shadow_color.green=(
unsigned short) (((
double)
3154 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3155 pixel->shadow_color.blue=(
unsigned short) (((
double)
3156 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3157 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3158 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3162 pixel->depth_color.red=(
unsigned short) (((
double)
3163 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3164 pixel->depth_color.green=(
unsigned short) (((
double)
3165 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3166 pixel->depth_color.blue=(
unsigned short) (((
double)
3167 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3168 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3169 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3173 pixel->trough_color.red=(
unsigned short) (((
double)
3174 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3175 pixel->trough_color.green=(
unsigned short) (((
double)
3176 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3177 pixel->trough_color.blue=(
unsigned short) (((
double)
3178 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3179 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3180 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3184 for (i=0; i < MaxNumberPens; i++)
3186 (void) XParseColor(display,colormap,(
char *) PenColors[i],
3187 &pixel->pen_colors[i]);
3188 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3189 &pixel->pen_colors[i]);
3190 if (status == False)
3191 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3192 resource_info->pen_colors[i]);
3193 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3194 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3196 pixel->box_color=pixel->background_color;
3197 pixel->pen_color=pixel->foreground_color;
3200 if (image != (
Image *) NULL)
3202 if ((resource_info->gamma_correct != MagickFalse) &&
3203 (image->gamma != 0.0))
3214 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3215 if ((flags & RhoValue) != 0)
3216 red_gamma=geometry_info.rho;
3217 green_gamma=red_gamma;
3218 if ((flags & SigmaValue) != 0)
3219 green_gamma=geometry_info.sigma;
3220 blue_gamma=red_gamma;
3221 if ((flags & XiValue) != 0)
3222 blue_gamma=geometry_info.xi;
3223 red_gamma*=image->gamma;
3224 green_gamma*=image->gamma;
3225 blue_gamma*=image->gamma;
3227 if (image->storage_class == PseudoClass)
3232 for (i=0; i < (ssize_t) image->colors; i++)
3233 pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
3234 for (i=0; i < MaxNumberPens; i++)
3235 pixel->pixels[image->colors+(
size_t) i]=pixel->pen_colors[i].pixel;
3236 pixel->colors+=MaxNumberPens;
3275MagickExport
char *XGetResourceClass(XrmDatabase database,
3276 const char *client_name,
const char *keyword,
char *resource_default)
3279 resource_class[MagickPathExtent],
3280 resource_name[MagickPathExtent];
3291 if (database == (XrmDatabase) NULL)
3292 return(resource_default);
3293 *resource_name=
'\0';
3294 *resource_class=
'\0';
3295 if (keyword != (
char *) NULL)
3304 (void) FormatLocaleString(resource_name,MagickPathExtent,
"%s.%s",
3305 client_name,keyword);
3306 c=(int) (*client_name);
3307 if ((c >= XK_a) && (c <= XK_z))
3310 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3311 c-=(XK_agrave-XK_Agrave);
3313 if ((c >= XK_oslash) && (c <= XK_thorn))
3314 c-=(XK_oslash-XK_Ooblique);
3316 if ((k >= XK_a) && (k <= XK_z))
3319 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3320 k-=(XK_agrave-XK_Agrave);
3322 if ((k >= XK_oslash) && (k <= XK_thorn))
3323 k-=(XK_oslash-XK_Ooblique);
3324 (void) FormatLocaleString(resource_class,MagickPathExtent,
"%c%s.%c%s",c,
3325 client_name+1,k,keyword+1);
3327 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3329 if (status == False)
3330 return(resource_default);
3331 return(resource_value.addr);
3364MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3365 const char *client_name)
3368 filename[MagickPathExtent];
3380 if (display == (Display *) NULL)
3381 return((XrmDatabase) NULL);
3382 assert(client_name != (
char *) NULL);
3387 (void) XGetDefault(display,(
char *) client_name,
"dummy");
3388 resource_database=XrmGetDatabase(display);
3392 p=client_name+(strlen(client_name)-1);
3393 while ((p > client_name) && (*p !=
'/'))
3397 c=(int) (*client_name);
3398 if ((c >= XK_a) && (c <= XK_z))
3401 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3402 c-=(XK_agrave-XK_Agrave);
3404 if ((c >= XK_oslash) && (c <= XK_thorn))
3405 c-=(XK_oslash-XK_Ooblique);
3406#if defined(X11_APPLICATION_PATH)
3407 (void) FormatLocaleString(filename,MagickPathExtent,
"%s%c%s",
3408 X11_APPLICATION_PATH,c,client_name+1);
3409 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3411 if (XResourceManagerString(display) != (
char *) NULL)
3416 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3417 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3422#if defined(X11_PREFERENCES_PATH)
3423 (void) FormatLocaleString(filename,MagickPathExtent,
"%s%src",
3424 X11_PREFERENCES_PATH,client_name);
3425 ExpandFilename(filename);
3426 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3428 return(resource_database);
3462MagickExport
void XGetResourceInfo(
const ImageInfo *image_info,
3463 XrmDatabase database,
const char *client_name,XResourceInfo *resource_info)
3472 assert(resource_info != (XResourceInfo *) NULL);
3473 if (IsEventLogging() != MagickFalse)
3474 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3475 (void) memset(resource_info,0,
sizeof(*resource_info));
3476 resource_info->resource_database=database;
3477 resource_info->image_info=(
ImageInfo *) image_info;
3478 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3479 XMagickProgressMonitor,(
void *) NULL);
3480 resource_info->quantize_info=CloneQuantizeInfo((
QuantizeInfo *) NULL);
3481 resource_info->close_server=MagickTrue;
3482 resource_info->client_name=AcquireString(client_name);
3483 resource_value=XGetResourceClass(database,client_name,
"backdrop",
3485 resource_info->backdrop=IsStringTrue(resource_value);
3486 resource_info->background_color=XGetResourceInstance(database,client_name,
3487 "background",(
char *)
"#d6d6d6d6d6d6");
3488 resource_info->border_color=XGetResourceInstance(database,client_name,
3489 "borderColor",BorderColor);
3490 resource_value=XGetResourceClass(database,client_name,
"borderWidth",
3492 resource_info->border_width=(
unsigned int) StringToUnsignedLong(
3494 resource_value=XGetResourceClass(database,client_name,
"colormap",
3496 resource_info->colormap=UndefinedColormap;
3497 if (LocaleCompare(
"private",resource_value) == 0)
3498 resource_info->colormap=PrivateColormap;
3499 if (LocaleCompare(
"shared",resource_value) == 0)
3500 resource_info->colormap=SharedColormap;
3501 if (resource_info->colormap == UndefinedColormap)
3502 ThrowXWindowException(OptionError,
"UnrecognizedColormapType",
3504 resource_value=XGetResourceClass(database,client_name,
3505 "colorRecovery",(
char *)
"False");
3506 resource_info->color_recovery=IsStringTrue(resource_value);
3507 resource_value=XGetResourceClass(database,client_name,
"confirmExit",
3509 resource_info->confirm_exit=IsStringTrue(resource_value);
3510 resource_value=XGetResourceClass(database,client_name,
"confirmEdit",
3512 resource_info->confirm_edit=IsStringTrue(resource_value);
3513 resource_value=XGetResourceClass(database,client_name,
"delay",(
char *)
"1");
3514 resource_info->delay=(
unsigned int) StringToUnsignedLong(resource_value);
3515 resource_info->display_gamma=XGetResourceClass(database,client_name,
3516 "displayGamma",(
char *)
"2.2");
3517 resource_value=XGetResourceClass(database,client_name,
"displayWarnings",
3519 resource_info->display_warnings=IsStringTrue(resource_value);
3520 resource_info->font=XGetResourceClass(database,client_name,
"font",
3522 resource_info->font=XGetResourceClass(database,client_name,
"fontList",
3523 resource_info->font);
3524 resource_info->font_name[0]=XGetResourceClass(database,client_name,
"font1",
3526 resource_info->font_name[1]=XGetResourceClass(database,client_name,
"font2",
3527 (
char *)
"variable");
3528 resource_info->font_name[2]=XGetResourceClass(database,client_name,
"font3",
3530 resource_info->font_name[3]=XGetResourceClass(database,client_name,
"font4",
3532 resource_info->font_name[4]=XGetResourceClass(database,client_name,
"font5",
3533 (
char *)
"7x13bold");
3534 resource_info->font_name[5]=XGetResourceClass(database,client_name,
"font6",
3535 (
char *)
"8x13bold");
3536 resource_info->font_name[6]=XGetResourceClass(database,client_name,
"font7",
3537 (
char *)
"9x15bold");
3538 resource_info->font_name[7]=XGetResourceClass(database,client_name,
"font8",
3540 resource_info->font_name[8]=XGetResourceClass(database,client_name,
"font9",
3542 resource_info->font_name[9]=XGetResourceClass(database,client_name,
"font0",
3544 resource_info->font_name[10]=XGetResourceClass(database,client_name,
"font0",
3546 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3547 "foreground",ForegroundColor);
3548 resource_value=XGetResourceClass(database,client_name,
"gammaCorrect",
3550 resource_info->gamma_correct=IsStringTrue(resource_value);
3551 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3552 client_name,
"geometry",(
char *) NULL));
3553 resource_value=XGetResourceClass(database,client_name,
"gravity",
3555 resource_info->gravity=(int) ParseCommandOption(MagickGravityOptions,
3556 MagickFalse,resource_value);
3557 directory=getcwd(resource_info->home_directory,MagickPathExtent);
3559 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3560 "iconGeometry",(
char *) NULL);
3561 resource_value=XGetResourceClass(database,client_name,
"iconic",
3563 resource_info->iconic=IsStringTrue(resource_value);
3564 resource_value=XGetResourceClass(database,client_name,
"immutable",
3565 LocaleCompare(client_name,
"PerlMagick") == 0 ? (
char *)
"True" :
3567 resource_info->immutable=IsStringTrue(resource_value);
3568 resource_value=XGetResourceClass(database,client_name,
"magnify",
3570 resource_info->magnify=(
unsigned int) StringToUnsignedLong(resource_value);
3571 resource_info->map_type=XGetResourceClass(database,client_name,
"map",
3573 resource_info->matte_color=XGetResourceInstance(database,client_name,
3574 "mattecolor",(
char *) NULL);
3575 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3576 "name",(
char *) NULL));
3577 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,
"pen1",
3579 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,
"pen2",
3581 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,
"pen3",
3583 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,
"pen4",
3585 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,
"pen5",
3587 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,
"pen6",
3589 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,
"pen7",
3590 (
char *)
"magenta");
3591 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,
"pen8",
3593 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,
"pen9",
3595 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,
"pen0",
3597 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,
"pen0",
3599 resource_value=XGetResourceClass(database,client_name,
"pause",(
char *)
"0");
3600 resource_info->pause=(
unsigned int) StringToUnsignedLong(resource_value);
3601 resource_value=XGetResourceClass(database,client_name,
"quantum",(
char *)
"1");
3602 resource_info->quantum=StringToLong(resource_value);
3603 resource_info->text_font=XGetResourceClass(database,client_name,(
char *)
3604 "font",(
char *)
"fixed");
3605 resource_info->text_font=XGetResourceClass(database,client_name,
3606 "textFontList",resource_info->text_font);
3607 resource_info->title=XGetResourceClass(database,client_name,
"title",
3609 resource_value=XGetResourceClass(database,client_name,
"undoCache",
3611 resource_info->undo_cache=(
unsigned int) StringToUnsignedLong(resource_value);
3612 resource_value=XGetResourceClass(database,client_name,
"update",
3614 resource_info->update=IsStringTrue(resource_value);
3615 resource_value=XGetResourceClass(database,client_name,
"usePixmap",
3617 resource_info->use_pixmap=IsStringTrue(resource_value);
3618 resource_value=XGetResourceClass(database,client_name,
"sharedMemory",
3620 resource_info->use_shared_memory=IsStringTrue(resource_value);
3621 resource_info->visual_type=XGetResourceClass(database,client_name,
"visual",
3623 resource_info->window_group=XGetResourceClass(database,client_name,
3624 "windowGroup",(
char *) NULL);
3625 resource_info->window_id=XGetResourceClass(database,client_name,
"window",
3627 resource_info->write_filename=XGetResourceClass(database,client_name,
3628 "writeFilename",(
char *) NULL);
3629 resource_info->debug=(GetLogEventMask() & X11Event) != 0 ? MagickTrue :
3667MagickExport
char *XGetResourceInstance(XrmDatabase database,
3668 const char *client_name,
const char *keyword,
const char *resource_default)
3672 resource_name[MagickPathExtent];
3680 if (database == (XrmDatabase) NULL)
3681 return((
char *) resource_default);
3682 *resource_name=
'\0';
3683 if (keyword != (
char *) NULL)
3684 (void) FormatLocaleString(resource_name,MagickPathExtent,
"%s.%s",client_name,
3686 status=XrmGetResource(database,resource_name,
"ImageMagick",&resource_type,
3688 if (status == False)
3689 return((
char *) resource_default);
3690 return(resource_value.addr);
3720MagickExport
char *XGetScreenDensity(Display *display)
3723 density[MagickPathExtent];
3732 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3733 ((
double) DisplayWidthMM(display,XDefaultScreen(display))));
3734 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3735 ((
double) DisplayHeightMM(display,XDefaultScreen(display))));
3736 (void) FormatLocaleString(density,MagickPathExtent,
"%gx%g",x_density,
3738 return(GetPageGeometry(density));
3776static Window XGetSubwindow(Display *display,Window window,
int x,
int y)
3789 assert(display != (Display *) NULL);
3790 source_window=XRootWindow(display,XDefaultScreen(display));
3791 if (window == (Window) NULL)
3792 return(source_window);
3793 target_window=window;
3796 status=XTranslateCoordinates(display,source_window,window,x,y,
3797 &x_offset,&y_offset,&target_window);
3800 if (target_window == (Window) NULL)
3802 source_window=window;
3803 window=target_window;
3807 if (target_window == (Window) NULL)
3808 target_window=window;
3809 return(target_window);
3844MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
3878 assert(display != (Display *) NULL);
3879 assert(name != (
char *) NULL);
3880 if (IsEventLogging() != MagickFalse)
3881 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
3883 target_window=XSelectWindow(display,&crop_info);
3884 if (target_window == (Window) NULL)
3885 return(MagickFalse);
3886 root_window=XRootWindow(display,XDefaultScreen(display));
3887 client_window=target_window;
3888 if (target_window != root_window)
3896 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3897 if (status != False)
3899 client_window=XClientWindow(display,target_window);
3900 target_window=client_window;
3906 status=XGetWindowAttributes(display,target_window,&window_attributes);
3907 if ((status == False) || (window_attributes.map_state != IsViewable))
3908 return(MagickFalse);
3912 (void) XTranslateCoordinates(display,root_window,target_window,
3913 (
int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3914 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3915 if (ximage == (XImage *) NULL)
3916 return(MagickFalse);
3917 color.pixel=XGetPixel(ximage,0,0);
3918 XDestroyImage(ximage);
3922 (void) XQueryColor(display,window_attributes.colormap,&color);
3923 pixel.red=(double) ScaleShortToQuantum(color.red);
3924 pixel.green=(double) ScaleShortToQuantum(color.green);
3925 pixel.blue=(double) ScaleShortToQuantum(color.blue);
3926 pixel.alpha=(MagickRealType) OpaqueAlpha;
3927 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3974static Image *XGetWindowImage(Display *display,
const Window window,
3975 const unsigned int borders,
const unsigned int level,
ExceptionInfo *exception)
3989 typedef struct _WindowInfo
4047 assert(display != (Display *) NULL);
4048 if (IsEventLogging() != MagickFalse)
4049 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4050 status=XGetWindowAttributes(display,window,&window_attributes);
4051 if ((status == False) || (window_attributes.map_state != IsViewable))
4052 return((
Image *) NULL);
4056 root_window=XRootWindow(display,XDefaultScreen(display));
4057 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4059 crop_info.x=(ssize_t) x_offset;
4060 crop_info.y=(ssize_t) y_offset;
4061 crop_info.width=(size_t) window_attributes.width;
4062 crop_info.height=(size_t) window_attributes.height;
4063 if (borders != MagickFalse)
4068 crop_info.x-=(ssize_t) window_attributes.border_width;
4069 crop_info.y-=(ssize_t) window_attributes.border_width;
4070 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4071 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4076 if (crop_info.x < 0)
4078 crop_info.width=(
unsigned int) ((
int) crop_info.width+crop_info.x);
4081 if (crop_info.y < 0)
4083 crop_info.height=(
unsigned int) ((
int) crop_info.height+crop_info.y);
4086 display_width=XDisplayWidth(display,XDefaultScreen(display));
4087 if ((crop_info.x+(
int) crop_info.width) > display_width)
4088 crop_info.width=(size_t) (display_width-crop_info.x);
4089 display_height=XDisplayHeight(display,XDefaultScreen(display));
4090 if ((crop_info.y+(
int) crop_info.height) > display_height)
4091 crop_info.height=(size_t) (display_height-crop_info.y);
4095 if (number_windows >= max_windows)
4101 if (window_info == (WindowInfo *) NULL)
4102 window_info=(WindowInfo *) AcquireQuantumMemory((
size_t) max_windows,
4103 sizeof(*window_info));
4105 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(
size_t)
4106 max_windows,
sizeof(*window_info));
4108 if (window_info == (WindowInfo *) NULL)
4110 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
"...");
4111 return((
Image *) NULL);
4113 id=number_windows++;
4114 window_info[id].window=window;
4115 window_info[id].visual=window_attributes.visual;
4116 window_info[id].colormap=window_attributes.colormap;
4117 window_info[id].bounds.x1=(short) crop_info.x;
4118 window_info[id].bounds.y1=(short) crop_info.y;
4119 window_info[id].bounds.x2=(short) (crop_info.x+(
int) crop_info.width-1);
4120 window_info[id].bounds.y2=(short) (crop_info.y+(
int) crop_info.height-1);
4121 crop_info.x-=x_offset;
4122 crop_info.y-=y_offset;
4123 window_info[id].crop_info=crop_info;
4135 status=XQueryTree(display,window,&root_window,&window_info[
id].parent,
4136 &children,&number_children);
4137 for (i=0; i < id; i++)
4138 if ((window_info[i].window == window_info[
id].parent) &&
4139 (window_info[i].visual == window_info[
id].visual) &&
4140 (window_info[i].colormap == window_info[
id].colormap))
4142 if ((window_info[
id].bounds.x1 < window_info[i].bounds.x1) ||
4143 (window_info[
id].bounds.x2 > window_info[i].bounds.x2) ||
4144 (window_info[
id].bounds.y1 < window_info[i].bounds.y1) ||
4145 (window_info[
id].bounds.y2 > window_info[i].bounds.y2))
4154 if ((status == True) && (number_children != 0))
4156 for (i=0; i < (int) number_children; i++)
4157 (
void) XGetWindowImage(display,children[i],MagickFalse,level+1,
4159 (void) XFree((
void *) children);
4202 image=NewImageList();
4203 for (
id=0;
id < number_windows;
id++)
4208 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4209 (window_info[
id].bounds.x1 <= window_info[0].bounds.x2) &&
4210 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4211 (window_info[
id].bounds.y1 <= window_info[0].bounds.y2)) ?
4212 MagickTrue : MagickFalse;
4216 for (j=0; j < id; j++)
4217 if ((window_info[
id].visual == window_info[j].visual) &&
4218 (window_info[
id].colormap == window_info[j].colormap))
4220 if ((window_info[
id].bounds.x1 >= window_info[j].bounds.x1) &&
4221 (window_info[
id].bounds.x2 <= window_info[j].bounds.x2) &&
4222 (window_info[
id].bounds.y1 >= window_info[j].bounds.y1) &&
4223 (window_info[
id].bounds.y2 <= window_info[j].bounds.y2))
4226 if (
import == MagickFalse)
4231 ximage=XGetImage(display,window_info[
id].window,(
int)
4232 window_info[
id].crop_info.x,(
int) window_info[
id].crop_info.y,
4233 (
unsigned int) window_info[
id].crop_info.width,(
unsigned int)
4234 window_info[
id].crop_info.height,AllPlanes,ZPixmap);
4235 if (ximage == (XImage *) NULL)
4241 colors=(XColor *) NULL;
4242 if (window_info[
id].colormap != (Colormap) NULL)
4250 number_colors=(
unsigned int) window_info[
id].visual->map_entries;
4251 for (p=colormap_info; p != (
ColormapInfo *) NULL; p=p->next)
4252 if (p->colormap == window_info[
id].colormap)
4259 colors=(XColor *) AcquireQuantumMemory(number_colors,
4261 if (colors == (XColor *) NULL)
4263 XDestroyImage(ximage);
4264 return((
Image *) NULL);
4266 if ((window_info[
id].visual->klass != DirectColor) &&
4267 (window_info[
id].visual->klass != TrueColor))
4268 for (i=0; i < (int) number_colors; i++)
4270 colors[i].pixel=(size_t) i;
4289 red_bit=window_info[id].visual->red_mask &
4290 (~(window_info[id].visual->red_mask)+1);
4291 green_bit=window_info[id].visual->green_mask &
4292 (~(window_info[id].visual->green_mask)+1);
4293 blue_bit=window_info[id].visual->blue_mask &
4294 (~(window_info[id].visual->blue_mask)+1);
4295 for (i=0; i < (int) number_colors; i++)
4297 colors[i].pixel=(
unsigned long) (red | green | blue);
4300 if (red > window_info[
id].visual->red_mask)
4303 if (green > window_info[
id].visual->green_mask)
4306 if (blue > window_info[
id].visual->blue_mask)
4310 (void) XQueryColors(display,window_info[
id].colormap,colors,
4311 (
int) number_colors);
4317 return((
Image *) NULL);
4318 p->colormap=window_info[id].colormap;
4320 p->next=colormap_info;
4328 composite_image=AcquireImage((
ImageInfo *) NULL,exception);
4329 if (composite_image == (
Image *) NULL)
4331 XDestroyImage(ximage);
4332 return((
Image *) NULL);
4337 if ((window_info[
id].visual->klass != TrueColor) &&
4338 (window_info[
id].visual->klass != DirectColor))
4339 composite_image->storage_class=PseudoClass;
4340 composite_image->columns=(size_t) ximage->width;
4341 composite_image->rows=(size_t) ximage->height;
4342 composite_view=AcquireAuthenticCacheView(composite_image,exception);
4343 switch (composite_image->storage_class)
4363 red_mask=window_info[id].visual->red_mask;
4365 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4370 green_mask=window_info[id].visual->green_mask;
4372 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4377 blue_mask=window_info[id].visual->blue_mask;
4379 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4387 if ((number_colors != 0) &&
4388 (window_info[
id].visual->klass == DirectColor))
4389 for (y=0; y < (int) composite_image->rows; y++)
4391 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4392 composite_image->columns,1,exception);
4393 if (q == (Quantum *) NULL)
4395 for (x=0; x < (int) composite_image->columns; x++)
4397 pixel=XGetPixel(ximage,x,y);
4398 index=(pixel >> red_shift) & red_mask;
4399 SetPixelRed(composite_image,
4400 ScaleShortToQuantum(colors[index].red),q);
4401 index=(pixel >> green_shift) & green_mask;
4402 SetPixelGreen(composite_image,
4403 ScaleShortToQuantum(colors[index].green),q);
4404 index=(pixel >> blue_shift) & blue_mask;
4405 SetPixelBlue(composite_image,
4406 ScaleShortToQuantum(colors[index].blue),q);
4407 q+=GetPixelChannels(composite_image);
4409 status=SyncCacheViewAuthenticPixels(composite_view,exception)
4410 == MagickFalse ? 0 : 1;
4411 if (status == MagickFalse)
4415 for (y=0; y < (int) composite_image->rows; y++)
4417 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4418 composite_image->columns,1,exception);
4419 if (q == (Quantum *) NULL)
4421 for (x=0; x < (int) composite_image->columns; x++)
4423 pixel=XGetPixel(ximage,x,y);
4424 color=(pixel >> red_shift) & red_mask;
4426 color=(65535UL*color)/red_mask;
4427 SetPixelRed(composite_image,ScaleShortToQuantum(
4428 (
unsigned short) color),q);
4429 color=(pixel >> green_shift) & green_mask;
4430 if (green_mask != 0)
4431 color=(65535UL*color)/green_mask;
4432 SetPixelGreen(composite_image,ScaleShortToQuantum(
4433 (
unsigned short) color),q);
4434 color=(pixel >> blue_shift) & blue_mask;
4436 color=(65535UL*color)/blue_mask;
4437 SetPixelBlue(composite_image,ScaleShortToQuantum(
4438 (
unsigned short) color),q);
4439 q+=GetPixelChannels(composite_image);
4441 status=SyncCacheViewAuthenticPixels(composite_view,exception)
4442 == MagickFalse ? 0 : 1;
4443 if (status == MagickFalse)
4453 status=AcquireImageColormap(composite_image,number_colors,
4454 exception) == MagickFalse ? 0 : 1;
4455 if (status == MagickFalse)
4457 XDestroyImage(ximage);
4458 composite_image=DestroyImage(composite_image);
4459 return((
Image *) NULL);
4461 if (colors == (XColor *) NULL)
4463 for (i=0; i < (int) composite_image->colors; i++)
4465 composite_image->colormap[colors[i].pixel].red=(double)
4466 ScaleShortToQuantum(colors[i].red);
4467 composite_image->colormap[colors[i].pixel].green=(double)
4468 ScaleShortToQuantum(colors[i].green);
4469 composite_image->colormap[colors[i].pixel].blue=(double)
4470 ScaleShortToQuantum(colors[i].blue);
4475 for (y=0; y < (int) composite_image->rows; y++)
4477 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4478 composite_image->columns,1,exception);
4479 if (q == (Quantum *) NULL)
4481 for (x=0; x < (int) composite_image->columns; x++)
4483 index=(Quantum) XGetPixel(ximage,x,y);
4484 SetPixelIndex(composite_image,index,q);
4485 SetPixelViaPixelInfo(composite_image,
4486 composite_image->colormap+(ssize_t) index,q);
4487 q+=GetPixelChannels(composite_image);
4489 status=SyncCacheViewAuthenticPixels(composite_view,exception)
4490 == MagickFalse ? 0 : 1;
4491 if (status == MagickFalse)
4497 composite_view=DestroyCacheView(composite_view);
4498 XDestroyImage(ximage);
4499 if (image == (
Image *) NULL)
4501 image=composite_image;
4507 (void) XTranslateCoordinates(display,window_info[
id].window,window,0,0,
4508 &x_offset,&y_offset,&child);
4509 x_offset-=(int) crop_info.x;
4512 y_offset-=(int) crop_info.y;
4515 (void) CompositeImage(image,composite_image,CopyCompositeOp,MagickTrue,
4516 (ssize_t) x_offset,(ssize_t) y_offset,exception);
4517 composite_image=DestroyImage(composite_image);
4524 next=colormap_info->next;
4525 colormap_info->colors=(XColor *) RelinquishMagickMemory(
4526 colormap_info->colors);
4527 colormap_info=(
ColormapInfo *) RelinquishMagickMemory(colormap_info);
4533 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4539 return((
Image *) NULL);
4580MagickPrivate
void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4581 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4582 XResourceInfo *resource_info,XWindowInfo *window)
4587 assert(display != (Display *) NULL);
4588 assert(visual_info != (XVisualInfo *) NULL);
4589 assert(map_info != (XStandardColormap *) NULL);
4590 assert(pixel != (XPixelInfo *) NULL);
4591 assert(resource_info != (XResourceInfo *) NULL);
4592 assert(window != (XWindowInfo *) NULL);
4593 if (IsEventLogging() != MagickFalse)
4594 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4595 if (window->id != (Window) NULL)
4597 if (window->cursor != (Cursor) NULL)
4598 (
void) XFreeCursor(display,window->cursor);
4599 if (window->busy_cursor != (Cursor) NULL)
4600 (void) XFreeCursor(display,window->busy_cursor);
4601 if (window->highlight_stipple != (Pixmap) NULL)
4602 (
void) XFreePixmap(display,window->highlight_stipple);
4603 if (window->shadow_stipple != (Pixmap) NULL)
4604 (void) XFreePixmap(display,window->shadow_stipple);
4605 if (window->name == (
char *) NULL)
4606 window->name=AcquireString(
"");
4607 if (window->icon_name == (
char *) NULL)
4608 window->icon_name=AcquireString(
"");
4615 window->id=(Window) NULL;
4616 if (window->name == (
char *) NULL)
4617 window->name=AcquireString(
"");
4618 if (window->icon_name == (
char *) NULL)
4619 window->icon_name=AcquireString(
"");
4620 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4621 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4622 window->ximage=(XImage *) NULL;
4623 window->matte_image=(XImage *) NULL;
4624 window->pixmap=(Pixmap) NULL;
4625 window->matte_pixmap=(Pixmap) NULL;
4626 window->mapped=MagickFalse;
4627 window->stasis=MagickFalse;
4628 window->shared_memory=MagickTrue;
4629 window->segment_info=(
void *) NULL;
4630#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4635 if (window->segment_info == (
void *) NULL)
4636 window->segment_info=AcquireCriticalMemory(2*
sizeof(*segment_info));
4637 segment_info=(XShmSegmentInfo *) window->segment_info;
4638 segment_info[0].shmid=(-1);
4639 segment_info[0].shmaddr=(
char *) NULL;
4640 segment_info[1].shmid=(-1);
4641 segment_info[1].shmaddr=(
char *) NULL;
4648 window->screen=visual_info->screen;
4649 window->root=XRootWindow(display,visual_info->screen);
4650 window->visual=visual_info->visual;
4651 window->storage_class=(
unsigned int) visual_info->klass;
4652 window->depth=(
unsigned int) visual_info->depth;
4653 window->visual_info=visual_info;
4654 window->map_info=map_info;
4655 window->pixel_info=pixel;
4656 window->font_info=font_info;
4657 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4658 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4659 window->geometry=(
char *) NULL;
4660 window->icon_geometry=(
char *) NULL;
4661 if (resource_info->icon_geometry != (
char *) NULL)
4662 (
void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4663 window->crop_geometry=(
char *) NULL;
4664 window->flags=(size_t) PSize;
4667 window->min_width=1;
4668 window->min_height=1;
4669 window->width_inc=1;
4670 window->height_inc=1;
4671 window->border_width=resource_info->border_width;
4672 window->annotate_context=pixel->annotate_context;
4673 window->highlight_context=pixel->highlight_context;
4674 window->widget_context=pixel->widget_context;
4675 window->shadow_stipple=(Pixmap) NULL;
4676 window->highlight_stipple=(Pixmap) NULL;
4677 window->use_pixmap=MagickTrue;
4678 window->immutable=MagickFalse;
4679 window->shape=MagickFalse;
4681 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4682 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4683 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4684 window->attributes.background_pixel=pixel->background_color.pixel;
4685 window->attributes.background_pixmap=(Pixmap) NULL;
4686 window->attributes.bit_gravity=ForgetGravity;
4687 window->attributes.backing_store=WhenMapped;
4688 window->attributes.save_under=MagickTrue;
4689 window->attributes.border_pixel=pixel->border_color.pixel;
4690 window->attributes.colormap=map_info->colormap;
4691 window->attributes.cursor=window->cursor;
4692 window->attributes.do_not_propagate_mask=NoEventMask;
4693 window->attributes.event_mask=NoEventMask;
4694 window->attributes.override_redirect=MagickFalse;
4695 window->attributes.win_gravity=NorthWestGravity;
4696 window->orphan=MagickFalse;
4731MagickPrivate
void XHighlightEllipse(Display *display,Window window,
4734 assert(display != (Display *) NULL);
4735 assert(window != (Window) NULL);
4736 assert(annotate_context != (GC) NULL);
4738 if (IsEventLogging() != MagickFalse)
4739 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4740 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4742 (void) XDrawArc(display,window,annotate_context,(
int) highlight_info->x,
4743 (int) highlight_info->y,(
unsigned int) highlight_info->width-1,
4744 (
unsigned int) highlight_info->height-1,0,360*64);
4745 (void) XDrawArc(display,window,annotate_context,(
int) highlight_info->x+1,
4746 (int) highlight_info->y+1,(
unsigned int) highlight_info->width-3,
4747 (
unsigned int) highlight_info->height-3,0,360*64);
4782MagickPrivate
void XHighlightLine(Display *display,Window window,
4783 GC annotate_context,
const XSegment *highlight_info)
4785 assert(display != (Display *) NULL);
4786 assert(window != (Window) NULL);
4787 assert(annotate_context != (GC) NULL);
4788 assert(highlight_info != (XSegment *) NULL);
4789 if (IsEventLogging() != MagickFalse)
4790 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4791 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4792 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4827MagickPrivate
void XHighlightRectangle(Display *display,Window window,
4830 assert(display != (Display *) NULL);
4831 assert(window != (Window) NULL);
4832 assert(annotate_context != (GC) NULL);
4834 if (IsEventLogging() != MagickFalse)
4835 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4836 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4838 (void) XDrawRectangle(display,window,annotate_context,(
int) highlight_info->x,
4839 (int) highlight_info->y,(
unsigned int) highlight_info->width-1,
4840 (
unsigned int) highlight_info->height-1);
4841 (void) XDrawRectangle(display,window,annotate_context,(
int) highlight_info->x+
4842 1,(int) highlight_info->y+1,(
unsigned int) highlight_info->width-3,
4843 (
unsigned int) highlight_info->height-3);
4909 assert(image_info != (
const ImageInfo *) NULL);
4910 assert(image_info->signature == MagickCoreSignature);
4912 if (IsEventLogging() != MagickFalse)
4913 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
4914 image_info->filename);
4915 display=XOpenDisplay(image_info->server_name);
4916 if (display == (Display *) NULL)
4918 ThrowXWindowException(XServerError,
"UnableToOpenXServer",
4919 XDisplayName(image_info->server_name));
4920 return((
Image *) NULL);
4925 (void) XSetErrorHandler(XError);
4933 root=XRootWindow(display,XDefaultScreen(display));
4934 target=(Window) NULL;
4935 if (*image_info->filename !=
'\0')
4937 if (LocaleCompare(image_info->filename,
"root") == 0)
4944 if (isdigit((
int) ((
unsigned char) *image_info->filename)) != 0)
4945 target=XWindowByID(display,root,(Window)
4946 strtol(image_info->filename,(
char **) NULL,0));
4947 if (target == (Window) NULL)
4948 target=XWindowByName(display,root,image_info->filename);
4949 if (target == (Window) NULL)
4950 ThrowXWindowException(XServerError,
"NoWindowWithSpecifiedIDExists",
4951 image_info->filename);
4957 prior_target=target;
4958 if (target == (Window) NULL)
4959 target=XSelectWindow(display,&crop_info);
4960 if (target == (Window) NULL)
4961 ThrowXWindowException(XServerError,
"UnableToReadXWindowImage",
4962 image_info->filename);
4969 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4970 if (status != False)
4980 status=XQueryTree(display,target,&root,&parent,&children,&d);
4981 if ((status != False) && (children != (Window *) NULL))
4982 (void) XFree((
char *) children);
4983 if ((status == False) || (parent == (Window) NULL) ||
4991 client=XClientWindow(display,target);
4992 if (ximage_info->frame == MagickFalse)
4994 if ((ximage_info->frame == MagickFalse) &&
4995 (prior_target != MagickFalse))
4996 target=prior_target;
4999 if (ximage_info->screen != MagickFalse)
5013 status=XGetWindowAttributes(display,target,&window_attributes);
5014 if (status == False)
5016 ThrowXWindowException(XServerError,
"UnableToReadXWindowAttributes",
5017 image_info->filename);
5018 (void) XCloseDisplay(display);
5019 return((
Image *) NULL);
5021 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5022 crop_info.x=(ssize_t) x;
5023 crop_info.y=(ssize_t) y;
5024 crop_info.width=(size_t) window_attributes.width;
5025 crop_info.height=(size_t) window_attributes.height;
5026 if (ximage_info->borders != 0)
5031 crop_info.x-=window_attributes.border_width;
5032 crop_info.y-=window_attributes.border_width;
5033 crop_info.width+=(size_t) (window_attributes.border_width << 1);
5034 crop_info.height+=(size_t) (window_attributes.border_width << 1);
5042 status=XGetWMColormapWindows(display,target,&children,&number_windows);
5043 if ((status == True) && (number_windows > 0))
5045 ximage_info->descend=MagickTrue;
5046 (void) XFree ((
char *) children);
5048 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5049 if (number_colormaps > 0)
5051 if (number_colormaps > 1)
5052 ximage_info->descend=MagickTrue;
5053 (void) XFree((
char *) colormaps);
5058 if (ximage_info->silent == MagickFalse)
5059 (void) XBell(display,0);
5063 (void) XGrabServer(display);
5064 image=XGetWindowImage(display,target,ximage_info->borders,
5065 ximage_info->descend ? 1U : 0U,exception);
5066 (void) XUngrabServer(display);
5067 if (image == (
Image *) NULL)
5068 ThrowXWindowException(XServerError,
"UnableToReadXWindowImage",
5069 image_info->filename)
5072 (void) CopyMagickString(image->filename,image_info->filename,
5074 if ((crop_info.width != 0) && (crop_info.height != 0))
5082 crop_image=CropImage(image,&crop_info,exception);
5083 if (crop_image != (
Image *) NULL)
5085 image=DestroyImage(image);
5089 status=XGetWMName(display,target,&window_name);
5092 if (*image_info->filename ==
'\0')
5093 (void) CopyMagickString(image->filename,(
char *) window_name.value,
5094 (size_t) window_name.nitems+1);
5095 (void) XFree((
void *) window_name.value);
5098 if (ximage_info->silent == MagickFalse)
5103 (void) XBell(display,0);
5104 (void) XBell(display,0);
5106 (void) XCloseDisplay(display);
5138MagickPrivate XWindows *XInitializeWindows(Display *display,
5139 XResourceInfo *resource_info)
5150 windows=(XWindows *) AcquireMagickMemory(
sizeof(*windows));
5151 if (windows == (XWindows *) NULL)
5153 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5155 return((XWindows *) NULL);
5157 (void) memset(windows,0,
sizeof(*windows));
5158 windows->pixel_info=(XPixelInfo *) AcquireQuantumMemory(1,
5159 sizeof(*windows->pixel_info));
5160 windows->icon_pixel=(XPixelInfo *) AcquireQuantumMemory(1,
5161 sizeof(*windows->icon_pixel));
5162 windows->icon_resources=(XResourceInfo *) AcquireQuantumMemory(1,
5163 sizeof(*windows->icon_resources));
5164 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5165 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5166 (windows->icon_resources == (XResourceInfo *) NULL))
5168 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5170 return((XWindows *) NULL);
5172 (void) memset((
void *) windows->pixel_info,0,
sizeof(XPixelInfo));
5173 (void) memset((
void *) windows->icon_pixel,0,
sizeof(XPixelInfo));
5177 windows->display=display;
5178 windows->wm_protocols=XInternAtom(display,
"WM_PROTOCOLS",MagickFalse);
5179 windows->wm_delete_window=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
5180 windows->wm_take_focus=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
5181 windows->im_protocols=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
5182 windows->im_remote_command=
5183 XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
5184 windows->im_update_widget=XInternAtom(display,
"IM_UPDATE_WIDGET",MagickFalse);
5185 windows->im_update_colormap=
5186 XInternAtom(display,
"IM_UPDATE_COLORMAP",MagickFalse);
5187 windows->im_former_image=XInternAtom(display,
"IM_FORMER_IMAGE",MagickFalse);
5188 windows->im_next_image=XInternAtom(display,
"IM_NEXT_IMAGE",MagickFalse);
5189 windows->im_retain_colors=XInternAtom(display,
"IM_RETAIN_COLORS",MagickFalse);
5190 windows->im_exit=XInternAtom(display,
"IM_EXIT",MagickFalse);
5191 windows->dnd_protocols=XInternAtom(display,
"DndProtocol",MagickFalse);
5192#if defined(MAGICKCORE_WINDOWS_SUPPORT)
5193 (void) XSynchronize(display,MagickFalse);
5195 if ((GetLogEventMask() & X11Event) != 0)
5197 (void) XSynchronize(display,MagickTrue);
5198 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Version: %s",
5199 GetMagickVersion((
size_t *) NULL));
5200 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Protocols:");
5201 (void) LogMagickEvent(X11Event,GetMagickModule(),
5202 " Window Manager: 0x%lx",windows->wm_protocols);
5203 (void) LogMagickEvent(X11Event,GetMagickModule(),
5204 " delete window: 0x%lx",windows->wm_delete_window);
5205 (void) LogMagickEvent(X11Event,GetMagickModule(),
" take focus: 0x%lx",
5206 windows->wm_take_focus);
5207 (void) LogMagickEvent(X11Event,GetMagickModule(),
" ImageMagick: 0x%lx",
5208 windows->im_protocols);
5209 (void) LogMagickEvent(X11Event,GetMagickModule(),
5210 " remote command: 0x%lx",windows->im_remote_command);
5211 (void) LogMagickEvent(X11Event,GetMagickModule(),
5212 " update widget: 0x%lx",windows->im_update_widget);
5213 (void) LogMagickEvent(X11Event,GetMagickModule(),
5214 " update colormap: 0x%lx",windows->im_update_colormap);
5215 (void) LogMagickEvent(X11Event,GetMagickModule(),
5216 " former image: 0x%lx",windows->im_former_image);
5217 (void) LogMagickEvent(X11Event,GetMagickModule(),
" next image: 0x%lx",
5218 windows->im_next_image);
5219 (void) LogMagickEvent(X11Event,GetMagickModule(),
5220 " retain colors: 0x%lx",windows->im_retain_colors);
5221 (void) LogMagickEvent(X11Event,GetMagickModule(),
" exit: 0x%lx",
5223 (void) LogMagickEvent(X11Event,GetMagickModule(),
" Drag and Drop: 0x%lx",
5224 windows->dnd_protocols);
5229 windows->map_info=XAllocStandardColormap();
5230 windows->icon_map=XAllocStandardColormap();
5231 if ((windows->map_info == (XStandardColormap *) NULL) ||
5232 (windows->icon_map == (XStandardColormap *) NULL))
5233 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5235 windows->map_info->colormap=(Colormap) NULL;
5236 windows->icon_map->colormap=(Colormap) NULL;
5237 windows->pixel_info->pixels=(
unsigned long *) NULL;
5238 windows->pixel_info->annotate_context=(GC) NULL;
5239 windows->pixel_info->highlight_context=(GC) NULL;
5240 windows->pixel_info->widget_context=(GC) NULL;
5241 windows->font_info=(XFontStruct *) NULL;
5242 windows->icon_pixel->annotate_context=(GC) NULL;
5243 windows->icon_pixel->pixels=(
unsigned long *) NULL;
5247 *windows->icon_resources=(*resource_info);
5248 windows->icon_resources->visual_type=(
char *)
"default";
5249 windows->icon_resources->colormap=SharedColormap;
5250 windows->visual_info=
5251 XBestVisualInfo(display,windows->map_info,resource_info);
5252 windows->icon_visual=
5253 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5254 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5255 (windows->icon_visual == (XVisualInfo *) NULL))
5256 ThrowXWindowFatalException(XServerFatalError,
"UnableToGetVisual",
5257 resource_info->visual_type);
5258 if ((GetLogEventMask() & X11Event) != 0)
5260 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Visual:");
5261 (void) LogMagickEvent(X11Event,GetMagickModule(),
" visual id: 0x%lx",
5262 windows->visual_info->visualid);
5263 (void) LogMagickEvent(X11Event,GetMagickModule(),
" class: %s",
5264 XVisualClassName(windows->visual_info->klass));
5265 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d planes",
5266 windows->visual_info->depth);
5267 (void) LogMagickEvent(X11Event,GetMagickModule(),
5268 " size of colormap: %d entries",windows->visual_info->colormap_size);
5269 (void) LogMagickEvent(X11Event,GetMagickModule(),
5270 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5271 windows->visual_info->red_mask,windows->visual_info->green_mask,
5272 windows->visual_info->blue_mask);
5273 (void) LogMagickEvent(X11Event,GetMagickModule(),
5274 " significant bits in color: %d bits",
5275 windows->visual_info->bits_per_rgb);
5280 windows->class_hints=XAllocClassHint();
5281 windows->manager_hints=XAllocWMHints();
5282 if ((windows->class_hints == (XClassHint *) NULL) ||
5283 (windows->manager_hints == (XWMHints *) NULL))
5284 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5289 root_window=XRootWindow(display,windows->visual_info->screen);
5290 windows->group_leader.id=(Window) NULL;
5291 if (resource_info->window_group != (
char *) NULL)
5293 if (isdigit((
int) ((
unsigned char) *resource_info->window_group)) != 0)
5294 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5295 strtol((
char *) resource_info->window_group,(
char **) NULL,0));
5296 if (windows->group_leader.id == (Window) NULL)
5297 windows->group_leader.id=
5298 XWindowByName(display,root_window,resource_info->window_group);
5337MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5338 Colormap colormap,
char *background_color,
char *foreground_color)
5340#define scope_height 17
5341#define scope_x_hot 8
5342#define scope_y_hot 8
5343#define scope_width 17
5345 static const unsigned char
5348 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5349 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5350 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5351 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5352 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5356 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5357 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5358 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5359 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5360 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5374 assert(display != (Display *) NULL);
5375 assert(window != (Window) NULL);
5376 assert(colormap != (Colormap) NULL);
5377 assert(background_color != (
char *) NULL);
5378 assert(foreground_color != (
char *) NULL);
5379 if (IsEventLogging() != MagickFalse)
5380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",background_color);
5381 source=XCreateBitmapFromData(display,window,(
char *) scope_bits,scope_width,
5383 mask=XCreateBitmapFromData(display,window,(
char *) scope_mask_bits,
5384 scope_width,scope_height);
5385 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5387 ThrowXWindowException(XServerError,
"UnableToCreatePixmap",
"...");
5388 return((Cursor) NULL);
5390 (void) XParseColor(display,colormap,background_color,&background);
5391 (void) XParseColor(display,colormap,foreground_color,&foreground);
5392 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5393 scope_x_hot,scope_y_hot);
5394 (void) XFreePixmap(display,source);
5395 (void) XFreePixmap(display,mask);
5439MagickPrivate MagickBooleanType XMakeImage(Display *display,
5440 const XResourceInfo *resource_info,XWindowInfo *window,
Image *image,
5441 unsigned int width,
unsigned int height,
ExceptionInfo *exception)
5443#define CheckOverflowException(length,width,height) \
5444 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5454 assert(display != (Display *) NULL);
5455 assert(resource_info != (XResourceInfo *) NULL);
5456 assert(window != (XWindowInfo *) NULL);
5458 assert(height != 0);
5459 if (IsEventLogging() != MagickFalse)
5460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
5461 if ((window->width == 0) || (window->height == 0))
5462 return(MagickFalse);
5466 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5467 (void) XFlush(display);
5468 depth=(int) window->depth;
5469 if (window->destroy)
5470 window->image=DestroyImage(window->image);
5471 window->image=image;
5472 window->destroy=MagickFalse;
5473 if (window->image != (
Image *) NULL)
5475 if (window->crop_geometry != (
char *) NULL)
5486 window->image->page.x=0;
5487 window->image->page.y=0;
5488 (void) ParsePageGeometry(window->image,window->crop_geometry,
5489 &crop_info,exception);
5490 crop_image=CropImage(window->image,&crop_info,exception);
5491 if (crop_image != (
Image *) NULL)
5493 if (window->image != image)
5494 window->image=DestroyImage(window->image);
5495 window->image=crop_image;
5496 window->destroy=MagickTrue;
5499 if ((width != (
unsigned int) window->image->columns) ||
5500 (height != (
unsigned int) window->image->rows))
5508 resize_image=NewImageList();
5509 if ((window->pixel_info->colors == 0) &&
5510 (window->image->rows > (
unsigned long) XDisplayHeight(display,window->screen)) &&
5511 (window->image->columns > (
unsigned long) XDisplayWidth(display,window->screen)))
5512 resize_image=ResizeImage(window->image,width,height,
5513 image->filter,exception);
5516 if (window->image->storage_class == PseudoClass)
5517 resize_image=SampleImage(window->image,width,height,
5520 resize_image=ThumbnailImage(window->image,width,height,
5523 if (resize_image != (
Image *) NULL)
5525 if (window->image != image)
5526 window->image=DestroyImage(window->image);
5527 window->image=resize_image;
5528 window->destroy=MagickTrue;
5531 width=(
unsigned int) window->image->columns;
5532 assert((
size_t) width == window->image->columns);
5533 height=(
unsigned int) window->image->rows;
5534 assert((
size_t) height == window->image->rows);
5539 ximage=(XImage *) NULL;
5540 format=(depth == 1) ? XYBitmap : ZPixmap;
5541#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5542 if (window->shared_memory != MagickFalse)
5550 segment_info=(XShmSegmentInfo *) window->segment_info;
5551 segment_info[1].shmid=(-1);
5552 segment_info[1].shmaddr=(
char *) NULL;
5553 ximage=XShmCreateImage(display,window->visual,(
unsigned int) depth,format,
5554 (
char *) NULL,&segment_info[1],width,height);
5556 if (ximage == (XImage *) NULL)
5557 window->shared_memory=MagickFalse;
5560 length=(size_t) (ximage->bytes_per_line*ximage->height);
5561 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5562 window->shared_memory=MagickFalse;
5564 if (window->shared_memory != MagickFalse)
5565 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5566 if (window->shared_memory != MagickFalse)
5567 segment_info[1].shmaddr=(
char *) shmat(segment_info[1].shmid,0,0);
5568 if (segment_info[1].shmid < 0)
5569 window->shared_memory=MagickFalse;
5570 if (window->shared_memory != MagickFalse)
5571 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5574 if (ximage != (XImage *) NULL)
5575 XDestroyImage(ximage);
5576 ximage=(XImage *) NULL;
5577 if (segment_info[1].shmaddr)
5579 (void) shmdt(segment_info[1].shmaddr);
5580 segment_info[1].shmaddr=(
char *) NULL;
5582 if (segment_info[1].shmid >= 0)
5584 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5585 segment_info[1].shmid=(-1);
5593#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5594 if (window->shared_memory)
5602 (void) XSync(display,MagickFalse);
5603 xerror_alert=MagickFalse;
5604 segment_info=(XShmSegmentInfo *) window->segment_info;
5605 ximage->data=segment_info[1].shmaddr;
5606 segment_info[1].readOnly=MagickFalse;
5607 status=XShmAttach(display,&segment_info[1]);
5608 if (status != False)
5609 (void) XSync(display,MagickFalse);
5610 if ((status == False) || (xerror_alert != MagickFalse))
5612 window->shared_memory=MagickFalse;
5613 if (status != False)
5614 XShmDetach(display,&segment_info[1]);
5616 XDestroyImage(ximage);
5617 ximage=(XImage *) NULL;
5618 if (segment_info[1].shmid >= 0)
5620 if (segment_info[1].shmaddr != NULL)
5621 (void) shmdt(segment_info[1].shmaddr);
5622 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5623 segment_info[1].shmid=(-1);
5624 segment_info[1].shmaddr=(
char *) NULL;
5629 if (window->shared_memory == MagickFalse)
5630 ximage=XCreateImage(display,window->visual,(
unsigned int) depth,format,0,
5631 (
char *) NULL,width,height,XBitmapPad(display),0);
5632 if (ximage == (XImage *) NULL)
5637 (void) XCheckDefineCursor(display,window->id,window->cursor);
5638 return(MagickFalse);
5640 if ((GetLogEventMask() & X11Event) != 0)
5642 (void) LogMagickEvent(X11Event,GetMagickModule(),
"XImage:");
5643 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %dx%d",
5644 ximage->width,ximage->height);
5645 (void) LogMagickEvent(X11Event,GetMagickModule(),
" format: %d",
5647 (void) LogMagickEvent(X11Event,GetMagickModule(),
" byte order: %d",
5648 ximage->byte_order);
5649 (void) LogMagickEvent(X11Event,GetMagickModule(),
5650 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5651 ximage->bitmap_bit_order,ximage->bitmap_pad);
5652 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d",
5654 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bytes per line: %d",
5655 ximage->bytes_per_line);
5656 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bits per pixel: %d",
5657 ximage->bits_per_pixel);
5658 (void) LogMagickEvent(X11Event,GetMagickModule(),
5659 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5660 ximage->green_mask,ximage->blue_mask);
5662 if (window->shared_memory == MagickFalse)
5664 if (ximage->format == XYBitmap)
5666 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5667 ximage->bytes_per_line,(size_t) (ximage->depth*ximage->height));
5668 if (ximage->data != (
char *) NULL)
5669 (
void) memset(ximage->data,0,(
size_t)
5670 (ximage->bytes_per_line*ximage->depth*ximage->height));
5674 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5675 ximage->bytes_per_line,(size_t) ximage->height);
5676 if (ximage->data != (
char *) NULL)
5677 (
void) memset(ximage->data,0,(
size_t)
5678 (ximage->bytes_per_line*ximage->height));
5681 if (ximage->data == (
char *) NULL)
5686 XDestroyImage(ximage);
5687 ximage=(XImage *) NULL;
5688 (void) XCheckDefineCursor(display,window->id,window->cursor);
5689 return(MagickFalse);
5691 if (window->ximage != (XImage *) NULL)
5696#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5697 if (window->segment_info != (XShmSegmentInfo *) NULL)
5702 segment_info=(XShmSegmentInfo *) window->segment_info;
5703 if (segment_info[0].shmid >= 0)
5705 (void) XSync(display,MagickFalse);
5706 (void) XShmDetach(display,&segment_info[0]);
5707 (void) XSync(display,MagickFalse);
5708 if (segment_info[0].shmaddr != (
char *) NULL)
5709 (
void) shmdt(segment_info[0].shmaddr);
5710 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5711 segment_info[0].shmid=(-1);
5712 segment_info[0].shmaddr=(
char *) NULL;
5713 window->ximage->data=(
char *) NULL;
5717 if (window->ximage->data != (
char *) NULL)
5718 free(window->ximage->data);
5719 window->ximage->data=(
char *) NULL;
5720 XDestroyImage(window->ximage);
5721 window->ximage=(XImage *) NULL;
5723#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5724 if (window->segment_info != (XShmSegmentInfo *) NULL)
5729 segment_info=(XShmSegmentInfo *) window->segment_info;
5730 segment_info[0]=segment_info[1];
5733 window->ximage=ximage;
5734 matte_image=(XImage *) NULL;
5735 if ((window->shape != MagickFalse) && (window->image != (
Image *) NULL))
5736 if ((window->image->alpha_trait != UndefinedPixelTrait) &&
5737 ((int) width <= XDisplayWidth(display,window->screen)) &&
5738 ((
int) height <= XDisplayHeight(display,window->screen)))
5743 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5744 (
char *) NULL,width,height,XBitmapPad(display),0);
5745 if ((GetLogEventMask() & X11Event) != 0)
5747 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Matte Image:");
5748 (void) LogMagickEvent(X11Event,GetMagickModule(),
5749 " width, height: %dx%d",matte_image->width,matte_image->height);
5751 if (matte_image != (XImage *) NULL)
5756 matte_image->data=(
char *) malloc((
size_t)
5757 (matte_image->bytes_per_line*matte_image->depth*
5758 matte_image->height));
5759 if (matte_image->data == (
char *) NULL)
5761 XDestroyImage(matte_image);
5762 matte_image=(XImage *) NULL;
5766 if (window->matte_image != (XImage *) NULL)
5771 if (window->matte_image->data != (
char *) NULL)
5772 free(window->matte_image->data);
5773 window->matte_image->data=(
char *) NULL;
5774 XDestroyImage(window->matte_image);
5775 window->matte_image=(XImage *) NULL;
5777 window->matte_image=matte_image;
5778 if (window->matte_pixmap != (Pixmap) NULL)
5780 (void) XFreePixmap(display,window->matte_pixmap);
5781 window->matte_pixmap=(Pixmap) NULL;
5782#if defined(MAGICKCORE_HAVE_SHAPE)
5783 if (window->shape != MagickFalse)
5784 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5787 window->stasis=MagickFalse;
5791 if (window->image != (
Image *) NULL)
5793 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5794 (ximage->bitmap_bit_order == LSBFirst)))
5795 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5796 matte_image,exception);
5798 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5799 matte_image,exception);
5801 if (window->matte_image != (XImage *) NULL)
5806 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5807 if (window->matte_pixmap != (Pixmap) NULL)
5818 context_values.background=0;
5819 context_values.foreground=1;
5820 graphics_context=XCreateGC(display,window->matte_pixmap,
5821 (
size_t) (GCBackground | GCForeground),&context_values);
5822 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5823 window->matte_image,0,0,0,0,width,height);
5824 (void) XFreeGC(display,graphics_context);
5825#if defined(MAGICKCORE_HAVE_SHAPE)
5826 if (window->shape != MagickFalse)
5827 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5828 window->matte_pixmap,ShapeSet);
5832 (void) XMakePixmap(display,resource_info,window);
5836 (void) XCheckDefineCursor(display,window->id,window->cursor);
5879static void XMakeImageLSBFirst(
const XResourceInfo *resource_info,
5880 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
5915 assert(resource_info != (XResourceInfo *) NULL);
5916 assert(window != (XWindowInfo *) NULL);
5917 assert(image != (
Image *) NULL);
5918 if (IsEventLogging() != MagickFalse)
5919 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5921 if ((window->immutable == MagickFalse) &&
5922 (image->storage_class == DirectClass) &&
5923 (image->alpha_trait != UndefinedPixelTrait))
5926 size[MagickPathExtent];
5934 image_info=AcquireImageInfo();
5935 (void) CopyMagickString(image_info->filename,
5936 resource_info->image_info->texture != (
char *) NULL ?
5937 resource_info->image_info->texture :
"pattern:checkerboard",
5939 (void) FormatLocaleString(size,MagickPathExtent,
"%.20gx%.20g",(
double)
5940 image->columns,(double) image->rows);
5941 image_info->size=ConstantString(size);
5942 pattern=ReadImage(image_info,exception);
5943 image_info=DestroyImageInfo(image_info);
5944 if (pattern != (
Image *) NULL)
5946 canvas=CloneImage(image,0,0,MagickTrue,exception);
5947 if (canvas == (
Image *) NULL)
5949 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
5951 pattern=DestroyImage(pattern);
5954 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
5955 ximage->bits_per_pixel) >> 3));
5956 map_info=window->map_info;
5957 pixels=window->pixel_info->pixels;
5958 q=(
unsigned char *) ximage->data;
5960 canvas_view=AcquireVirtualCacheView(canvas,exception);
5961 if (ximage->format == XYBitmap)
5973 background=(
unsigned char)
5974 (XPixelIntensity(&window->pixel_info->foreground_color) <
5975 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5976 foreground=(
unsigned char)
5977 (XPixelIntensity(&window->pixel_info->background_color) <
5978 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5979 polarity=(
unsigned short) ((GetPixelInfoIntensity(image,
5980 &canvas->colormap[0])) < ((
double) QuantumRange/2.0) ? 1 : 0);
5981 if (canvas->colors == 2)
5982 polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
5983 GetPixelInfoIntensity(image,&canvas->colormap[1]);
5984 for (y=0; y < (int) canvas->rows; y++)
5986 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5988 if (p == (
const Quantum *) NULL)
5992 for (x=0; x < (int) canvas->columns; x++)
5995 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6006 p+=GetPixelChannels(canvas);
6014 if (window->pixel_info->colors != 0)
6015 switch (ximage->bits_per_pixel)
6025 for (y=0; y < (int) canvas->rows; y++)
6027 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6028 canvas->columns,1,exception);
6029 if (p == (
const Quantum *) NULL)
6032 for (x=0; x < (int) canvas->columns; x++)
6034 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
6039 *q=(
unsigned char) pixel;
6045 *q|=(
unsigned char) (pixel << 2);
6051 *q|=(
unsigned char) (pixel << 4);
6057 *q|=(
unsigned char) (pixel << 6);
6063 p+=GetPixelChannels(canvas);
6077 for (y=0; y < (int) canvas->rows; y++)
6079 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6080 canvas->columns,1,exception);
6081 if (p == (
const Quantum *) NULL)
6084 for (x=0; x < (int) canvas->columns; x++)
6086 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6091 *q=(
unsigned char) pixel;
6097 *q|=(
unsigned char) (pixel << 4);
6103 p+=GetPixelChannels(canvas);
6115 if (resource_info->color_recovery &&
6116 resource_info->quantize_info->dither_method != NoDitherMethod)
6118 XDitherImage(canvas,ximage,exception);
6121 for (y=0; y < (int) canvas->rows; y++)
6123 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6124 canvas->columns,1,exception);
6125 if (p == (
const Quantum *) NULL)
6127 for (x=0; x < (int) canvas->columns; x++)
6129 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6130 *q++=(
unsigned char) pixel;
6131 p+=GetPixelChannels(canvas);
6148 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6149 for (y=0; y < (int) canvas->rows; y++)
6151 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6152 canvas->columns,1,exception);
6153 if (p == (
const Quantum *) NULL)
6155 for (x=0; x < (int) canvas->columns; x++)
6157 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6158 for (k=0; k < (int) bytes_per_pixel; k++)
6160 *q++=(
unsigned char) (pixel & 0xff);
6163 p+=GetPixelChannels(canvas);
6171 switch (ximage->bits_per_pixel)
6181 for (y=0; y < (int) canvas->rows; y++)
6184 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6185 canvas->columns,1,exception);
6186 if (p == (
const Quantum *) NULL)
6188 for (x=0; x < (int) canvas->columns; x++)
6190 pixel=XGammaPixel(canvas,map_info,p);
6196 *q=(
unsigned char) pixel;
6202 *q|=(
unsigned char) (pixel << 2);
6208 *q|=(
unsigned char) (pixel << 4);
6214 *q|=(
unsigned char) (pixel << 6);
6220 p+=GetPixelChannels(canvas);
6234 for (y=0; y < (int) canvas->rows; y++)
6236 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6237 canvas->columns,1,exception);
6238 if (p == (
const Quantum *) NULL)
6241 for (x=0; x < (int) canvas->columns; x++)
6243 pixel=XGammaPixel(canvas,map_info,p);
6249 *q=(
unsigned char) pixel;
6255 *q|=(
unsigned char) (pixel << 4);
6261 p+=GetPixelChannels(canvas);
6273 if (resource_info->color_recovery &&
6274 resource_info->quantize_info->dither_method != NoDitherMethod)
6276 XDitherImage(canvas,ximage,exception);
6279 for (y=0; y < (int) canvas->rows; y++)
6281 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6282 canvas->columns,1,exception);
6283 if (p == (
const Quantum *) NULL)
6285 for (x=0; x < (int) canvas->columns; x++)
6287 pixel=XGammaPixel(canvas,map_info,p);
6288 *q++=(
unsigned char) pixel;
6289 p+=GetPixelChannels(canvas);
6297 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6298 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6299 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6300 (map_info->blue_mult == 1))
6305 for (y=0; y < (int) canvas->rows; y++)
6307 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6308 canvas->columns,1,exception);
6309 if (p == (
const Quantum *) NULL)
6311 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6312 (blue_gamma != 1.0))
6317 for (x=(
int) canvas->columns-1; x >= 0; x--)
6319 *q++=ScaleQuantumToChar(XBlueGamma(
6320 GetPixelBlue(canvas,p)));
6321 *q++=ScaleQuantumToChar(XGreenGamma(
6322 GetPixelGreen(canvas,p)));
6323 *q++=ScaleQuantumToChar(XRedGamma(
6324 GetPixelRed(canvas,p)));
6326 p+=GetPixelChannels(canvas);
6330 for (x=(
int) canvas->columns-1; x >= 0; x--)
6332 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6333 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6334 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6336 p+=GetPixelChannels(canvas);
6341 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6342 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6343 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6344 (map_info->blue_mult == 65536L))
6349 for (y=0; y < (int) canvas->rows; y++)
6351 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6352 canvas->columns,1,exception);
6353 if (p == (
const Quantum *) NULL)
6355 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6356 (blue_gamma != 1.0))
6361 for (x=(
int) canvas->columns-1; x >= 0; x--)
6363 *q++=ScaleQuantumToChar(XRedGamma(
6364 GetPixelRed(canvas,p)));
6365 *q++=ScaleQuantumToChar(XGreenGamma(
6366 GetPixelGreen(canvas,p)));
6367 *q++=ScaleQuantumToChar(XBlueGamma(
6368 GetPixelBlue(canvas,p)));
6370 p+=GetPixelChannels(canvas);
6374 for (x=(
int) canvas->columns-1; x >= 0; x--)
6376 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6377 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6378 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6380 p+=GetPixelChannels(canvas);
6395 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6396 for (y=0; y < (int) canvas->rows; y++)
6398 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6399 canvas->columns,1,exception);
6400 if (p == (
const Quantum *) NULL)
6402 for (x=0; x < (int) canvas->columns; x++)
6404 pixel=XGammaPixel(canvas,map_info,p);
6405 for (k=0; k < (int) bytes_per_pixel; k++)
6407 *q++=(
unsigned char) (pixel & 0xff);
6410 p+=GetPixelChannels(canvas);
6418 if (matte_image != (XImage *) NULL)
6423 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6424 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6425 q=(
unsigned char *) matte_image->data;
6426 for (y=0; y < (int) canvas->rows; y++)
6428 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6430 if (p == (
const Quantum *) NULL)
6434 for (x=(
int) canvas->columns-1; x >= 0; x--)
6437 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6446 p+=GetPixelChannels(canvas);
6453 canvas_view=DestroyCacheView(canvas_view);
6454 if (canvas != image)
6455 canvas=DestroyImage(canvas);
6497static void XMakeImageMSBFirst(
const XResourceInfo *resource_info,
6498 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
6533 assert(resource_info != (XResourceInfo *) NULL);
6534 assert(window != (XWindowInfo *) NULL);
6535 assert(image != (
Image *) NULL);
6536 if (IsEventLogging() != MagickFalse)
6537 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6539 if ((window->immutable != MagickFalse) &&
6540 (image->storage_class == DirectClass) &&
6541 (image->alpha_trait != UndefinedPixelTrait))
6544 size[MagickPathExtent];
6552 image_info=AcquireImageInfo();
6553 (void) CopyMagickString(image_info->filename,
6554 resource_info->image_info->texture != (
char *) NULL ?
6555 resource_info->image_info->texture :
"pattern:checkerboard",
6557 (void) FormatLocaleString(size,MagickPathExtent,
"%.20gx%.20g",(
double)
6558 image->columns,(double) image->rows);
6559 image_info->size=ConstantString(size);
6560 pattern=ReadImage(image_info,exception);
6561 image_info=DestroyImageInfo(image_info);
6562 if (pattern != (
Image *) NULL)
6564 canvas=CloneImage(image,0,0,MagickTrue,exception);
6565 if (canvas == (
Image *) NULL)
6567 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
6569 pattern=DestroyImage(pattern);
6572 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
6573 ximage->bits_per_pixel) >> 3));
6574 map_info=window->map_info;
6575 pixels=window->pixel_info->pixels;
6576 q=(
unsigned char *) ximage->data;
6578 canvas_view=AcquireVirtualCacheView(canvas,exception);
6579 if (ximage->format == XYBitmap)
6591 background=(
unsigned char)
6592 (XPixelIntensity(&window->pixel_info->foreground_color) <
6593 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6594 foreground=(
unsigned char)
6595 (XPixelIntensity(&window->pixel_info->background_color) <
6596 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6597 polarity=(
unsigned short) ((GetPixelInfoIntensity(image,
6598 &canvas->colormap[0])) < ((
double) QuantumRange/2.0) ? 1 : 0);
6599 if (canvas->colors == 2)
6600 polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
6601 GetPixelInfoIntensity(image,&canvas->colormap[1]);
6602 for (y=0; y < (int) canvas->rows; y++)
6604 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6606 if (p == (
const Quantum *) NULL)
6610 for (x=(
int) canvas->columns-1; x >= 0; x--)
6613 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6624 p+=GetPixelChannels(canvas);
6632 if (window->pixel_info->colors != 0)
6633 switch (ximage->bits_per_pixel)
6643 for (y=0; y < (int) canvas->rows; y++)
6645 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6646 canvas->columns,1,exception);
6647 if (p == (
const Quantum *) NULL)
6650 for (x=0; x < (int) canvas->columns; x++)
6652 pixel=pixels[(ssize_t)
6653 GetPixelIndex(canvas,p)] & 0xf;
6658 *q=(
unsigned char) (pixel << 6);
6664 *q|=(
unsigned char) (pixel << 4);
6670 *q|=(
unsigned char) (pixel << 2);
6676 *q|=(
unsigned char) pixel;
6682 p+=GetPixelChannels(canvas);
6696 for (y=0; y < (int) canvas->rows; y++)
6698 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6699 canvas->columns,1,exception);
6700 if (p == (
const Quantum *) NULL)
6703 for (x=0; x < (int) canvas->columns; x++)
6705 pixel=pixels[(ssize_t)
6706 GetPixelIndex(canvas,p)] & 0xf;
6711 *q=(
unsigned char) (pixel << 4);
6717 *q|=(
unsigned char) pixel;
6723 p+=GetPixelChannels(canvas);
6735 if ((resource_info->color_recovery != MagickFalse) &&
6736 (resource_info->quantize_info->dither_method != NoDitherMethod))
6738 XDitherImage(canvas,ximage,exception);
6741 for (y=0; y < (int) canvas->rows; y++)
6743 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6744 canvas->columns,1,exception);
6745 if (p == (
const Quantum *) NULL)
6747 for (x=0; x < (int) canvas->columns; x++)
6749 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6750 *q++=(
unsigned char) pixel;
6751 p+=GetPixelChannels(canvas);
6766 channel[
sizeof(size_t)];
6771 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6772 for (y=0; y < (int) canvas->rows; y++)
6774 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6775 canvas->columns,1,exception);
6776 if (p == (
const Quantum *) NULL)
6778 for (x=0; x < (int) canvas->columns; x++)
6780 pixel=pixels[(ssize_t)
6781 GetPixelIndex(canvas,p)];
6782 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
6784 channel[k]=(
unsigned char) pixel;
6787 for (k=0; k < (int) bytes_per_pixel; k++)
6789 p+=GetPixelChannels(canvas);
6797 switch (ximage->bits_per_pixel)
6807 for (y=0; y < (int) canvas->rows; y++)
6809 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6810 canvas->columns,1,exception);
6811 if (p == (
const Quantum *) NULL)
6814 for (x=(
int) canvas->columns-1; x >= 0; x--)
6816 pixel=XGammaPixel(canvas,map_info,p);
6822 *q=(
unsigned char) (pixel << 6);
6828 *q|=(
unsigned char) (pixel << 4);
6834 *q|=(
unsigned char) (pixel << 2);
6840 *q|=(
unsigned char) pixel;
6846 p+=GetPixelChannels(canvas);
6860 for (y=0; y < (int) canvas->rows; y++)
6862 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6863 canvas->columns,1,exception);
6864 if (p == (
const Quantum *) NULL)
6867 for (x=(
int) canvas->columns-1; x >= 0; x--)
6869 pixel=XGammaPixel(canvas,map_info,p);
6875 *q=(
unsigned char) (pixel << 4);
6881 *q|=(
unsigned char) pixel;
6887 p+=GetPixelChannels(canvas);
6899 if ((resource_info->color_recovery != MagickFalse) &&
6900 (resource_info->quantize_info->dither_method != NoDitherMethod))
6902 XDitherImage(canvas,ximage,exception);
6905 for (y=0; y < (int) canvas->rows; y++)
6907 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6908 canvas->columns,1,exception);
6909 if (p == (
const Quantum *) NULL)
6911 for (x=(
int) canvas->columns-1; x >= 0; x--)
6913 pixel=XGammaPixel(canvas,map_info,p);
6914 *q++=(
unsigned char) pixel;
6915 p+=GetPixelChannels(canvas);
6923 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6924 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6925 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6926 (map_info->blue_mult == 1))
6931 for (y=0; y < (int) canvas->rows; y++)
6933 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6934 canvas->columns,1,exception);
6935 if (p == (
const Quantum *) NULL)
6937 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6938 (blue_gamma != 1.0))
6943 for (x=(
int) canvas->columns-1; x >= 0; x--)
6946 *q++=ScaleQuantumToChar(XRedGamma(
6947 GetPixelRed(canvas,p)));
6948 *q++=ScaleQuantumToChar(XGreenGamma(
6949 GetPixelGreen(canvas,p)));
6950 *q++=ScaleQuantumToChar(XBlueGamma(
6951 GetPixelBlue(canvas,p)));
6952 p+=GetPixelChannels(canvas);
6956 for (x=(
int) canvas->columns-1; x >= 0; x--)
6959 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6960 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6961 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6962 p+=GetPixelChannels(canvas);
6967 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6968 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6969 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6970 (map_info->blue_mult == 65536L))
6975 for (y=0; y < (int) canvas->rows; y++)
6977 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6978 canvas->columns,1,exception);
6979 if (p == (
const Quantum *) NULL)
6981 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6982 (blue_gamma != 1.0))
6987 for (x=(
int) canvas->columns-1; x >= 0; x--)
6990 *q++=ScaleQuantumToChar(XBlueGamma(
6991 GetPixelBlue(canvas,p)));
6992 *q++=ScaleQuantumToChar(XGreenGamma(
6993 GetPixelGreen(canvas,p)));
6994 *q++=ScaleQuantumToChar(XRedGamma(
6995 GetPixelRed(canvas,p)));
6996 p+=GetPixelChannels(canvas);
7000 for (x=(
int) canvas->columns-1; x >= 0; x--)
7003 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
7004 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
7005 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
7006 p+=GetPixelChannels(canvas);
7019 channel[
sizeof(size_t)];
7024 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
7025 for (y=0; y < (int) canvas->rows; y++)
7027 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7028 canvas->columns,1,exception);
7029 if (p == (
const Quantum *) NULL)
7031 for (x=(
int) canvas->columns-1; x >= 0; x--)
7033 pixel=XGammaPixel(canvas,map_info,p);
7034 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
7036 channel[k]=(
unsigned char) pixel;
7039 for (k=0; k < (int) bytes_per_pixel; k++)
7041 p+=GetPixelChannels(canvas);
7049 if (matte_image != (XImage *) NULL)
7054 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
7055 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7056 q=(
unsigned char *) matte_image->data;
7057 for (y=0; y < (int) canvas->rows; y++)
7059 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7061 if (p == (
const Quantum *) NULL)
7065 for (x=(
int) canvas->columns-1; x >= 0; x--)
7068 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7077 p+=GetPixelChannels(canvas);
7084 canvas_view=DestroyCacheView(canvas_view);
7085 if (canvas != image)
7086 canvas=DestroyImage(canvas);
7117MagickPrivate
void XMakeMagnifyImage(Display *display,XWindows *windows,
7121 tuple[MagickPathExtent];
7143 previous_magnify = 0;
7163 assert(display != (Display *) NULL);
7164 assert(windows != (XWindows *) NULL);
7165 if (IsEventLogging() != MagickFalse)
7166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7168 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7170 while ((magnify*(
unsigned int) windows->image.ximage->width) < windows->magnify.width)
7172 while ((magnify*(
unsigned int) windows->image.ximage->height) < windows->magnify.height)
7174 while (magnify > windows->magnify.width)
7176 while (magnify > windows->magnify.height)
7181 if (previous_magnify != 0)
7182 magnify=previous_magnify;
7184 if (magnify != previous_magnify)
7196 while ((1 << i) <= (int) magnify)
7198 (void) FormatLocaleString(windows->magnify.name,MagickPathExtent,
7199 "Magnify %.20gX",(
double) i);
7200 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7201 if (status != False)
7203 XSetWMName(display,windows->magnify.id,&window_name);
7204 XSetWMIconName(display,windows->magnify.id,&window_name);
7205 (void) XFree((
void *) window_name.value);
7208 previous_magnify=magnify;
7209 ximage=windows->image.ximage;
7210 width=(
unsigned int) windows->magnify.ximage->width;
7211 height=(
unsigned int) windows->magnify.ximage->height;
7212 if ((windows->magnify.x < 0) ||
7213 (windows->magnify.x >= windows->image.ximage->width))
7214 windows->magnify.x=windows->image.ximage->width >> 1;
7215 x=windows->magnify.x-(int) ((width/magnify) >> 1);
7219 if (x > (ximage->width-(
int) (width/magnify)))
7220 x=ximage->width-(
int) (width/magnify);
7221 if ((windows->magnify.y < 0) ||
7222 (windows->magnify.y >= windows->image.ximage->height))
7223 windows->magnify.y=windows->image.ximage->height >> 1;
7224 y=windows->magnify.y-(int) ((height/magnify) >> 1);
7228 if (y > (ximage->height-(
int) (height/magnify)))
7229 y=ximage->height-(
int) (height/magnify);
7230 q=(
unsigned char *) windows->magnify.ximage->data;
7231 scanline_pad=(
unsigned int) (windows->magnify.ximage->bytes_per_line-
7232 (((
int) width*windows->magnify.ximage->bits_per_pixel) >> 3));
7233 if (ximage->bits_per_pixel < 8)
7248 pixel_info=windows->magnify.pixel_info;
7249 switch (ximage->bitmap_bit_order)
7258 if (ximage->format == XYBitmap)
7260 background=(
unsigned char)
7261 (XPixelIntensity(&pixel_info->foreground_color) <
7262 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7263 foreground=(
unsigned char)
7264 (XPixelIntensity(&pixel_info->background_color) <
7265 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7266 if (windows->magnify.depth > 1)
7267 Swap(background,foreground);
7269 for (i=0; i < (ssize_t) height; i+=magnify)
7274 for (j=0; j < magnify; j++)
7276 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7277 ((x*ximage->bits_per_pixel) >> 3);
7278 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7281 for (k=0; k < width; k+=magnify)
7286 for (l=0; l < magnify; l++)
7291 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7294 if (*p & (0x01 << (p_bit+plane)))
7307 p_bit+=ximage->bits_per_pixel;
7314 *q=
byte >> (8-q_bit);
7330 if (ximage->format == XYBitmap)
7332 background=(
unsigned char)
7333 (XPixelIntensity(&pixel_info->foreground_color) <
7334 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7335 foreground=(
unsigned char)
7336 (XPixelIntensity(&pixel_info->background_color) <
7337 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7338 if (windows->magnify.depth > 1)
7339 Swap(background,foreground);
7341 for (i=0; i < (ssize_t) height; i+=magnify)
7346 for (j=0; j < magnify; j++)
7348 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7349 ((x*ximage->bits_per_pixel) >> 3);
7350 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7353 for (k=0; k < width; k+=magnify)
7358 for (l=0; l < magnify; l++)
7363 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7366 if (*p & (0x80 >> (p_bit+plane)))
7379 p_bit+=ximage->bits_per_pixel;
7386 *q=
byte << (8-q_bit);
7397 switch (ximage->bits_per_pixel)
7405 for (i=0; i < (ssize_t) height; i+=magnify)
7410 for (j=0; j < magnify; j++)
7412 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7413 ((x*ximage->bits_per_pixel) >> 3);
7414 for (k=0; k < width; k+=magnify)
7419 for (l=0; l < magnify; l++)
7438 bytes_per_pixel=(
unsigned int) ximage->bits_per_pixel >> 3;
7439 for (i=0; i < (ssize_t) height; i+=magnify)
7444 for (j=0; j < magnify; j++)
7446 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7447 ((x*ximage->bits_per_pixel) >> 3);
7448 for (k=0; k < width; k+=magnify)
7453 for (l=0; l < magnify; l++)
7454 for (m=0; m < bytes_per_pixel; m++)
7468 x=windows->magnify.x-(int) ((width/magnify) >> 1);
7470 x=((int) (width >> 1)-windows->magnify.x*(int) magnify);
7472 if (x > (ximage->width-(
int) (width/magnify)))
7473 x=(
int) ((ximage->width-windows->magnify.x)*(
int) magnify-(int)
7477 y=windows->magnify.y-(int) ((height/magnify) >> 1);
7479 y=((int) (height >> 1)-windows->magnify.y*(int) magnify);
7481 if (y > (ximage->height-(
int) (height/magnify)))
7482 y=(
int) ((ximage->height-windows->magnify.y)*(
int) magnify-(int)
7486 if ((x != 0) || (y != 0))
7487 (void) XFillRectangle(display,windows->magnify.pixmap,
7488 windows->magnify.annotate_context,0,0,width,height);
7489 (void) XPutImage(display,windows->magnify.pixmap,
7490 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,
7491 (
unsigned int) ((int) width-x),(
unsigned int) ((
int) height-y));
7492 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7493 (magnify <= (height >> 1))))
7501 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7502 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7503 highlight_info.width=magnify;
7504 highlight_info.height=magnify;
7505 (void) XDrawRectangle(display,windows->magnify.pixmap,
7506 windows->magnify.highlight_context,(
int) highlight_info.x,
7507 (int) highlight_info.y,(
unsigned int) highlight_info.width-1,
7508 (
unsigned int) highlight_info.height-1);
7510 (void) XDrawRectangle(display,windows->magnify.pixmap,
7511 windows->magnify.annotate_context,(
int) highlight_info.x+1,
7512 (int) highlight_info.y+1,(
unsigned int) highlight_info.width-3,
7513 (
unsigned int) highlight_info.height-3);
7518 (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
7519 (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7520 (void) FormatLocaleString(tuple,MagickPathExtent,
"%d,%d: ",
7521 windows->magnify.x,windows->magnify.y);
7522 (void) ConcatenateMagickString(tuple,
"(",MagickPathExtent);
7523 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7524 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7525 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7526 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7527 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7528 if (pixel.colorspace == CMYKColorspace)
7530 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7531 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7533 if (pixel.alpha_trait != UndefinedPixelTrait)
7535 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7536 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7538 (void) ConcatenateMagickString(tuple,
")",MagickPathExtent);
7539 height=(
unsigned int) (windows->magnify.font_info->ascent+
7540 windows->magnify.font_info->descent);
7541 x=windows->magnify.font_info->max_bounds.width >> 1;
7542 y=windows->magnify.font_info->ascent+(int) (height >> 2);
7543 (void) XDrawImageString(display,windows->magnify.pixmap,
7544 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7545 GetColorTuple(&pixel,MagickTrue,tuple);
7547 (void) XDrawImageString(display,windows->magnify.pixmap,
7548 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7549 (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7552 (void) XDrawImageString(display,windows->magnify.pixmap,
7553 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7557 magnify_window=windows->magnify;
7560 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7592static MagickBooleanType XMakePixmap(Display *display,
7593 const XResourceInfo *resource_info,XWindowInfo *window)
7599 assert(display != (Display *) NULL);
7600 assert(resource_info != (XResourceInfo *) NULL);
7601 assert(window != (XWindowInfo *) NULL);
7602 if (IsEventLogging() != MagickFalse)
7603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7604 if (window->pixmap != (Pixmap) NULL)
7609 (void) XFreePixmap(display,window->pixmap);
7610 window->pixmap=(Pixmap) NULL;
7612 if (window->use_pixmap == MagickFalse)
7613 return(MagickFalse);
7614 if (window->ximage == (XImage *) NULL)
7615 return(MagickFalse);
7619 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7620 (void) XFlush(display);
7624 width=(
unsigned int) window->ximage->width;
7625 height=(
unsigned int) window->ximage->height;
7626 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7627 if (window->pixmap == (Pixmap) NULL)
7632 (void) XCheckDefineCursor(display,window->id,window->cursor);
7633 return(MagickFalse);
7638#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7639 if (window->shared_memory)
7640 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7641 window->ximage,0,0,0,0,width,height,MagickTrue);
7643 if (window->shared_memory == MagickFalse)
7644 (void) XPutImage(display,window->pixmap,window->annotate_context,
7645 window->ximage,0,0,0,0,width,height);
7646 if ((GetLogEventMask() & X11Event) != 0)
7648 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Pixmap:");
7649 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %ux%u",
7655 (void) XCheckDefineCursor(display,window->id,window->cursor);
7699#if defined(__cplusplus) || defined(c_plusplus)
7703static inline double DiversityPixelIntensity(
7704 const DiversityPacket *pixel)
7709 intensity=0.212656*(double) pixel->red+0.715158*(
double) pixel->green+
7710 0.072186*(double) pixel->blue;
7714static int IntensityCompare(
const void *x,
const void *y)
7723 color_1=(DiversityPacket *) x;
7724 color_2=(DiversityPacket *) y;
7725 diversity=(int) (DiversityPixelIntensity(color_2)-
7726 DiversityPixelIntensity(color_1));
7730static int PopularityCompare(
const void *x,
const void *y)
7736 color_1=(DiversityPacket *) x;
7737 color_2=(DiversityPacket *) y;
7738 return((
int) color_2->count-(int) color_1->count);
7741#if defined(__cplusplus) || defined(c_plusplus)
7745static inline Quantum ScaleXToQuantum(
const size_t x,
7748 return((Quantum) (((
double) QuantumRange*x)/scale+0.5));
7751MagickPrivate
void XMakeStandardColormap(Display *display,
7752 XVisualInfo *visual_info,XResourceInfo *resource_info,
Image *image,
7753 XStandardColormap *map_info,XPixelInfo *pixel,
ExceptionInfo *exception)
7776 assert(display != (Display *) NULL);
7777 assert(visual_info != (XVisualInfo *) NULL);
7778 assert(map_info != (XStandardColormap *) NULL);
7779 assert(resource_info != (XResourceInfo *) NULL);
7780 assert(pixel != (XPixelInfo *) NULL);
7781 if (IsEventLogging() != MagickFalse)
7782 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7783 if (resource_info->map_type != (
char *) NULL)
7788 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7790 number_colors=(
unsigned int) (map_info->base_pixel+
7791 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7792 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7793 if (((image->alpha_trait & BlendPixelTrait) == 0) &&
7794 (resource_info->color_recovery == MagickFalse) &&
7795 (resource_info->quantize_info->dither_method != NoDitherMethod) &&
7796 (number_colors < MaxColormapSize))
7807 affinity_image=AcquireImage((
ImageInfo *) NULL,exception);
7808 if (affinity_image == (
Image *) NULL)
7809 ThrowXWindowFatalException(ResourceLimitFatalError,
7810 "UnableToDitherImage",image->filename);
7811 affinity_image->columns=number_colors;
7812 affinity_image->rows=1;
7816 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7818 if (q != (Quantum *) NULL)
7820 for (i=0; i < (ssize_t) number_colors; i++)
7822 SetPixelRed(affinity_image,0,q);
7823 if (map_info->red_max != 0)
7824 SetPixelRed(affinity_image,ScaleXToQuantum((
size_t)
7825 (i/(ssize_t) map_info->red_mult),map_info->red_max),q);
7826 SetPixelGreen(affinity_image,0,q);
7827 if (map_info->green_max != 0)
7828 SetPixelGreen(affinity_image,ScaleXToQuantum((
size_t)
7829 ((i/(ssize_t) map_info->green_mult) % (ssize_t)
7830 (map_info->green_max+1)),map_info->green_max),q);
7831 SetPixelBlue(affinity_image,0,q);
7832 if (map_info->blue_max != 0)
7833 SetPixelBlue(affinity_image,ScaleXToQuantum((
size_t)
7834 (i % (ssize_t) map_info->green_mult),map_info->blue_max),
7836 SetPixelAlpha(affinity_image,TransparentAlpha,q);
7837 q+=GetPixelChannels(affinity_image);
7839 (void) SyncAuthenticPixels(affinity_image,exception);
7840 (void) RemapImage(resource_info->quantize_info,image,
7841 affinity_image,exception);
7843 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7845 (void) SetImageStorageClass(image,DirectClass,exception);
7846 affinity_image=DestroyImage(affinity_image);
7848 if ((GetLogEventMask() & X11Event) != 0)
7850 (void) LogMagickEvent(X11Event,GetMagickModule(),
7851 "Standard Colormap:");
7852 (void) LogMagickEvent(X11Event,GetMagickModule(),
7853 " colormap id: 0x%lx",map_info->colormap);
7854 (void) LogMagickEvent(X11Event,GetMagickModule(),
7855 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7856 map_info->green_max,map_info->blue_max);
7857 (void) LogMagickEvent(X11Event,GetMagickModule(),
7858 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7859 map_info->green_mult,map_info->blue_mult);
7863 if ((visual_info->klass != DirectColor) &&
7864 (visual_info->klass != TrueColor))
7865 if ((image->storage_class == DirectClass) ||
7866 ((int) image->colors > visual_info->colormap_size))
7874 quantize_info=(*resource_info->quantize_info);
7875 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7876 (void) QuantizeImage(&quantize_info,image,exception);
7881 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7882 colormap=XDefaultColormap(display,visual_info->screen);
7883 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7884 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7885 visual_info->visual,visual_info->klass == DirectColor ?
7886 AllocAll : AllocNone);
7887 if (colormap == (Colormap) NULL)
7888 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToCreateColormap",
7893 XGetMapInfo(visual_info,colormap,map_info);
7894 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7898 switch (visual_info->klass)
7906 number_colors=image->colors;
7907 colors=(XColor *) AcquireQuantumMemory((
size_t)
7908 visual_info->colormap_size,
sizeof(*colors));
7909 if (colors == (XColor *) NULL)
7910 ThrowXWindowFatalException(ResourceLimitFatalError,
7911 "UnableToCreateColormap",image->filename);
7913 color.flags=(char) (DoRed | DoGreen | DoBlue);
7914 for (i=0; i < (ssize_t) image->colors; i++)
7916 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7917 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7918 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7919 if (visual_info->klass != StaticColor)
7921 gray_value=(
unsigned short) XPixelIntensity(&color);
7922 color.red=gray_value;
7923 color.green=gray_value;
7924 color.blue=gray_value;
7926 status=XAllocColor(display,colormap,&color);
7927 if (status == False)
7929 colormap=XCopyColormapAndFree(display,colormap);
7930 (void) XAllocColor(display,colormap,&color);
7932 pixel->pixels[i]=color.pixel;
7946 number_colors=image->colors;
7947 colors=(XColor *) AcquireQuantumMemory((
size_t)
7948 visual_info->colormap_size,
sizeof(*colors));
7949 if (colors == (XColor *) NULL)
7950 ThrowXWindowFatalException(ResourceLimitFatalError,
7951 "UnableToCreateColormap",image->filename);
7955 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7956 (void) XAllocColor(display,colormap,&pixel->background_color);
7957 (void) XAllocColor(display,colormap,&pixel->border_color);
7958 (void) XAllocColor(display,colormap,&pixel->matte_color);
7959 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7960 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7961 (void) XAllocColor(display,colormap,&pixel->depth_color);
7962 (void) XAllocColor(display,colormap,&pixel->trough_color);
7963 for (i=0; i < MaxNumberPens; i++)
7964 (
void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7968 colormap_type=resource_info->colormap;
7969 status=XAllocColorCells(display,colormap,MagickFalse,(
unsigned long *)
7970 NULL,0,pixel->pixels,(
unsigned int) image->colors);
7971 if (status != False)
7972 colormap_type=PrivateColormap;
7973 if (colormap_type == SharedColormap)
7996 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7997 sizeof(*diversity));
7998 if (diversity == (DiversityPacket *) NULL)
7999 ThrowXWindowFatalException(ResourceLimitFatalError,
8000 "UnableToCreateColormap",image->filename);
8001 for (i=0; i < (ssize_t) image->colors; i++)
8003 diversity[i].red=ClampToQuantum(image->colormap[i].red);
8004 diversity[i].green=ClampToQuantum(image->colormap[i].green);
8005 diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
8006 diversity[i].index=(
unsigned short) i;
8007 diversity[i].count=0;
8009 image_view=AcquireAuthenticCacheView(image,exception);
8010 for (y=0; y < (int) image->rows; y++)
8018 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
8019 image->columns,1,exception);
8020 if (p == (
const Quantum *) NULL)
8022 for (x=(
int) image->columns-1; x >= 0; x--)
8024 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
8025 p+=GetPixelChannels(image);
8028 image_view=DestroyCacheView(image_view);
8032 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
8034 for (i=0; i < (ssize_t) image->colors; )
8036 diversity[i].count<<=4;
8037 i+=MagickMax((
int) (image->colors >> 4),2);
8039 diversity[image->colors-1].count<<=4;
8040 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
8046 color.flags=(char) (DoRed | DoGreen | DoBlue);
8047 for (i=0; i < (ssize_t) image->colors; i++)
8049 index=diversity[i].index;
8051 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8053 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8055 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8056 if (visual_info->klass != PseudoColor)
8058 gray_value=(
unsigned short) XPixelIntensity(&color);
8059 color.red=gray_value;
8060 color.green=gray_value;
8061 color.blue=gray_value;
8063 status=XAllocColor(display,colormap,&color);
8064 if (status == False)
8066 pixel->pixels[index]=color.pixel;
8072 server_colors=(XColor *) AcquireQuantumMemory((
size_t)
8073 visual_info->colormap_size,
sizeof(*server_colors));
8074 if (server_colors == (XColor *) NULL)
8075 ThrowXWindowFatalException(ResourceLimitFatalError,
8076 "UnableToCreateColormap",image->filename);
8077 for (x=visual_info->colormap_size-1; x >= 0; x--)
8078 server_colors[x].pixel=(
size_t) x;
8079 (void) XQueryColors(display,colormap,server_colors,
8080 (
int) MagickMin((
unsigned int) visual_info->colormap_size,256));
8084 for (; i < (ssize_t) image->colors; i++)
8086 index=diversity[i].index;
8087 color.red=ScaleQuantumToShort(
8088 XRedGamma(image->colormap[index].red));
8089 color.green=ScaleQuantumToShort(
8090 XGreenGamma(image->colormap[index].green));
8091 color.blue=ScaleQuantumToShort(
8092 XBlueGamma(image->colormap[index].blue));
8093 if (visual_info->klass != PseudoColor)
8095 gray_value=(
unsigned short) XPixelIntensity(&color);
8096 color.red=gray_value;
8097 color.green=gray_value;
8098 color.blue=gray_value;
8100 XBestPixel(display,colormap,server_colors,(
unsigned int)
8101 visual_info->colormap_size,&color);
8102 pixel->pixels[index]=color.pixel;
8105 if ((
int) image->colors < visual_info->colormap_size)
8110 retain_colors=MagickMin((
unsigned int)
8111 (visual_info->colormap_size-(
int) image->colors),256);
8112 for (i=0; i < (ssize_t) retain_colors; i++)
8113 *p++=server_colors[i];
8114 number_colors+=retain_colors;
8116 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8117 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8123 if (status == False)
8128 colormap=XCreateColormap(display,
8129 XRootWindow(display,visual_info->screen),visual_info->visual,
8131 if (colormap == (Colormap) NULL)
8132 ThrowXWindowFatalException(ResourceLimitFatalError,
8133 "UnableToCreateColormap",image->filename);
8134 map_info->colormap=colormap;
8135 if ((
int) image->colors < visual_info->colormap_size)
8141 retain_colors=MagickMin((
unsigned int)
8142 (visual_info->colormap_size-(
int) image->colors),256);
8143 p=colors+image->colors;
8144 for (i=0; i < (ssize_t) retain_colors; i++)
8146 p->pixel=(
unsigned long) i;
8149 (void) XQueryColors(display,
8150 XDefaultColormap(display,visual_info->screen),
8151 colors+image->colors,(int) retain_colors);
8155 (void) XAllocColorCells(display,colormap,MagickFalse,
8156 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8158 p=colors+image->colors;
8159 for (i=0; i < (ssize_t) retain_colors; i++)
8161 p->pixel=pixel->pixels[i];
8164 (void) XStoreColors(display,colormap,colors+image->colors,
8165 (
int) retain_colors);
8166 number_colors+=retain_colors;
8168 (void) XAllocColorCells(display,colormap,MagickFalse,
8169 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8176 color.flags=(char) (DoRed | DoGreen | DoBlue);
8177 for (i=0; i < (ssize_t) image->colors; i++)
8179 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8180 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8181 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8182 if (visual_info->klass != PseudoColor)
8184 gray_value=(
unsigned short) XPixelIntensity(&color);
8185 color.red=gray_value;
8186 color.green=gray_value;
8187 color.blue=gray_value;
8189 color.pixel=pixel->pixels[i];
8192 (void) XStoreColors(display,colormap,colors,(
int) image->colors);
8205 number_colors=(
unsigned int) ((map_info->red_max*map_info->red_mult)+
8206 (map_info->green_max*map_info->green_mult)+
8207 (map_info->blue_max*map_info->blue_mult)+1);
8208 linear_colormap=(number_colors > 4096) ||
8209 (((
int) (map_info->red_max+1) == visual_info->colormap_size) &&
8210 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8211 ((
int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8212 MagickTrue : MagickFalse;
8213 if (linear_colormap != MagickFalse)
8214 number_colors=(size_t) visual_info->colormap_size;
8218 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
8219 if (colors == (XColor *) NULL)
8220 ThrowXWindowFatalException(ResourceLimitFatalError,
8221 "UnableToCreateColormap",image->filename);
8226 color.flags=(char) (DoRed | DoGreen | DoBlue);
8227 if (linear_colormap != MagickFalse)
8228 for (i=0; i < (ssize_t) number_colors; i++)
8230 color.blue=(
unsigned short) 0;
8231 if (map_info->blue_max != 0)
8232 color.blue=(
unsigned short) (((65535L*(i % (ssize_t)
8233 map_info->green_mult))/(ssize_t) map_info->blue_max));
8234 color.green=color.blue;
8235 color.red=color.blue;
8236 color.pixel=XStandardPixel(map_info,&color);
8240 for (i=0; i < (ssize_t) number_colors; i++)
8242 color.red=(
unsigned short) 0;
8243 if (map_info->red_max != 0)
8244 color.red=(
unsigned short) ((
size_t) ((65535L*(i/(ssize_t)
8245 map_info->red_mult))/(ssize_t) map_info->red_max));
8246 color.green=(
unsigned int) 0;
8247 if (map_info->green_max != 0)
8248 color.green=(
unsigned short) ((
size_t) ((65535L*((i/(ssize_t)
8249 map_info->green_mult) % (ssize_t) (map_info->green_max+1)))/
8250 (ssize_t) map_info->green_max));
8251 color.blue=(
unsigned short) 0;
8252 if (map_info->blue_max != 0)
8253 color.blue=(
unsigned short) ((
size_t) ((65535L*(i % (ssize_t)
8254 map_info->green_mult))/(ssize_t) map_info->blue_max));
8255 color.pixel=XStandardPixel(map_info,&color);
8258 if ((visual_info->klass == DirectColor) &&
8259 (colormap != XDefaultColormap(display,visual_info->screen)))
8260 (void) XStoreColors(display,colormap,colors,(
int) number_colors);
8262 for (i=0; i < (ssize_t) number_colors; i++)
8263 (
void) XAllocColor(display,colormap,&colors[i]);
8267 if ((visual_info->klass != DirectColor) &&
8268 (visual_info->klass != TrueColor))
8273 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8274 &pixel->foreground_color);
8275 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8276 &pixel->background_color);
8277 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8282 pixel->background_color.red=(~pixel->foreground_color.red);
8283 pixel->background_color.green=
8284 (~pixel->foreground_color.green);
8285 pixel->background_color.blue=
8286 (~pixel->foreground_color.blue);
8287 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8288 &pixel->background_color);
8290 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8291 &pixel->border_color);
8292 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8293 &pixel->matte_color);
8294 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8295 &pixel->highlight_color);
8296 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8297 &pixel->shadow_color);
8298 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8299 &pixel->depth_color);
8300 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8301 &pixel->trough_color);
8302 for (i=0; i < MaxNumberPens; i++)
8304 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8305 &pixel->pen_colors[i]);
8306 pixel->pixels[(ssize_t) image->colors+i]=pixel->pen_colors[i].pixel;
8308 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8310 colors=(XColor *) RelinquishMagickMemory(colors);
8311 if ((GetLogEventMask() & X11Event) != 0)
8313 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Standard Colormap:");
8314 (void) LogMagickEvent(X11Event,GetMagickModule(),
" colormap id: 0x%lx",
8315 map_info->colormap);
8316 (void) LogMagickEvent(X11Event,GetMagickModule(),
8317 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8318 map_info->green_max,map_info->blue_max);
8319 (void) LogMagickEvent(X11Event,GetMagickModule(),
8320 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8321 map_info->green_mult,map_info->blue_mult);
8362MagickPrivate
void XMakeWindow(Display *display,Window parent,
char **argv,
8363 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8364 XWindowInfo *window_info)
8366#define MinWindowSize 64
8374 static XTextProperty
8387 assert(display != (Display *) NULL);
8388 assert(window_info != (XWindowInfo *) NULL);
8389 if (IsEventLogging() != MagickFalse)
8390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8391 size_hints=XAllocSizeHints();
8392 if (size_hints == (XSizeHints *) NULL)
8393 ThrowXWindowFatalException(XServerFatalError,
"UnableToMakeXWindow",argv[0]);
8394 size_hints->flags=(int) window_info->flags;
8395 size_hints->x=window_info->x;
8396 size_hints->y=window_info->y;
8397 size_hints->width=(int) window_info->width;
8398 size_hints->height=(int) window_info->height;
8399 if (window_info->immutable != MagickFalse)
8404 size_hints->min_width=size_hints->width;
8405 size_hints->min_height=size_hints->height;
8406 size_hints->max_width=size_hints->width;
8407 size_hints->max_height=size_hints->height;
8408 size_hints->flags|=PMinSize;
8409 size_hints->flags|=PMaxSize;
8416 size_hints->min_width=(int) window_info->min_width;
8417 size_hints->min_height=(int) window_info->min_height;
8418 size_hints->flags|=PResizeInc;
8419 size_hints->width_inc=(int) window_info->width_inc;
8420 size_hints->height_inc=(int) window_info->height_inc;
8421#if !defined(PRE_R4_ICCCM)
8422 size_hints->flags|=PBaseSize;
8423 size_hints->base_width=size_hints->width_inc;
8424 size_hints->base_height=size_hints->height_inc;
8427 gravity=NorthWestGravity;
8428 if (window_info->geometry != (
char *) NULL)
8431 default_geometry[MagickPathExtent],
8432 geometry[MagickPathExtent];
8443 (void) FormatLocaleString(default_geometry,MagickPathExtent,
"%dx%d",
8444 size_hints->width,size_hints->height);
8445 (void) CopyMagickString(geometry,window_info->geometry,MagickPathExtent);
8447 while (strlen(p) != 0)
8449 if ((isspace((
int) ((
unsigned char) *p)) == 0) && (*p !=
'%'))
8452 (
void) memmove(p,p+1,(
size_t) (MagickPathExtent-(p-geometry)));
8454 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8455 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8456 &size_hints->width,&size_hints->height,&gravity);
8457 if ((flags & WidthValue) && (flags & HeightValue))
8458 size_hints->flags|=USSize;
8459 if ((flags & XValue) && (flags & YValue))
8461 size_hints->flags|=USPosition;
8462 window_info->x=size_hints->x;
8463 window_info->y=size_hints->y;
8466#if !defined(PRE_R4_ICCCM)
8467 size_hints->win_gravity=gravity;
8468 size_hints->flags|=PWinGravity;
8470 if (window_info->id == (Window) NULL)
8471 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8472 (
unsigned int) size_hints->width,(
unsigned int) size_hints->height,
8473 window_info->border_width,(
int) window_info->depth,InputOutput,
8474 window_info->visual,(
unsigned long) window_info->mask,
8475 &window_info->attributes);
8490 (void) XChangeWindowAttributes(display,window_info->id,(
unsigned long)
8491 window_info->mask,&window_info->attributes);
8492 mask=ConfigureNotify;
8493 while (XCheckTypedWindowEvent(display,window_info->id,(
int) mask,&sans_event)) ;
8494 window_changes.x=window_info->x;
8495 window_changes.y=window_info->y;
8496 window_changes.width=(int) window_info->width;
8497 window_changes.height=(int) window_info->height;
8498 mask=(MagickStatusType) (CWWidth | CWHeight);
8499 if (window_info->flags & USPosition)
8501 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8502 mask,&window_changes);
8504 if (window_info->id == (Window) NULL)
8505 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateWindow",
8507 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8508 if (status == False)
8509 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8511 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8512 if (status == False)
8513 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8514 window_info->icon_name);
8515 if (window_info->icon_geometry != (
char *) NULL)
8525 size_hints->flags|=USPosition;
8526 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8527 (
char *) NULL,0,size_hints,&manager_hints->icon_x,
8528 &manager_hints->icon_y,&width,&height,&gravity);
8529 if ((flags & XValue) && (flags & YValue))
8530 manager_hints->flags|=IconPositionHint;
8532 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8533 size_hints,manager_hints,class_hint);
8534 if (window_name.value != (
void *) NULL)
8536 (void) XFree((
void *) window_name.value);
8537 window_name.value=(
unsigned char *) NULL;
8538 window_name.nitems=0;
8540 if (icon_name.value != (
void *) NULL)
8542 (void) XFree((
void *) icon_name.value);
8543 icon_name.value=(
unsigned char *) NULL;
8546 atom_list[0]=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
8547 atom_list[1]=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
8548 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8549 (void) XFree((
void *) size_hints);
8550 if (window_info->shape != MagickFalse)
8552#if defined(MAGICKCORE_HAVE_SHAPE)
8562 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8563 window_info->shape=MagickFalse;
8565 window_info->shape=MagickFalse;
8568 window_info->shape=MagickFalse;
8569 if (window_info->shared_memory != MagickFalse)
8571#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8575 if (XShmQueryExtension(display) == 0)
8576 window_info->shared_memory=MagickFalse;
8578 window_info->shared_memory=MagickFalse;
8581 window_info->image=NewImageList();
8582 window_info->destroy=MagickFalse;
8618static const char *GetLocaleMonitorMessage(
const char *text)
8621 message[MagickPathExtent],
8622 tag[MagickPathExtent];
8630 (void) CopyMagickString(tag,text,MagickPathExtent);
8632 if (p != (
char *) NULL)
8634 (void) FormatLocaleString(message,MagickPathExtent,
"Monitor/%s",tag);
8635 locale_message=GetLocaleMessage(message);
8636 if (locale_message == message)
8638 return(locale_message);
8641MagickPrivate MagickBooleanType XMagickProgressMonitor(
const char *tag,
8642 const MagickOffsetType quantum,
const MagickSizeType span,
8643 void *magick_unused(client_data))
8648 windows=XSetWindows((XWindows *) ~0);
8649 if (windows == (XWindows *) NULL)
8651 if (windows->info.mapped != MagickFalse)
8652 XProgressMonitorWidget(windows->display,windows,
8653 GetLocaleMonitorMessage(tag),quantum,span);
8683MagickPrivate MagickBooleanType XQueryColorCompliance(
const char *target,
8690 *display = (Display *) NULL;
8701 assert(color != (XColor *) NULL);
8705 color->flags=(char) (DoRed | DoGreen | DoBlue);
8706 if ((target == (
char *) NULL) || (*target ==
'\0'))
8707 target=
"#ffffffffffff";
8711 if (display == (Display *) NULL)
8712 display=XOpenDisplay((
char *) NULL);
8713 if (display == (Display *) NULL)
8715 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",target);
8716 return(MagickFalse);
8718 colormap=XDefaultColormap(display,XDefaultScreen(display));
8719 status=XParseColor(display,colormap,(
char *) target,&xcolor);
8720 if (status == False)
8721 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",target)
8724 color->red=xcolor.red;
8725 color->green=xcolor.green;
8726 color->blue=xcolor.blue;
8727 color->flags=xcolor.flags;
8729 return(status != False ? MagickTrue : MagickFalse);
8763MagickPrivate
void XQueryPosition(Display *display,
const Window window,
int *x,
8776 assert(display != (Display *) NULL);
8777 assert(window != (Window) NULL);
8778 assert(x != (
int *) NULL);
8779 assert(y != (
int *) NULL);
8780 if (IsEventLogging() != MagickFalse)
8781 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8782 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8815MagickPrivate
void XRefreshWindow(Display *display,
const XWindowInfo *window,
8816 const XEvent *event)
8826 assert(display != (Display *) NULL);
8827 assert(window != (XWindowInfo *) NULL);
8828 if (IsEventLogging() != MagickFalse)
8829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8830 if (window->ximage == (XImage *) NULL)
8832 if (event != (XEvent *) NULL)
8839 width=(
unsigned int) event->xexpose.width;
8840 height=(
unsigned int) event->xexpose.height;
8852 width=window->width;
8853 height=window->height;
8854 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8855 if (window->matte_pixmap != (Pixmap) NULL)
8857#if defined(MAGICKCORE_HAVE_SHAPE)
8858 if (window->shape != MagickFalse)
8859 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8860 window->matte_pixmap,ShapeSet);
8867 if ((window->ximage->width-(x+window->x)) < (
int) width)
8868 width=(
unsigned int) (window->ximage->width-(x+window->x));
8869 if ((window->ximage->height-(y+window->y)) < (int) height)
8870 height=(
unsigned int) (window->ximage->height-(y+window->y));
8874 if (window->matte_pixmap != (Pixmap) NULL)
8875 (
void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8876 if (window->pixmap != (Pixmap) NULL)
8878 if (window->depth > 1)
8879 (void) XCopyArea(display,window->pixmap,window->id,
8880 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8882 (
void) XCopyPlane(display,window->pixmap,window->id,
8883 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8888#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8889 if (window->shared_memory)
8890 (void) XShmPutImage(display,window->id,window->annotate_context,
8891 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8893 if (window->shared_memory == MagickFalse)
8894 (void) XPutImage(display,window->id,window->annotate_context,
8895 window->ximage,x+window->x,y+window->y,x,y,width,height);
8897 if (window->matte_pixmap != (Pixmap) NULL)
8898 (
void) XSetClipMask(display,window->annotate_context,None);
8899 (void) XFlush(display);
8931MagickExport MagickBooleanType XRemoteCommand(Display *display,
8932 const char *window,
const char *filename)
8941 assert(filename != (
char *) NULL);
8942 if (IsEventLogging() != MagickFalse)
8943 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
8944 if (display == (Display *) NULL)
8945 display=XOpenDisplay((
char *) NULL);
8946 if (display == (Display *) NULL)
8948 ThrowXWindowException(XServerError,
"UnableToOpenXServer",filename);
8949 return(MagickFalse);
8951 remote_atom=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
8952 remote_window=(Window) NULL;
8953 root_window=XRootWindow(display,XDefaultScreen(display));
8954 if (window != (
char *) NULL)
8959 if (isdigit((
int) ((
unsigned char) *window)) != 0)
8960 remote_window=XWindowByID(display,root_window,(Window)
8961 strtol((
char *) window,(
char **) NULL,0));
8962 if (remote_window == (Window) NULL)
8963 remote_window=XWindowByName(display,root_window,window);
8965 if (remote_window == (Window) NULL)
8966 remote_window=XWindowByProperty(display,root_window,remote_atom);
8967 if (remote_window == (Window) NULL)
8969 ThrowXWindowException(XServerError,
"UnableToConnectToRemoteDisplay",
8971 return(MagickFalse);
8976 remote_atom=XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
8977 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8978 PropModeReplace,(
unsigned char *) filename,(int) strlen(filename));
8979 (void) XSync(display,MagickFalse);
9015MagickPrivate MagickBooleanType XRenderImage(
Image *image,
9027 *display = (Display *) NULL;
9032 static XAnnotateInfo
9041 static XResourceInfo
9047 static XStandardColormap
9053 if (display == (Display *) NULL)
9064 display=XOpenDisplay(draw_info->server_name);
9065 if (display == (Display *) NULL)
9067 ThrowXWindowException(XServerError,
"UnableToOpenXServer",
9068 draw_info->server_name);
9069 return(MagickFalse);
9074 (void) XSetErrorHandler(XError);
9075 image_info=AcquireImageInfo();
9076 client_name=GetClientName();
9077 resource_database=XGetResourceDatabase(display,client_name);
9078 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
9079 resource_info.close_server=MagickFalse;
9080 resource_info.colormap=PrivateColormap;
9081 resource_info.font=AcquireString(draw_info->font);
9082 resource_info.background_color=AcquireString(
"#ffffffffffff");
9083 resource_info.foreground_color=AcquireString(
"#000000000000");
9084 map_info=XAllocStandardColormap();
9085 visual_info=(XVisualInfo *) NULL;
9086 font_info=(XFontStruct *) NULL;
9087 pixel.pixels=(
unsigned long *) NULL;
9088 if (map_info == (XStandardColormap *) NULL)
9090 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
9092 return(MagickFalse);
9097 visual_info=XBestVisualInfo(display,map_info,&resource_info);
9098 if (visual_info == (XVisualInfo *) NULL)
9100 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9101 &resource_info,(XWindowInfo *) NULL);
9102 ThrowXWindowException(XServerError,
"UnableToGetVisual",
9104 return(MagickFalse);
9106 map_info->colormap=(Colormap) NULL;
9110 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9112 XGetPixelInfo(display,visual_info,map_info,&resource_info,(
Image *) NULL,
9114 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9118 font_info=XBestFont(display,&resource_info,MagickFalse);
9119 if (font_info == (XFontStruct *) NULL)
9121 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9122 &resource_info,(XWindowInfo *) NULL);
9123 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9125 return(MagickFalse);
9127 cache_info=(*draw_info);
9132 XGetAnnotateInfo(&annotate_info);
9133 annotate_info.stencil=ForegroundStencil;
9134 if (cache_info.font != draw_info->font)
9139 (void) XFreeFont(display,font_info);
9140 (void) CloneString(&resource_info.font,draw_info->font);
9141 font_info=XBestFont(display,&resource_info,MagickFalse);
9142 if (font_info == (XFontStruct *) NULL)
9144 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9146 return(MagickFalse);
9149 if (draw_info->debug != MagickFalse)
9150 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9151 "Font %s; pointsize %g",draw_info->font != (
char *) NULL ?
9152 draw_info->font :
"none",draw_info->pointsize);
9153 cache_info=(*draw_info);
9154 annotate_info.font_info=font_info;
9155 annotate_info.text=(
char *) draw_info->text;
9156 annotate_info.width=(
unsigned int) XTextWidth(font_info,draw_info->text,(
int)
9157 strlen(draw_info->text));
9158 annotate_info.height=(
unsigned int) (font_info->ascent+font_info->descent);
9159 metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
9160 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9161 metrics->ascent=(double) font_info->ascent+4;
9162 metrics->descent=(double) (-font_info->descent);
9163 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9164 metrics->height=(double) font_info->ascent+font_info->descent;
9165 metrics->max_advance=(double) font_info->max_bounds.width;
9166 metrics->bounds.x1=0.0;
9167 metrics->bounds.y1=metrics->descent;
9168 metrics->bounds.x2=metrics->ascent+metrics->descent;
9169 metrics->bounds.y2=metrics->ascent+metrics->descent;
9170 metrics->underline_position=(-2.0);
9171 metrics->underline_thickness=1.0;
9172 if (draw_info->render == MagickFalse)
9174 if (draw_info->fill.alpha == (
double) TransparentAlpha)
9179 width=annotate_info.width;
9180 height=annotate_info.height;
9181 if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
9182 (fabs(draw_info->affine.ry) >= MagickEpsilon))
9184 if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
9185 (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
9186 annotate_info.degrees=(double) (180.0/MagickPI)*
9187 atan2(draw_info->affine.rx,draw_info->affine.sx);
9189 (void) FormatLocaleString(annotate_info.geometry,MagickPathExtent,
9190 "%.20gx%.20g%+.20g%+.20g",(
double) width,(double) height,
9191 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9192 draw_info->interline_spacing-0.5));
9193 pixel.pen_color.red=ScaleQuantumToShort(
9194 ClampToQuantum(draw_info->fill.red));
9195 pixel.pen_color.green=ScaleQuantumToShort(
9196 ClampToQuantum(draw_info->fill.green));
9197 pixel.pen_color.blue=ScaleQuantumToShort(
9198 ClampToQuantum(draw_info->fill.blue));
9199 status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
9202 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
9204 return(MagickFalse);
9235MagickExport
void XRetainWindowColors(Display *display,
const Window window)
9246 assert(display != (Display *) NULL);
9247 assert(window != (Window) NULL);
9248 if (IsEventLogging() != MagickFalse)
9249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9250 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
9251 if (property == (Atom) NULL)
9253 ThrowXWindowException(XServerError,
"UnableToCreateProperty",
9257 pixmap=XCreatePixmap(display,window,1,1,1);
9258 if (pixmap == (Pixmap) NULL)
9260 ThrowXWindowException(XServerError,
"UnableToCreateBitmap",
"");
9263 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9264 (
unsigned char *) &pixmap,1);
9265 (void) XSetCloseDownMode(display,RetainPermanent);
9298static Window XSelectWindow(Display *display,
RectangleInfo *crop_info)
9300#define MinimumCropArea (unsigned int) 9
9329 assert(display != (Display *) NULL);
9331 if (IsEventLogging() != MagickFalse)
9332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9333 root_window=XRootWindow(display,XDefaultScreen(display));
9334 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9335 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9336 context_values.function=GXinvert;
9337 context_values.plane_mask=
9338 context_values.background ^ context_values.foreground;
9339 context_values.subwindow_mode=IncludeInferiors;
9340 annotate_context=XCreateGC(display,root_window,(
size_t) (GCBackground |
9341 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9342 if (annotate_context == (GC) NULL)
9343 return(MagickFalse);
9347 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9348 XDefaultScreen(display)),(
char * )
"white",(
char * )
"black");
9349 status=XGrabPointer(display,root_window,MagickFalse,(
unsigned int)
9350 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9351 GrabModeAsync,root_window,target_cursor,CurrentTime);
9352 if (status != GrabSuccess)
9354 ThrowXWindowException(XServerError,
"UnableToGrabMouse",
"");
9355 return((Window) NULL);
9361 crop_info->height=0;
9363 target_window=(Window) NULL;
9366 (void) XGrabServer(display);
9369 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9370 (
void) XDrawRectangle(display,root_window,annotate_context,
9371 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9372 (
unsigned int) crop_info->height-1);
9376 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9377 (void) XWindowEvent(display,root_window,ButtonPressMask |
9378 ButtonReleaseMask | ButtonMotionMask,&event);
9379 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9380 (
void) XDrawRectangle(display,root_window,annotate_context,
9381 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9382 (
unsigned int) crop_info->height-1);
9387 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9388 event.xbutton.x,event.xbutton.y);
9389 if (target_window == (Window) NULL)
9390 target_window=root_window;
9391 x_offset=
event.xbutton.x_root;
9392 y_offset=
event.xbutton.y_root;
9393 crop_info->x=(ssize_t) x_offset;
9394 crop_info->y=(ssize_t) y_offset;
9396 crop_info->height=0;
9410 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9411 crop_info->x=(ssize_t) event.xmotion.x;
9412 crop_info->y=(ssize_t) event.xmotion.y;
9416 if ((
int) crop_info->x < x_offset)
9417 crop_info->width=(size_t) (x_offset-crop_info->x);
9420 crop_info->width=(size_t) (crop_info->x-x_offset);
9421 crop_info->x=(ssize_t) x_offset;
9423 if ((
int) crop_info->y < y_offset)
9424 crop_info->height=(
size_t) (y_offset-crop_info->y);
9427 crop_info->height=(size_t) (crop_info->y-y_offset);
9428 crop_info->y=(ssize_t) y_offset;
9434 }
while ((target_window == (Window) NULL) || (presses > 0));
9435 (void) XUngrabServer(display);
9436 (void) XUngrabPointer(display,CurrentTime);
9437 (void) XFreeCursor(display,target_cursor);
9438 (void) XFreeGC(display,annotate_context);
9439 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9442 crop_info->height=0;
9444 if ((crop_info->width != 0) && (crop_info->height != 0))
9445 target_window=root_window;
9446 return(target_window);
9478MagickPrivate
void XSetCursorState(Display *display,XWindows *windows,
9479 const MagickStatusType state)
9481 assert(display != (Display *) NULL);
9482 assert(windows != (XWindows *) NULL);
9483 if (IsEventLogging() != MagickFalse)
9484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9487 (void) XCheckDefineCursor(display,windows->image.id,
9488 windows->image.busy_cursor);
9489 (void) XCheckDefineCursor(display,windows->pan.id,
9490 windows->pan.busy_cursor);
9491 (void) XCheckDefineCursor(display,windows->magnify.id,
9492 windows->magnify.busy_cursor);
9493 (void) XCheckDefineCursor(display,windows->command.id,
9494 windows->command.busy_cursor);
9498 (void) XCheckDefineCursor(display,windows->image.id,
9499 windows->image.cursor);
9500 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9501 (void) XCheckDefineCursor(display,windows->magnify.id,
9502 windows->magnify.cursor);
9503 (void) XCheckDefineCursor(display,windows->command.id,
9504 windows->command.cursor);
9505 (void) XCheckDefineCursor(display,windows->command.id,
9506 windows->widget.cursor);
9507 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9509 windows->info.mapped=MagickFalse;
9535MagickPrivate XWindows *XSetWindows(XWindows *windows_info)
9538 *windows = (XWindows *) NULL;
9540 if (windows_info != (XWindows *) ~0)
9542 windows=(XWindows *) RelinquishMagickMemory(windows);
9543 windows=windows_info;
9570MagickPrivate
void XUserPreferences(XResourceInfo *resource_info)
9572#if defined(X11_PREFERENCES_PATH)
9574 cache[MagickPathExtent],
9575 filename[MagickPathExtent],
9576 specifier[MagickPathExtent];
9583 preferences_database;
9588 assert(resource_info != (XResourceInfo *) NULL);
9589 client_name=GetClientName();
9590 preferences_database=XrmGetStringDatabase(
"");
9591 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.backdrop",client_name);
9592 value=resource_info->backdrop ?
"True" :
"False";
9593 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9594 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.colormap",client_name);
9595 value=resource_info->colormap == SharedColormap ?
"Shared" :
"Private";
9596 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9597 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.confirmExit",
9599 value=resource_info->confirm_exit ?
"True" :
"False";
9600 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9601 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.confirmEdit",
9603 value=resource_info->confirm_edit ?
"True" :
"False";
9604 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9605 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.displayWarnings",
9607 value=resource_info->display_warnings ?
"True" :
"False";
9608 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9609 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.dither",client_name);
9610 value=resource_info->quantize_info->dither_method != NoDitherMethod ?
9612 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9613 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.gammaCorrect",
9615 value=resource_info->gamma_correct ?
"True" :
"False";
9616 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9617 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.undoCache",client_name);
9618 (void) FormatLocaleString(cache,MagickPathExtent,
"%.20g",(
double)
9619 resource_info->undo_cache);
9620 XrmPutStringResource(&preferences_database,specifier,cache);
9621 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.usePixmap",client_name);
9622 value=resource_info->use_pixmap ?
"True" :
"False";
9623 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9624 (void) FormatLocaleString(filename,MagickPathExtent,
"%s%src",
9625 X11_PREFERENCES_PATH,client_name);
9626 ExpandFilename(filename);
9627 XrmPutFileDatabase(preferences_database,filename);
9656static const char *XVisualClassName(
const int visual_class)
9658 switch (visual_class)
9660 case StaticGray:
return(
"StaticGray");
9661 case GrayScale:
return(
"GrayScale");
9662 case StaticColor:
return(
"StaticColor");
9663 case PseudoColor:
return(
"PseudoColor");
9664 case TrueColor:
return(
"TrueColor");
9665 case DirectColor:
return(
"DirectColor");
9667 return(
"unknown visual class");
9698MagickPrivate
void XWarning(
const ExceptionType magick_unused(warning),
9699 const char *reason,
const char *description)
9702 text[MagickPathExtent];
9707 if (reason == (
char *) NULL)
9709 (void) CopyMagickString(text,reason,MagickPathExtent);
9710 (void) ConcatenateMagickString(text,
":",MagickPathExtent);
9711 windows=XSetWindows((XWindows *) ~0);
9712 XNoticeWidget(windows->display,windows,text,(
char *) description);
9745MagickPrivate Window XWindowByID(Display *display,
const Window root_window,
9765 assert(display != (Display *) NULL);
9766 assert(root_window != (Window) NULL);
9767 if (IsEventLogging() != MagickFalse)
9768 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9770 return(XSelectWindow(display,&rectangle_info));
9771 if (root_window ==
id)
9772 return(root_window);
9773 status=XQueryTree(display,root_window,&child,&child,&children,
9775 if (status == False)
9776 return((Window) NULL);
9777 window=(Window) NULL;
9778 for (i=0; i < (int) number_children; i++)
9783 window=XWindowByID(display,children[i],
id);
9784 if (window != (Window) NULL)
9787 if (children != (Window *) NULL)
9788 (void) XFree((
void *) children);
9824MagickPrivate Window XWindowByName(Display *display,
const Window root_window,
9844 assert(display != (Display *) NULL);
9845 assert(root_window != (Window) NULL);
9846 assert(name != (
char *) NULL);
9847 if (IsEventLogging() != MagickFalse)
9848 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
9849 if (XGetWMName(display,root_window,&window_name) != 0)
9850 if (LocaleCompare((
char *) window_name.value,name) == 0)
9851 return(root_window);
9852 status=XQueryTree(display,root_window,&child,&child,&children,
9854 if (status == False)
9855 return((Window) NULL);
9856 window=(Window) NULL;
9857 for (i=0; i < (int) number_children; i++)
9862 window=XWindowByName(display,children[i],name);
9863 if (window != (Window) NULL)
9866 if (children != (Window *) NULL)
9867 (void) XFree((
void *) children);
9902MagickPrivate Window XWindowByProperty(Display *display,
const Window window,
9903 const Atom property)
9931 assert(display != (Display *) NULL);
9932 assert(window != (Window) NULL);
9933 assert(property != (Atom) NULL);
9934 if (IsEventLogging() != MagickFalse)
9935 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9936 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9937 if (status == False)
9938 return((Window) NULL);
9940 child=(Window) NULL;
9941 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9943 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9944 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9946 (void) XFree((
void *) data);
9947 if ((status == Success) && (type != (Atom) NULL))
9950 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9951 child=XWindowByProperty(display,children[i],property);
9952 if (children != (Window *) NULL)
9953 (
void) XFree((
void *) children);
9988 assert(image_info != (
const ImageInfo *) NULL);
9989 assert(image_info->signature == MagickCoreSignature);
9992 assert(exception->signature == MagickCoreSignature);
9993 if (IsEventLogging() != MagickFalse)
9994 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
9995 image_info->filename);
9998 return((
Image *) NULL);
10033MagickPrivate MagickBooleanType XRenderImage(
Image *image,
10040 (void) ThrowMagickException(exception,GetMagickModule(),
10041 MissingDelegateError,
"DelegateLibrarySupportNotBuiltIn",
"'%s' (X11)",
10043 return(MagickFalse);
10065MagickPrivate MagickBooleanType XComponentGenesis(
void)
10067 return(MagickTrue);
10092MagickExport
void XGetImportInfo(
XImportInfo *ximage_info)
10095 ximage_info->frame=MagickFalse;
10096 ximage_info->borders=MagickFalse;
10097 ximage_info->screen=MagickFalse;
10098 ximage_info->descend=MagickTrue;
10099 ximage_info->silent=MagickFalse;