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)
5069 (void) CopyMagickString(image->filename,image_info->filename,
5071 if ((crop_info.width != 0) && (crop_info.height != 0))
5079 crop_image=CropImage(image,&crop_info,exception);
5080 if (crop_image != (
Image *) NULL)
5082 image=DestroyImage(image);
5086 status=XGetWMName(display,target,&window_name);
5089 if (*image_info->filename ==
'\0')
5090 (void) CopyMagickString(image->filename,(
char *) window_name.value,
5091 (
size_t) window_name.nitems+1);
5092 (void) XFree((
void *) window_name.value);
5095 if (ximage_info->silent == MagickFalse)
5100 (void) XBell(display,0);
5101 (void) XBell(display,0);
5103 (void) XCloseDisplay(display);
5135MagickPrivate XWindows *XInitializeWindows(Display *display,
5136 XResourceInfo *resource_info)
5147 windows=(XWindows *) AcquireMagickMemory(
sizeof(*windows));
5148 if (windows == (XWindows *) NULL)
5150 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5152 return((XWindows *) NULL);
5154 (void) memset(windows,0,
sizeof(*windows));
5155 windows->pixel_info=(XPixelInfo *) AcquireQuantumMemory(1,
5156 sizeof(*windows->pixel_info));
5157 windows->icon_pixel=(XPixelInfo *) AcquireQuantumMemory(1,
5158 sizeof(*windows->icon_pixel));
5159 windows->icon_resources=(XResourceInfo *) AcquireQuantumMemory(1,
5160 sizeof(*windows->icon_resources));
5161 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5162 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5163 (windows->icon_resources == (XResourceInfo *) NULL))
5165 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5167 return((XWindows *) NULL);
5169 (void) memset((
void *) windows->pixel_info,0,
sizeof(XPixelInfo));
5170 (void) memset((
void *) windows->icon_pixel,0,
sizeof(XPixelInfo));
5174 windows->display=display;
5175 windows->wm_protocols=XInternAtom(display,
"WM_PROTOCOLS",MagickFalse);
5176 windows->wm_delete_window=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
5177 windows->wm_take_focus=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
5178 windows->im_protocols=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
5179 windows->im_remote_command=
5180 XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
5181 windows->im_update_widget=XInternAtom(display,
"IM_UPDATE_WIDGET",MagickFalse);
5182 windows->im_update_colormap=
5183 XInternAtom(display,
"IM_UPDATE_COLORMAP",MagickFalse);
5184 windows->im_former_image=XInternAtom(display,
"IM_FORMER_IMAGE",MagickFalse);
5185 windows->im_next_image=XInternAtom(display,
"IM_NEXT_IMAGE",MagickFalse);
5186 windows->im_retain_colors=XInternAtom(display,
"IM_RETAIN_COLORS",MagickFalse);
5187 windows->im_exit=XInternAtom(display,
"IM_EXIT",MagickFalse);
5188 windows->dnd_protocols=XInternAtom(display,
"DndProtocol",MagickFalse);
5189#if defined(MAGICKCORE_WINDOWS_SUPPORT)
5190 (void) XSynchronize(display,MagickFalse);
5192 if ((GetLogEventMask() & X11Event) != 0)
5194 (void) XSynchronize(display,MagickTrue);
5195 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Version: %s",
5196 GetMagickVersion((
size_t *) NULL));
5197 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Protocols:");
5198 (void) LogMagickEvent(X11Event,GetMagickModule(),
5199 " Window Manager: 0x%lx",windows->wm_protocols);
5200 (void) LogMagickEvent(X11Event,GetMagickModule(),
5201 " delete window: 0x%lx",windows->wm_delete_window);
5202 (void) LogMagickEvent(X11Event,GetMagickModule(),
" take focus: 0x%lx",
5203 windows->wm_take_focus);
5204 (void) LogMagickEvent(X11Event,GetMagickModule(),
" ImageMagick: 0x%lx",
5205 windows->im_protocols);
5206 (void) LogMagickEvent(X11Event,GetMagickModule(),
5207 " remote command: 0x%lx",windows->im_remote_command);
5208 (void) LogMagickEvent(X11Event,GetMagickModule(),
5209 " update widget: 0x%lx",windows->im_update_widget);
5210 (void) LogMagickEvent(X11Event,GetMagickModule(),
5211 " update colormap: 0x%lx",windows->im_update_colormap);
5212 (void) LogMagickEvent(X11Event,GetMagickModule(),
5213 " former image: 0x%lx",windows->im_former_image);
5214 (void) LogMagickEvent(X11Event,GetMagickModule(),
" next image: 0x%lx",
5215 windows->im_next_image);
5216 (void) LogMagickEvent(X11Event,GetMagickModule(),
5217 " retain colors: 0x%lx",windows->im_retain_colors);
5218 (void) LogMagickEvent(X11Event,GetMagickModule(),
" exit: 0x%lx",
5220 (void) LogMagickEvent(X11Event,GetMagickModule(),
" Drag and Drop: 0x%lx",
5221 windows->dnd_protocols);
5226 windows->map_info=XAllocStandardColormap();
5227 windows->icon_map=XAllocStandardColormap();
5228 if ((windows->map_info == (XStandardColormap *) NULL) ||
5229 (windows->icon_map == (XStandardColormap *) NULL))
5230 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5232 windows->map_info->colormap=(Colormap) NULL;
5233 windows->icon_map->colormap=(Colormap) NULL;
5234 windows->pixel_info->pixels=(
unsigned long *) NULL;
5235 windows->pixel_info->annotate_context=(GC) NULL;
5236 windows->pixel_info->highlight_context=(GC) NULL;
5237 windows->pixel_info->widget_context=(GC) NULL;
5238 windows->font_info=(XFontStruct *) NULL;
5239 windows->icon_pixel->annotate_context=(GC) NULL;
5240 windows->icon_pixel->pixels=(
unsigned long *) NULL;
5244 *windows->icon_resources=(*resource_info);
5245 windows->icon_resources->visual_type=(
char *)
"default";
5246 windows->icon_resources->colormap=SharedColormap;
5247 windows->visual_info=
5248 XBestVisualInfo(display,windows->map_info,resource_info);
5249 windows->icon_visual=
5250 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5251 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5252 (windows->icon_visual == (XVisualInfo *) NULL))
5253 ThrowXWindowFatalException(XServerFatalError,
"UnableToGetVisual",
5254 resource_info->visual_type);
5255 if ((GetLogEventMask() & X11Event) != 0)
5257 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Visual:");
5258 (void) LogMagickEvent(X11Event,GetMagickModule(),
" visual id: 0x%lx",
5259 windows->visual_info->visualid);
5260 (void) LogMagickEvent(X11Event,GetMagickModule(),
" class: %s",
5261 XVisualClassName(windows->visual_info->klass));
5262 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d planes",
5263 windows->visual_info->depth);
5264 (void) LogMagickEvent(X11Event,GetMagickModule(),
5265 " size of colormap: %d entries",windows->visual_info->colormap_size);
5266 (void) LogMagickEvent(X11Event,GetMagickModule(),
5267 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5268 windows->visual_info->red_mask,windows->visual_info->green_mask,
5269 windows->visual_info->blue_mask);
5270 (void) LogMagickEvent(X11Event,GetMagickModule(),
5271 " significant bits in color: %d bits",
5272 windows->visual_info->bits_per_rgb);
5277 windows->class_hints=XAllocClassHint();
5278 windows->manager_hints=XAllocWMHints();
5279 if ((windows->class_hints == (XClassHint *) NULL) ||
5280 (windows->manager_hints == (XWMHints *) NULL))
5281 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5286 root_window=XRootWindow(display,windows->visual_info->screen);
5287 windows->group_leader.id=(Window) NULL;
5288 if (resource_info->window_group != (
char *) NULL)
5290 if (isdigit((
int) ((
unsigned char) *resource_info->window_group)) != 0)
5291 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5292 strtol((
char *) resource_info->window_group,(
char **) NULL,0));
5293 if (windows->group_leader.id == (Window) NULL)
5294 windows->group_leader.id=
5295 XWindowByName(display,root_window,resource_info->window_group);
5334MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5335 Colormap colormap,
char *background_color,
char *foreground_color)
5337#define scope_height 17
5338#define scope_x_hot 8
5339#define scope_y_hot 8
5340#define scope_width 17
5342 static const unsigned char
5345 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5346 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5347 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5348 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5349 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5353 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5354 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5355 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5356 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5357 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5371 assert(display != (Display *) NULL);
5372 assert(window != (Window) NULL);
5373 assert(colormap != (Colormap) NULL);
5374 assert(background_color != (
char *) NULL);
5375 assert(foreground_color != (
char *) NULL);
5376 if (IsEventLogging() != MagickFalse)
5377 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",background_color);
5378 source=XCreateBitmapFromData(display,window,(
char *) scope_bits,scope_width,
5380 mask=XCreateBitmapFromData(display,window,(
char *) scope_mask_bits,
5381 scope_width,scope_height);
5382 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5384 ThrowXWindowException(XServerError,
"UnableToCreatePixmap",
"...");
5385 return((Cursor) NULL);
5387 (void) XParseColor(display,colormap,background_color,&background);
5388 (void) XParseColor(display,colormap,foreground_color,&foreground);
5389 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5390 scope_x_hot,scope_y_hot);
5391 (void) XFreePixmap(display,source);
5392 (void) XFreePixmap(display,mask);
5436MagickPrivate MagickBooleanType XMakeImage(Display *display,
5437 const XResourceInfo *resource_info,XWindowInfo *window,
Image *image,
5438 unsigned int width,
unsigned int height,
ExceptionInfo *exception)
5440#define CheckOverflowException(length,width,height) \
5441 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5451 assert(display != (Display *) NULL);
5452 assert(resource_info != (XResourceInfo *) NULL);
5453 assert(window != (XWindowInfo *) NULL);
5455 assert(height != 0);
5456 if (IsEventLogging() != MagickFalse)
5457 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
5458 if ((window->width == 0) || (window->height == 0))
5459 return(MagickFalse);
5463 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5464 (void) XFlush(display);
5465 depth=(int) window->depth;
5466 if (window->destroy)
5467 window->image=DestroyImage(window->image);
5468 window->image=image;
5469 window->destroy=MagickFalse;
5470 if (window->image != (
Image *) NULL)
5472 if (window->crop_geometry != (
char *) NULL)
5483 window->image->page.x=0;
5484 window->image->page.y=0;
5485 (void) ParsePageGeometry(window->image,window->crop_geometry,
5486 &crop_info,exception);
5487 crop_image=CropImage(window->image,&crop_info,exception);
5488 if (crop_image != (
Image *) NULL)
5490 if (window->image != image)
5491 window->image=DestroyImage(window->image);
5492 window->image=crop_image;
5493 window->destroy=MagickTrue;
5496 if ((width != (
unsigned int) window->image->columns) ||
5497 (height != (
unsigned int) window->image->rows))
5505 resize_image=NewImageList();
5506 if ((window->pixel_info->colors == 0) &&
5507 (window->image->rows > (
unsigned long) XDisplayHeight(display,window->screen)) &&
5508 (window->image->columns > (
unsigned long) XDisplayWidth(display,window->screen)))
5509 resize_image=ResizeImage(window->image,width,height,
5510 image->filter,exception);
5513 if (window->image->storage_class == PseudoClass)
5514 resize_image=SampleImage(window->image,width,height,
5517 resize_image=ThumbnailImage(window->image,width,height,
5520 if (resize_image != (
Image *) NULL)
5522 if (window->image != image)
5523 window->image=DestroyImage(window->image);
5524 window->image=resize_image;
5525 window->destroy=MagickTrue;
5528 width=(
unsigned int) window->image->columns;
5529 assert((
size_t) width == window->image->columns);
5530 height=(
unsigned int) window->image->rows;
5531 assert((
size_t) height == window->image->rows);
5536 ximage=(XImage *) NULL;
5537 format=(depth == 1) ? XYBitmap : ZPixmap;
5538#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5539 if (window->shared_memory != MagickFalse)
5547 segment_info=(XShmSegmentInfo *) window->segment_info;
5548 segment_info[1].shmid=(-1);
5549 segment_info[1].shmaddr=(
char *) NULL;
5550 ximage=XShmCreateImage(display,window->visual,(
unsigned int) depth,format,
5551 (
char *) NULL,&segment_info[1],width,height);
5553 if (ximage == (XImage *) NULL)
5554 window->shared_memory=MagickFalse;
5557 length=(size_t) (ximage->bytes_per_line*ximage->height);
5558 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5559 window->shared_memory=MagickFalse;
5561 if (window->shared_memory != MagickFalse)
5562 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5563 if (window->shared_memory != MagickFalse)
5564 segment_info[1].shmaddr=(
char *) shmat(segment_info[1].shmid,0,0);
5565 if (segment_info[1].shmid < 0)
5566 window->shared_memory=MagickFalse;
5567 if (window->shared_memory != MagickFalse)
5568 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5571 if (ximage != (XImage *) NULL)
5572 XDestroyImage(ximage);
5573 ximage=(XImage *) NULL;
5574 if (segment_info[1].shmaddr)
5576 (void) shmdt(segment_info[1].shmaddr);
5577 segment_info[1].shmaddr=(
char *) NULL;
5579 if (segment_info[1].shmid >= 0)
5581 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5582 segment_info[1].shmid=(-1);
5590#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5591 if (window->shared_memory)
5599 (void) XSync(display,MagickFalse);
5600 xerror_alert=MagickFalse;
5601 segment_info=(XShmSegmentInfo *) window->segment_info;
5602 ximage->data=segment_info[1].shmaddr;
5603 segment_info[1].readOnly=MagickFalse;
5604 status=XShmAttach(display,&segment_info[1]);
5605 if (status != False)
5606 (void) XSync(display,MagickFalse);
5607 if ((status == False) || (xerror_alert != MagickFalse))
5609 window->shared_memory=MagickFalse;
5610 if (status != False)
5611 XShmDetach(display,&segment_info[1]);
5613 XDestroyImage(ximage);
5614 ximage=(XImage *) NULL;
5615 if (segment_info[1].shmid >= 0)
5617 if (segment_info[1].shmaddr != NULL)
5618 (void) shmdt(segment_info[1].shmaddr);
5619 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5620 segment_info[1].shmid=(-1);
5621 segment_info[1].shmaddr=(
char *) NULL;
5626 if (window->shared_memory == MagickFalse)
5627 ximage=XCreateImage(display,window->visual,(
unsigned int) depth,format,0,
5628 (
char *) NULL,width,height,XBitmapPad(display),0);
5629 if (ximage == (XImage *) NULL)
5634 (void) XCheckDefineCursor(display,window->id,window->cursor);
5635 return(MagickFalse);
5637 if ((GetLogEventMask() & X11Event) != 0)
5639 (void) LogMagickEvent(X11Event,GetMagickModule(),
"XImage:");
5640 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %dx%d",
5641 ximage->width,ximage->height);
5642 (void) LogMagickEvent(X11Event,GetMagickModule(),
" format: %d",
5644 (void) LogMagickEvent(X11Event,GetMagickModule(),
" byte order: %d",
5645 ximage->byte_order);
5646 (void) LogMagickEvent(X11Event,GetMagickModule(),
5647 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5648 ximage->bitmap_bit_order,ximage->bitmap_pad);
5649 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d",
5651 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bytes per line: %d",
5652 ximage->bytes_per_line);
5653 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bits per pixel: %d",
5654 ximage->bits_per_pixel);
5655 (void) LogMagickEvent(X11Event,GetMagickModule(),
5656 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5657 ximage->green_mask,ximage->blue_mask);
5659 if (window->shared_memory == MagickFalse)
5661 if (ximage->format == XYBitmap)
5663 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5664 ximage->bytes_per_line,(
size_t) (ximage->depth*ximage->height));
5665 if (ximage->data != (
char *) NULL)
5666 (void) memset(ximage->data,0,(
size_t)
5667 (ximage->bytes_per_line*ximage->depth*ximage->height));
5671 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5672 ximage->bytes_per_line,(
size_t) ximage->height);
5673 if (ximage->data != (
char *) NULL)
5674 (void) memset(ximage->data,0,(
size_t)
5675 (ximage->bytes_per_line*ximage->height));
5678 if (ximage->data == (
char *) NULL)
5683 XDestroyImage(ximage);
5684 ximage=(XImage *) NULL;
5685 (void) XCheckDefineCursor(display,window->id,window->cursor);
5686 return(MagickFalse);
5688 if (window->ximage != (XImage *) NULL)
5693#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5694 if (window->segment_info != (XShmSegmentInfo *) NULL)
5699 segment_info=(XShmSegmentInfo *) window->segment_info;
5700 if (segment_info[0].shmid >= 0)
5702 (void) XSync(display,MagickFalse);
5703 (void) XShmDetach(display,&segment_info[0]);
5704 (void) XSync(display,MagickFalse);
5705 if (segment_info[0].shmaddr != (
char *) NULL)
5706 (void) shmdt(segment_info[0].shmaddr);
5707 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5708 segment_info[0].shmid=(-1);
5709 segment_info[0].shmaddr=(
char *) NULL;
5710 window->ximage->data=(
char *) NULL;
5714 if (window->ximage->data != (
char *) NULL)
5715 free(window->ximage->data);
5716 window->ximage->data=(
char *) NULL;
5717 XDestroyImage(window->ximage);
5718 window->ximage=(XImage *) NULL;
5720#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5721 if (window->segment_info != (XShmSegmentInfo *) NULL)
5726 segment_info=(XShmSegmentInfo *) window->segment_info;
5727 segment_info[0]=segment_info[1];
5730 window->ximage=ximage;
5731 matte_image=(XImage *) NULL;
5732 if ((window->shape != MagickFalse) && (window->image != (
Image *) NULL))
5733 if ((window->image->alpha_trait != UndefinedPixelTrait) &&
5734 ((
int) width <= XDisplayWidth(display,window->screen)) &&
5735 ((
int) height <= XDisplayHeight(display,window->screen)))
5740 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5741 (
char *) NULL,width,height,XBitmapPad(display),0);
5742 if ((GetLogEventMask() & X11Event) != 0)
5744 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Matte Image:");
5745 (void) LogMagickEvent(X11Event,GetMagickModule(),
5746 " width, height: %dx%d",matte_image->width,matte_image->height);
5748 if (matte_image != (XImage *) NULL)
5753 matte_image->data=(
char *) malloc((
size_t)
5754 (matte_image->bytes_per_line*matte_image->depth*
5755 matte_image->height));
5756 if (matte_image->data == (
char *) NULL)
5758 XDestroyImage(matte_image);
5759 matte_image=(XImage *) NULL;
5763 if (window->matte_image != (XImage *) NULL)
5768 if (window->matte_image->data != (
char *) NULL)
5769 free(window->matte_image->data);
5770 window->matte_image->data=(
char *) NULL;
5771 XDestroyImage(window->matte_image);
5772 window->matte_image=(XImage *) NULL;
5774 window->matte_image=matte_image;
5775 if (window->matte_pixmap != (Pixmap) NULL)
5777 (void) XFreePixmap(display,window->matte_pixmap);
5778 window->matte_pixmap=(Pixmap) NULL;
5779#if defined(MAGICKCORE_HAVE_SHAPE)
5780 if (window->shape != MagickFalse)
5781 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5784 window->stasis=MagickFalse;
5788 if (window->image != (
Image *) NULL)
5790 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5791 (ximage->bitmap_bit_order == LSBFirst)))
5792 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5793 matte_image,exception);
5795 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5796 matte_image,exception);
5798 if (window->matte_image != (XImage *) NULL)
5803 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5804 if (window->matte_pixmap != (Pixmap) NULL)
5815 context_values.background=0;
5816 context_values.foreground=1;
5817 graphics_context=XCreateGC(display,window->matte_pixmap,
5818 (
size_t) (GCBackground | GCForeground),&context_values);
5819 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5820 window->matte_image,0,0,0,0,width,height);
5821 (void) XFreeGC(display,graphics_context);
5822#if defined(MAGICKCORE_HAVE_SHAPE)
5823 if (window->shape != MagickFalse)
5824 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5825 window->matte_pixmap,ShapeSet);
5829 (void) XMakePixmap(display,resource_info,window);
5833 (void) XCheckDefineCursor(display,window->id,window->cursor);
5876static void XMakeImageLSBFirst(
const XResourceInfo *resource_info,
5877 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
5912 assert(resource_info != (XResourceInfo *) NULL);
5913 assert(window != (XWindowInfo *) NULL);
5914 assert(image != (
Image *) NULL);
5915 if (IsEventLogging() != MagickFalse)
5916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5918 if ((window->immutable == MagickFalse) &&
5919 (image->storage_class == DirectClass) &&
5920 (image->alpha_trait != UndefinedPixelTrait))
5923 size[MagickPathExtent];
5931 image_info=AcquireImageInfo();
5932 (void) CopyMagickString(image_info->filename,
5933 resource_info->image_info->texture != (
char *) NULL ?
5934 resource_info->image_info->texture :
"pattern:checkerboard",
5936 (void) FormatLocaleString(size,MagickPathExtent,
"%.20gx%.20g",(
double)
5937 image->columns,(
double) image->rows);
5938 image_info->size=ConstantString(size);
5939 pattern=ReadImage(image_info,exception);
5940 image_info=DestroyImageInfo(image_info);
5941 if (pattern != (
Image *) NULL)
5943 canvas=CloneImage(image,0,0,MagickTrue,exception);
5944 if (canvas == (
Image *) NULL)
5946 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
5948 pattern=DestroyImage(pattern);
5951 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
5952 ximage->bits_per_pixel) >> 3));
5953 map_info=window->map_info;
5954 pixels=window->pixel_info->pixels;
5955 q=(
unsigned char *) ximage->data;
5957 canvas_view=AcquireVirtualCacheView(canvas,exception);
5958 if (ximage->format == XYBitmap)
5970 background=(
unsigned char)
5971 (XPixelIntensity(&window->pixel_info->foreground_color) <
5972 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5973 foreground=(
unsigned char)
5974 (XPixelIntensity(&window->pixel_info->background_color) <
5975 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5976 polarity=(
unsigned short) ((GetPixelInfoIntensity(image,
5977 &canvas->colormap[0])) < ((
double) QuantumRange/2.0) ? 1 : 0);
5978 if (canvas->colors == 2)
5979 polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
5980 GetPixelInfoIntensity(image,&canvas->colormap[1]);
5981 for (y=0; y < (int) canvas->rows; y++)
5983 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5985 if (p == (
const Quantum *) NULL)
5989 for (x=0; x < (int) canvas->columns; x++)
5992 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6003 p+=GetPixelChannels(canvas);
6011 if (window->pixel_info->colors != 0)
6012 switch (ximage->bits_per_pixel)
6022 for (y=0; y < (int) canvas->rows; y++)
6024 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6025 canvas->columns,1,exception);
6026 if (p == (
const Quantum *) NULL)
6029 for (x=0; x < (int) canvas->columns; x++)
6031 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
6036 *q=(
unsigned char) pixel;
6042 *q|=(
unsigned char) (pixel << 2);
6048 *q|=(
unsigned char) (pixel << 4);
6054 *q|=(
unsigned char) (pixel << 6);
6060 p+=GetPixelChannels(canvas);
6074 for (y=0; y < (int) canvas->rows; y++)
6076 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6077 canvas->columns,1,exception);
6078 if (p == (
const Quantum *) NULL)
6081 for (x=0; x < (int) canvas->columns; x++)
6083 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6088 *q=(
unsigned char) pixel;
6094 *q|=(
unsigned char) (pixel << 4);
6100 p+=GetPixelChannels(canvas);
6112 if (resource_info->color_recovery &&
6113 resource_info->quantize_info->dither_method != NoDitherMethod)
6115 XDitherImage(canvas,ximage,exception);
6118 for (y=0; y < (int) canvas->rows; y++)
6120 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6121 canvas->columns,1,exception);
6122 if (p == (
const Quantum *) NULL)
6124 for (x=0; x < (int) canvas->columns; x++)
6126 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6127 *q++=(
unsigned char) pixel;
6128 p+=GetPixelChannels(canvas);
6145 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6146 for (y=0; y < (int) canvas->rows; y++)
6148 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6149 canvas->columns,1,exception);
6150 if (p == (
const Quantum *) NULL)
6152 for (x=0; x < (int) canvas->columns; x++)
6154 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6155 for (k=0; k < (int) bytes_per_pixel; k++)
6157 *q++=(
unsigned char) (pixel & 0xff);
6160 p+=GetPixelChannels(canvas);
6168 switch (ximage->bits_per_pixel)
6178 for (y=0; y < (int) canvas->rows; y++)
6181 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6182 canvas->columns,1,exception);
6183 if (p == (
const Quantum *) NULL)
6185 for (x=0; x < (int) canvas->columns; x++)
6187 pixel=XGammaPixel(canvas,map_info,p);
6193 *q=(
unsigned char) pixel;
6199 *q|=(
unsigned char) (pixel << 2);
6205 *q|=(
unsigned char) (pixel << 4);
6211 *q|=(
unsigned char) (pixel << 6);
6217 p+=GetPixelChannels(canvas);
6231 for (y=0; y < (int) canvas->rows; y++)
6233 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6234 canvas->columns,1,exception);
6235 if (p == (
const Quantum *) NULL)
6238 for (x=0; x < (int) canvas->columns; x++)
6240 pixel=XGammaPixel(canvas,map_info,p);
6246 *q=(
unsigned char) pixel;
6252 *q|=(
unsigned char) (pixel << 4);
6258 p+=GetPixelChannels(canvas);
6270 if (resource_info->color_recovery &&
6271 resource_info->quantize_info->dither_method != NoDitherMethod)
6273 XDitherImage(canvas,ximage,exception);
6276 for (y=0; y < (int) canvas->rows; y++)
6278 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6279 canvas->columns,1,exception);
6280 if (p == (
const Quantum *) NULL)
6282 for (x=0; x < (int) canvas->columns; x++)
6284 pixel=XGammaPixel(canvas,map_info,p);
6285 *q++=(
unsigned char) pixel;
6286 p+=GetPixelChannels(canvas);
6294 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6295 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6296 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6297 (map_info->blue_mult == 1))
6302 for (y=0; y < (int) canvas->rows; y++)
6304 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6305 canvas->columns,1,exception);
6306 if (p == (
const Quantum *) NULL)
6308 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6309 (blue_gamma != 1.0))
6314 for (x=(
int) canvas->columns-1; x >= 0; x--)
6316 *q++=ScaleQuantumToChar(XBlueGamma(
6317 GetPixelBlue(canvas,p)));
6318 *q++=ScaleQuantumToChar(XGreenGamma(
6319 GetPixelGreen(canvas,p)));
6320 *q++=ScaleQuantumToChar(XRedGamma(
6321 GetPixelRed(canvas,p)));
6323 p+=GetPixelChannels(canvas);
6327 for (x=(
int) canvas->columns-1; x >= 0; x--)
6329 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6330 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6331 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6333 p+=GetPixelChannels(canvas);
6338 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6339 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6340 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6341 (map_info->blue_mult == 65536L))
6346 for (y=0; y < (int) canvas->rows; y++)
6348 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6349 canvas->columns,1,exception);
6350 if (p == (
const Quantum *) NULL)
6352 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6353 (blue_gamma != 1.0))
6358 for (x=(
int) canvas->columns-1; x >= 0; x--)
6360 *q++=ScaleQuantumToChar(XRedGamma(
6361 GetPixelRed(canvas,p)));
6362 *q++=ScaleQuantumToChar(XGreenGamma(
6363 GetPixelGreen(canvas,p)));
6364 *q++=ScaleQuantumToChar(XBlueGamma(
6365 GetPixelBlue(canvas,p)));
6367 p+=GetPixelChannels(canvas);
6371 for (x=(
int) canvas->columns-1; x >= 0; x--)
6373 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6374 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6375 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6377 p+=GetPixelChannels(canvas);
6392 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6393 for (y=0; y < (int) canvas->rows; y++)
6395 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6396 canvas->columns,1,exception);
6397 if (p == (
const Quantum *) NULL)
6399 for (x=0; x < (int) canvas->columns; x++)
6401 pixel=XGammaPixel(canvas,map_info,p);
6402 for (k=0; k < (int) bytes_per_pixel; k++)
6404 *q++=(
unsigned char) (pixel & 0xff);
6407 p+=GetPixelChannels(canvas);
6415 if (matte_image != (XImage *) NULL)
6420 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6421 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6422 q=(
unsigned char *) matte_image->data;
6423 for (y=0; y < (int) canvas->rows; y++)
6425 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6427 if (p == (
const Quantum *) NULL)
6431 for (x=(
int) canvas->columns-1; x >= 0; x--)
6434 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6443 p+=GetPixelChannels(canvas);
6450 canvas_view=DestroyCacheView(canvas_view);
6451 if (canvas != image)
6452 canvas=DestroyImage(canvas);
6494static void XMakeImageMSBFirst(
const XResourceInfo *resource_info,
6495 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
6530 assert(resource_info != (XResourceInfo *) NULL);
6531 assert(window != (XWindowInfo *) NULL);
6532 assert(image != (
Image *) NULL);
6533 if (IsEventLogging() != MagickFalse)
6534 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6536 if ((window->immutable != MagickFalse) &&
6537 (image->storage_class == DirectClass) &&
6538 (image->alpha_trait != UndefinedPixelTrait))
6541 size[MagickPathExtent];
6549 image_info=AcquireImageInfo();
6550 (void) CopyMagickString(image_info->filename,
6551 resource_info->image_info->texture != (
char *) NULL ?
6552 resource_info->image_info->texture :
"pattern:checkerboard",
6554 (void) FormatLocaleString(size,MagickPathExtent,
"%.20gx%.20g",(
double)
6555 image->columns,(
double) image->rows);
6556 image_info->size=ConstantString(size);
6557 pattern=ReadImage(image_info,exception);
6558 image_info=DestroyImageInfo(image_info);
6559 if (pattern != (
Image *) NULL)
6561 canvas=CloneImage(image,0,0,MagickTrue,exception);
6562 if (canvas == (
Image *) NULL)
6564 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
6566 pattern=DestroyImage(pattern);
6569 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
6570 ximage->bits_per_pixel) >> 3));
6571 map_info=window->map_info;
6572 pixels=window->pixel_info->pixels;
6573 q=(
unsigned char *) ximage->data;
6575 canvas_view=AcquireVirtualCacheView(canvas,exception);
6576 if (ximage->format == XYBitmap)
6588 background=(
unsigned char)
6589 (XPixelIntensity(&window->pixel_info->foreground_color) <
6590 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6591 foreground=(
unsigned char)
6592 (XPixelIntensity(&window->pixel_info->background_color) <
6593 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6594 polarity=(
unsigned short) ((GetPixelInfoIntensity(image,
6595 &canvas->colormap[0])) < ((
double) QuantumRange/2.0) ? 1 : 0);
6596 if (canvas->colors == 2)
6597 polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
6598 GetPixelInfoIntensity(image,&canvas->colormap[1]);
6599 for (y=0; y < (int) canvas->rows; y++)
6601 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6603 if (p == (
const Quantum *) NULL)
6607 for (x=(
int) canvas->columns-1; x >= 0; x--)
6610 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6621 p+=GetPixelChannels(canvas);
6629 if (window->pixel_info->colors != 0)
6630 switch (ximage->bits_per_pixel)
6640 for (y=0; y < (int) canvas->rows; y++)
6642 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6643 canvas->columns,1,exception);
6644 if (p == (
const Quantum *) NULL)
6647 for (x=0; x < (int) canvas->columns; x++)
6649 pixel=pixels[(ssize_t)
6650 GetPixelIndex(canvas,p)] & 0xf;
6655 *q=(
unsigned char) (pixel << 6);
6661 *q|=(
unsigned char) (pixel << 4);
6667 *q|=(
unsigned char) (pixel << 2);
6673 *q|=(
unsigned char) pixel;
6679 p+=GetPixelChannels(canvas);
6693 for (y=0; y < (int) canvas->rows; y++)
6695 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6696 canvas->columns,1,exception);
6697 if (p == (
const Quantum *) NULL)
6700 for (x=0; x < (int) canvas->columns; x++)
6702 pixel=pixels[(ssize_t)
6703 GetPixelIndex(canvas,p)] & 0xf;
6708 *q=(
unsigned char) (pixel << 4);
6714 *q|=(
unsigned char) pixel;
6720 p+=GetPixelChannels(canvas);
6732 if ((resource_info->color_recovery != MagickFalse) &&
6733 (resource_info->quantize_info->dither_method != NoDitherMethod))
6735 XDitherImage(canvas,ximage,exception);
6738 for (y=0; y < (int) canvas->rows; y++)
6740 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6741 canvas->columns,1,exception);
6742 if (p == (
const Quantum *) NULL)
6744 for (x=0; x < (int) canvas->columns; x++)
6746 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6747 *q++=(
unsigned char) pixel;
6748 p+=GetPixelChannels(canvas);
6763 channel[
sizeof(size_t)];
6768 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6769 for (y=0; y < (int) canvas->rows; y++)
6771 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6772 canvas->columns,1,exception);
6773 if (p == (
const Quantum *) NULL)
6775 for (x=0; x < (int) canvas->columns; x++)
6777 pixel=pixels[(ssize_t)
6778 GetPixelIndex(canvas,p)];
6779 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
6781 channel[k]=(
unsigned char) pixel;
6784 for (k=0; k < (int) bytes_per_pixel; k++)
6786 p+=GetPixelChannels(canvas);
6794 switch (ximage->bits_per_pixel)
6804 for (y=0; y < (int) canvas->rows; y++)
6806 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6807 canvas->columns,1,exception);
6808 if (p == (
const Quantum *) NULL)
6811 for (x=(
int) canvas->columns-1; x >= 0; x--)
6813 pixel=XGammaPixel(canvas,map_info,p);
6819 *q=(
unsigned char) (pixel << 6);
6825 *q|=(
unsigned char) (pixel << 4);
6831 *q|=(
unsigned char) (pixel << 2);
6837 *q|=(
unsigned char) pixel;
6843 p+=GetPixelChannels(canvas);
6857 for (y=0; y < (int) canvas->rows; y++)
6859 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6860 canvas->columns,1,exception);
6861 if (p == (
const Quantum *) NULL)
6864 for (x=(
int) canvas->columns-1; x >= 0; x--)
6866 pixel=XGammaPixel(canvas,map_info,p);
6872 *q=(
unsigned char) (pixel << 4);
6878 *q|=(
unsigned char) pixel;
6884 p+=GetPixelChannels(canvas);
6896 if ((resource_info->color_recovery != MagickFalse) &&
6897 (resource_info->quantize_info->dither_method != NoDitherMethod))
6899 XDitherImage(canvas,ximage,exception);
6902 for (y=0; y < (int) canvas->rows; y++)
6904 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6905 canvas->columns,1,exception);
6906 if (p == (
const Quantum *) NULL)
6908 for (x=(
int) canvas->columns-1; x >= 0; x--)
6910 pixel=XGammaPixel(canvas,map_info,p);
6911 *q++=(
unsigned char) pixel;
6912 p+=GetPixelChannels(canvas);
6920 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6921 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6922 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6923 (map_info->blue_mult == 1))
6928 for (y=0; y < (int) canvas->rows; y++)
6930 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6931 canvas->columns,1,exception);
6932 if (p == (
const Quantum *) NULL)
6934 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6935 (blue_gamma != 1.0))
6940 for (x=(
int) canvas->columns-1; x >= 0; x--)
6943 *q++=ScaleQuantumToChar(XRedGamma(
6944 GetPixelRed(canvas,p)));
6945 *q++=ScaleQuantumToChar(XGreenGamma(
6946 GetPixelGreen(canvas,p)));
6947 *q++=ScaleQuantumToChar(XBlueGamma(
6948 GetPixelBlue(canvas,p)));
6949 p+=GetPixelChannels(canvas);
6953 for (x=(
int) canvas->columns-1; x >= 0; x--)
6956 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6957 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6958 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6959 p+=GetPixelChannels(canvas);
6964 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6965 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6966 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6967 (map_info->blue_mult == 65536L))
6972 for (y=0; y < (int) canvas->rows; y++)
6974 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6975 canvas->columns,1,exception);
6976 if (p == (
const Quantum *) NULL)
6978 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6979 (blue_gamma != 1.0))
6984 for (x=(
int) canvas->columns-1; x >= 0; x--)
6987 *q++=ScaleQuantumToChar(XBlueGamma(
6988 GetPixelBlue(canvas,p)));
6989 *q++=ScaleQuantumToChar(XGreenGamma(
6990 GetPixelGreen(canvas,p)));
6991 *q++=ScaleQuantumToChar(XRedGamma(
6992 GetPixelRed(canvas,p)));
6993 p+=GetPixelChannels(canvas);
6997 for (x=(
int) canvas->columns-1; x >= 0; x--)
7000 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
7001 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
7002 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
7003 p+=GetPixelChannels(canvas);
7016 channel[
sizeof(size_t)];
7021 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
7022 for (y=0; y < (int) canvas->rows; y++)
7024 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7025 canvas->columns,1,exception);
7026 if (p == (
const Quantum *) NULL)
7028 for (x=(
int) canvas->columns-1; x >= 0; x--)
7030 pixel=XGammaPixel(canvas,map_info,p);
7031 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
7033 channel[k]=(
unsigned char) pixel;
7036 for (k=0; k < (int) bytes_per_pixel; k++)
7038 p+=GetPixelChannels(canvas);
7046 if (matte_image != (XImage *) NULL)
7051 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
7052 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7053 q=(
unsigned char *) matte_image->data;
7054 for (y=0; y < (int) canvas->rows; y++)
7056 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7058 if (p == (
const Quantum *) NULL)
7062 for (x=(
int) canvas->columns-1; x >= 0; x--)
7065 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7074 p+=GetPixelChannels(canvas);
7081 canvas_view=DestroyCacheView(canvas_view);
7082 if (canvas != image)
7083 canvas=DestroyImage(canvas);
7114MagickPrivate
void XMakeMagnifyImage(Display *display,XWindows *windows,
7118 tuple[MagickPathExtent];
7140 previous_magnify = 0;
7160 assert(display != (Display *) NULL);
7161 assert(windows != (XWindows *) NULL);
7162 if (IsEventLogging() != MagickFalse)
7163 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7165 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7167 while ((magnify*(
unsigned int) windows->image.ximage->width) < windows->magnify.width)
7169 while ((magnify*(
unsigned int) windows->image.ximage->height) < windows->magnify.height)
7171 while (magnify > windows->magnify.width)
7173 while (magnify > windows->magnify.height)
7178 if (previous_magnify != 0)
7179 magnify=previous_magnify;
7181 if (magnify != previous_magnify)
7193 while ((1 << i) <= (
int) magnify)
7195 (void) FormatLocaleString(windows->magnify.name,MagickPathExtent,
7196 "Magnify %.20gX",(
double) i);
7197 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7198 if (status != False)
7200 XSetWMName(display,windows->magnify.id,&window_name);
7201 XSetWMIconName(display,windows->magnify.id,&window_name);
7202 (void) XFree((
void *) window_name.value);
7205 previous_magnify=magnify;
7206 ximage=windows->image.ximage;
7207 width=(
unsigned int) windows->magnify.ximage->width;
7208 height=(
unsigned int) windows->magnify.ximage->height;
7209 if ((windows->magnify.x < 0) ||
7210 (windows->magnify.x >= windows->image.ximage->width))
7211 windows->magnify.x=windows->image.ximage->width >> 1;
7212 x=windows->magnify.x-(int) ((width/magnify) >> 1);
7216 if (x > (ximage->width-(
int) (width/magnify)))
7217 x=ximage->width-(int) (width/magnify);
7218 if ((windows->magnify.y < 0) ||
7219 (windows->magnify.y >= windows->image.ximage->height))
7220 windows->magnify.y=windows->image.ximage->height >> 1;
7221 y=windows->magnify.y-(int) ((height/magnify) >> 1);
7225 if (y > (ximage->height-(
int) (height/magnify)))
7226 y=ximage->height-(int) (height/magnify);
7227 q=(
unsigned char *) windows->magnify.ximage->data;
7228 scanline_pad=(
unsigned int) (windows->magnify.ximage->bytes_per_line-
7229 (((
int) width*windows->magnify.ximage->bits_per_pixel) >> 3));
7230 if (ximage->bits_per_pixel < 8)
7245 pixel_info=windows->magnify.pixel_info;
7246 switch (ximage->bitmap_bit_order)
7255 if (ximage->format == XYBitmap)
7257 background=(
unsigned char)
7258 (XPixelIntensity(&pixel_info->foreground_color) <
7259 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7260 foreground=(
unsigned char)
7261 (XPixelIntensity(&pixel_info->background_color) <
7262 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7263 if (windows->magnify.depth > 1)
7264 Swap(background,foreground);
7266 for (i=0; i < (ssize_t) height; i+=magnify)
7271 for (j=0; j < magnify; j++)
7273 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7274 ((x*ximage->bits_per_pixel) >> 3);
7275 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7278 for (k=0; k < width; k+=magnify)
7283 for (l=0; l < magnify; l++)
7288 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7291 if (*p & (0x01 << (p_bit+plane)))
7304 p_bit+=ximage->bits_per_pixel;
7311 *q=
byte >> (8-q_bit);
7327 if (ximage->format == XYBitmap)
7329 background=(
unsigned char)
7330 (XPixelIntensity(&pixel_info->foreground_color) <
7331 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7332 foreground=(
unsigned char)
7333 (XPixelIntensity(&pixel_info->background_color) <
7334 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7335 if (windows->magnify.depth > 1)
7336 Swap(background,foreground);
7338 for (i=0; i < (ssize_t) height; i+=magnify)
7343 for (j=0; j < magnify; j++)
7345 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7346 ((x*ximage->bits_per_pixel) >> 3);
7347 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7350 for (k=0; k < width; k+=magnify)
7355 for (l=0; l < magnify; l++)
7360 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7363 if (*p & (0x80 >> (p_bit+plane)))
7376 p_bit+=ximage->bits_per_pixel;
7383 *q=
byte << (8-q_bit);
7394 switch (ximage->bits_per_pixel)
7402 for (i=0; i < (ssize_t) height; i+=magnify)
7407 for (j=0; j < magnify; j++)
7409 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7410 ((x*ximage->bits_per_pixel) >> 3);
7411 for (k=0; k < width; k+=magnify)
7416 for (l=0; l < magnify; l++)
7435 bytes_per_pixel=(
unsigned int) ximage->bits_per_pixel >> 3;
7436 for (i=0; i < (ssize_t) height; i+=magnify)
7441 for (j=0; j < magnify; j++)
7443 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7444 ((x*ximage->bits_per_pixel) >> 3);
7445 for (k=0; k < width; k+=magnify)
7450 for (l=0; l < magnify; l++)
7451 for (m=0; m < bytes_per_pixel; m++)
7465 x=windows->magnify.x-(int) ((width/magnify) >> 1);
7467 x=((int) (width >> 1)-windows->magnify.x*(int) magnify);
7469 if (x > (ximage->width-(
int) (width/magnify)))
7470 x=(int) ((ximage->width-windows->magnify.x)*(
int) magnify-(
int)
7474 y=windows->magnify.y-(int) ((height/magnify) >> 1);
7476 y=((int) (height >> 1)-windows->magnify.y*(int) magnify);
7478 if (y > (ximage->height-(
int) (height/magnify)))
7479 y=(int) ((ximage->height-windows->magnify.y)*(
int) magnify-(
int)
7483 if ((x != 0) || (y != 0))
7484 (void) XFillRectangle(display,windows->magnify.pixmap,
7485 windows->magnify.annotate_context,0,0,width,height);
7486 (void) XPutImage(display,windows->magnify.pixmap,
7487 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,
7488 (
unsigned int) ((
int) width-x),(
unsigned int) ((
int) height-y));
7489 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7490 (magnify <= (height >> 1))))
7498 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7499 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7500 highlight_info.width=magnify;
7501 highlight_info.height=magnify;
7502 (void) XDrawRectangle(display,windows->magnify.pixmap,
7503 windows->magnify.highlight_context,(
int) highlight_info.x,
7504 (
int) highlight_info.y,(
unsigned int) highlight_info.width-1,
7505 (
unsigned int) highlight_info.height-1);
7507 (void) XDrawRectangle(display,windows->magnify.pixmap,
7508 windows->magnify.annotate_context,(
int) highlight_info.x+1,
7509 (
int) highlight_info.y+1,(
unsigned int) highlight_info.width-3,
7510 (
unsigned int) highlight_info.height-3);
7515 (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
7516 (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7517 (void) FormatLocaleString(tuple,MagickPathExtent,
"%d,%d: ",
7518 windows->magnify.x,windows->magnify.y);
7519 (void) ConcatenateMagickString(tuple,
"(",MagickPathExtent);
7520 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7521 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7522 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7523 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7524 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7525 if (pixel.colorspace == CMYKColorspace)
7527 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7528 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7530 if (pixel.alpha_trait != UndefinedPixelTrait)
7532 (void) ConcatenateMagickString(tuple,
",",MagickPathExtent);
7533 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7535 (void) ConcatenateMagickString(tuple,
")",MagickPathExtent);
7536 height=(
unsigned int) (windows->magnify.font_info->ascent+
7537 windows->magnify.font_info->descent);
7538 x=windows->magnify.font_info->max_bounds.width >> 1;
7539 y=windows->magnify.font_info->ascent+(int) (height >> 2);
7540 (void) XDrawImageString(display,windows->magnify.pixmap,
7541 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7542 GetColorTuple(&pixel,MagickTrue,tuple);
7544 (void) XDrawImageString(display,windows->magnify.pixmap,
7545 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7546 (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7549 (void) XDrawImageString(display,windows->magnify.pixmap,
7550 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7554 magnify_window=windows->magnify;
7557 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7589static MagickBooleanType XMakePixmap(Display *display,
7590 const XResourceInfo *resource_info,XWindowInfo *window)
7596 assert(display != (Display *) NULL);
7597 assert(resource_info != (XResourceInfo *) NULL);
7598 assert(window != (XWindowInfo *) NULL);
7599 if (IsEventLogging() != MagickFalse)
7600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7601 if (window->pixmap != (Pixmap) NULL)
7606 (void) XFreePixmap(display,window->pixmap);
7607 window->pixmap=(Pixmap) NULL;
7609 if (window->use_pixmap == MagickFalse)
7610 return(MagickFalse);
7611 if (window->ximage == (XImage *) NULL)
7612 return(MagickFalse);
7616 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7617 (void) XFlush(display);
7621 width=(
unsigned int) window->ximage->width;
7622 height=(
unsigned int) window->ximage->height;
7623 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7624 if (window->pixmap == (Pixmap) NULL)
7629 (void) XCheckDefineCursor(display,window->id,window->cursor);
7630 return(MagickFalse);
7635#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7636 if (window->shared_memory)
7637 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7638 window->ximage,0,0,0,0,width,height,MagickTrue);
7640 if (window->shared_memory == MagickFalse)
7641 (void) XPutImage(display,window->pixmap,window->annotate_context,
7642 window->ximage,0,0,0,0,width,height);
7643 if ((GetLogEventMask() & X11Event) != 0)
7645 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Pixmap:");
7646 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %ux%u",
7652 (void) XCheckDefineCursor(display,window->id,window->cursor);
7696#if defined(__cplusplus) || defined(c_plusplus)
7700static inline double DiversityPixelIntensity(
7701 const DiversityPacket *pixel)
7706 intensity=0.212656*(double) pixel->red+0.715158*(
double) pixel->green+
7707 0.072186*(double) pixel->blue;
7711static int IntensityCompare(
const void *x,
const void *y)
7720 color_1=(DiversityPacket *) x;
7721 color_2=(DiversityPacket *) y;
7722 diversity=(int) (DiversityPixelIntensity(color_2)-
7723 DiversityPixelIntensity(color_1));
7727static int PopularityCompare(
const void *x,
const void *y)
7733 color_1=(DiversityPacket *) x;
7734 color_2=(DiversityPacket *) y;
7735 return((
int) color_2->count-(
int) color_1->count);
7738#if defined(__cplusplus) || defined(c_plusplus)
7742static inline Quantum ScaleXToQuantum(
const size_t x,
7745 return((Quantum) (((
double) QuantumRange*x)/scale+0.5));
7748MagickPrivate
void XMakeStandardColormap(Display *display,
7749 XVisualInfo *visual_info,XResourceInfo *resource_info,
Image *image,
7750 XStandardColormap *map_info,XPixelInfo *pixel,
ExceptionInfo *exception)
7773 assert(display != (Display *) NULL);
7774 assert(visual_info != (XVisualInfo *) NULL);
7775 assert(map_info != (XStandardColormap *) NULL);
7776 assert(resource_info != (XResourceInfo *) NULL);
7777 assert(pixel != (XPixelInfo *) NULL);
7778 if (IsEventLogging() != MagickFalse)
7779 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7780 if (resource_info->map_type != (
char *) NULL)
7785 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7787 number_colors=(
unsigned int) (map_info->base_pixel+
7788 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7789 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7790 if (((image->alpha_trait & BlendPixelTrait) == 0) &&
7791 (resource_info->color_recovery == MagickFalse) &&
7792 (resource_info->quantize_info->dither_method != NoDitherMethod) &&
7793 (number_colors < MaxColormapSize))
7804 affinity_image=AcquireImage((
ImageInfo *) NULL,exception);
7805 if (affinity_image == (
Image *) NULL)
7806 ThrowXWindowFatalException(ResourceLimitFatalError,
7807 "UnableToDitherImage",image->filename);
7808 affinity_image->columns=number_colors;
7809 affinity_image->rows=1;
7813 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7815 if (q != (Quantum *) NULL)
7817 for (i=0; i < (ssize_t) number_colors; i++)
7819 SetPixelRed(affinity_image,0,q);
7820 if (map_info->red_max != 0)
7821 SetPixelRed(affinity_image,ScaleXToQuantum((
size_t)
7822 (i/(ssize_t) map_info->red_mult),map_info->red_max),q);
7823 SetPixelGreen(affinity_image,0,q);
7824 if (map_info->green_max != 0)
7825 SetPixelGreen(affinity_image,ScaleXToQuantum((
size_t)
7826 ((i/(ssize_t) map_info->green_mult) % (ssize_t)
7827 (map_info->green_max+1)),map_info->green_max),q);
7828 SetPixelBlue(affinity_image,0,q);
7829 if (map_info->blue_max != 0)
7830 SetPixelBlue(affinity_image,ScaleXToQuantum((
size_t)
7831 (i % (ssize_t) map_info->green_mult),map_info->blue_max),
7833 SetPixelAlpha(affinity_image,TransparentAlpha,q);
7834 q+=GetPixelChannels(affinity_image);
7836 (void) SyncAuthenticPixels(affinity_image,exception);
7837 (void) RemapImage(resource_info->quantize_info,image,
7838 affinity_image,exception);
7840 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7842 (void) SetImageStorageClass(image,DirectClass,exception);
7843 affinity_image=DestroyImage(affinity_image);
7845 if ((GetLogEventMask() & X11Event) != 0)
7847 (void) LogMagickEvent(X11Event,GetMagickModule(),
7848 "Standard Colormap:");
7849 (void) LogMagickEvent(X11Event,GetMagickModule(),
7850 " colormap id: 0x%lx",map_info->colormap);
7851 (void) LogMagickEvent(X11Event,GetMagickModule(),
7852 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7853 map_info->green_max,map_info->blue_max);
7854 (void) LogMagickEvent(X11Event,GetMagickModule(),
7855 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7856 map_info->green_mult,map_info->blue_mult);
7860 if ((visual_info->klass != DirectColor) &&
7861 (visual_info->klass != TrueColor))
7862 if ((image->storage_class == DirectClass) ||
7863 ((
int) image->colors > visual_info->colormap_size))
7871 quantize_info=(*resource_info->quantize_info);
7872 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7873 (void) QuantizeImage(&quantize_info,image,exception);
7878 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7879 colormap=XDefaultColormap(display,visual_info->screen);
7880 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7881 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7882 visual_info->visual,visual_info->klass == DirectColor ?
7883 AllocAll : AllocNone);
7884 if (colormap == (Colormap) NULL)
7885 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToCreateColormap",
7890 XGetMapInfo(visual_info,colormap,map_info);
7891 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7895 switch (visual_info->klass)
7903 number_colors=image->colors;
7904 colors=(XColor *) AcquireQuantumMemory((
size_t)
7905 visual_info->colormap_size,
sizeof(*colors));
7906 if (colors == (XColor *) NULL)
7907 ThrowXWindowFatalException(ResourceLimitFatalError,
7908 "UnableToCreateColormap",image->filename);
7910 color.flags=(char) (DoRed | DoGreen | DoBlue);
7911 for (i=0; i < (ssize_t) image->colors; i++)
7913 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7914 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7915 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7916 if (visual_info->klass != StaticColor)
7918 gray_value=(
unsigned short) XPixelIntensity(&color);
7919 color.red=gray_value;
7920 color.green=gray_value;
7921 color.blue=gray_value;
7923 status=XAllocColor(display,colormap,&color);
7924 if (status == False)
7926 colormap=XCopyColormapAndFree(display,colormap);
7927 (void) XAllocColor(display,colormap,&color);
7929 pixel->pixels[i]=color.pixel;
7943 number_colors=image->colors;
7944 colors=(XColor *) AcquireQuantumMemory((
size_t)
7945 visual_info->colormap_size,
sizeof(*colors));
7946 if (colors == (XColor *) NULL)
7947 ThrowXWindowFatalException(ResourceLimitFatalError,
7948 "UnableToCreateColormap",image->filename);
7952 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7953 (void) XAllocColor(display,colormap,&pixel->background_color);
7954 (void) XAllocColor(display,colormap,&pixel->border_color);
7955 (void) XAllocColor(display,colormap,&pixel->matte_color);
7956 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7957 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7958 (void) XAllocColor(display,colormap,&pixel->depth_color);
7959 (void) XAllocColor(display,colormap,&pixel->trough_color);
7960 for (i=0; i < MaxNumberPens; i++)
7961 (
void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7965 colormap_type=resource_info->colormap;
7966 status=XAllocColorCells(display,colormap,MagickFalse,(
unsigned long *)
7967 NULL,0,pixel->pixels,(
unsigned int) image->colors);
7968 if (status != False)
7969 colormap_type=PrivateColormap;
7970 if (colormap_type == SharedColormap)
7993 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7994 sizeof(*diversity));
7995 if (diversity == (DiversityPacket *) NULL)
7996 ThrowXWindowFatalException(ResourceLimitFatalError,
7997 "UnableToCreateColormap",image->filename);
7998 for (i=0; i < (ssize_t) image->colors; i++)
8000 diversity[i].red=ClampToQuantum(image->colormap[i].red);
8001 diversity[i].green=ClampToQuantum(image->colormap[i].green);
8002 diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
8003 diversity[i].index=(
unsigned short) i;
8004 diversity[i].count=0;
8006 image_view=AcquireAuthenticCacheView(image,exception);
8007 for (y=0; y < (int) image->rows; y++)
8015 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
8016 image->columns,1,exception);
8017 if (p == (
const Quantum *) NULL)
8019 for (x=(
int) image->columns-1; x >= 0; x--)
8021 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
8022 p+=GetPixelChannels(image);
8025 image_view=DestroyCacheView(image_view);
8029 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
8031 for (i=0; i < (ssize_t) image->colors; )
8033 diversity[i].count<<=4;
8034 i+=MagickMax((
int) (image->colors >> 4),2);
8036 diversity[image->colors-1].count<<=4;
8037 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
8043 color.flags=(char) (DoRed | DoGreen | DoBlue);
8044 for (i=0; i < (ssize_t) image->colors; i++)
8046 index=diversity[i].index;
8048 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8050 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8052 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8053 if (visual_info->klass != PseudoColor)
8055 gray_value=(
unsigned short) XPixelIntensity(&color);
8056 color.red=gray_value;
8057 color.green=gray_value;
8058 color.blue=gray_value;
8060 status=XAllocColor(display,colormap,&color);
8061 if (status == False)
8063 pixel->pixels[index]=color.pixel;
8069 server_colors=(XColor *) AcquireQuantumMemory((
size_t)
8070 visual_info->colormap_size,
sizeof(*server_colors));
8071 if (server_colors == (XColor *) NULL)
8072 ThrowXWindowFatalException(ResourceLimitFatalError,
8073 "UnableToCreateColormap",image->filename);
8074 for (x=visual_info->colormap_size-1; x >= 0; x--)
8075 server_colors[x].pixel=(size_t) x;
8076 (void) XQueryColors(display,colormap,server_colors,
8077 (
int) MagickMin((
unsigned int) visual_info->colormap_size,256));
8081 for (; i < (ssize_t) image->colors; i++)
8083 index=diversity[i].index;
8084 color.red=ScaleQuantumToShort(
8085 XRedGamma(image->colormap[index].red));
8086 color.green=ScaleQuantumToShort(
8087 XGreenGamma(image->colormap[index].green));
8088 color.blue=ScaleQuantumToShort(
8089 XBlueGamma(image->colormap[index].blue));
8090 if (visual_info->klass != PseudoColor)
8092 gray_value=(
unsigned short) XPixelIntensity(&color);
8093 color.red=gray_value;
8094 color.green=gray_value;
8095 color.blue=gray_value;
8097 XBestPixel(display,colormap,server_colors,(
unsigned int)
8098 visual_info->colormap_size,&color);
8099 pixel->pixels[index]=color.pixel;
8102 if ((
int) image->colors < visual_info->colormap_size)
8107 retain_colors=MagickMin((
unsigned int)
8108 (visual_info->colormap_size-(
int) image->colors),256);
8109 for (i=0; i < (ssize_t) retain_colors; i++)
8110 *p++=server_colors[i];
8111 number_colors+=retain_colors;
8113 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8114 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8120 if (status == False)
8125 colormap=XCreateColormap(display,
8126 XRootWindow(display,visual_info->screen),visual_info->visual,
8128 if (colormap == (Colormap) NULL)
8129 ThrowXWindowFatalException(ResourceLimitFatalError,
8130 "UnableToCreateColormap",image->filename);
8131 map_info->colormap=colormap;
8132 if ((
int) image->colors < visual_info->colormap_size)
8138 retain_colors=MagickMin((
unsigned int)
8139 (visual_info->colormap_size-(
int) image->colors),256);
8140 p=colors+image->colors;
8141 for (i=0; i < (ssize_t) retain_colors; i++)
8143 p->pixel=(
unsigned long) i;
8146 (void) XQueryColors(display,
8147 XDefaultColormap(display,visual_info->screen),
8148 colors+image->colors,(
int) retain_colors);
8152 (void) XAllocColorCells(display,colormap,MagickFalse,
8153 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8155 p=colors+image->colors;
8156 for (i=0; i < (ssize_t) retain_colors; i++)
8158 p->pixel=pixel->pixels[i];
8161 (void) XStoreColors(display,colormap,colors+image->colors,
8162 (
int) retain_colors);
8163 number_colors+=retain_colors;
8165 (void) XAllocColorCells(display,colormap,MagickFalse,
8166 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8173 color.flags=(char) (DoRed | DoGreen | DoBlue);
8174 for (i=0; i < (ssize_t) image->colors; i++)
8176 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8177 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8178 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8179 if (visual_info->klass != PseudoColor)
8181 gray_value=(
unsigned short) XPixelIntensity(&color);
8182 color.red=gray_value;
8183 color.green=gray_value;
8184 color.blue=gray_value;
8186 color.pixel=pixel->pixels[i];
8189 (void) XStoreColors(display,colormap,colors,(
int) image->colors);
8202 number_colors=(
unsigned int) ((map_info->red_max*map_info->red_mult)+
8203 (map_info->green_max*map_info->green_mult)+
8204 (map_info->blue_max*map_info->blue_mult)+1);
8205 linear_colormap=(number_colors > 4096) ||
8206 (((
int) (map_info->red_max+1) == visual_info->colormap_size) &&
8207 ((
int) (map_info->green_max+1) == visual_info->colormap_size) &&
8208 ((
int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8209 MagickTrue : MagickFalse;
8210 if (linear_colormap != MagickFalse)
8211 number_colors=(size_t) visual_info->colormap_size;
8215 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
8216 if (colors == (XColor *) NULL)
8217 ThrowXWindowFatalException(ResourceLimitFatalError,
8218 "UnableToCreateColormap",image->filename);
8223 color.flags=(char) (DoRed | DoGreen | DoBlue);
8224 if (linear_colormap != MagickFalse)
8225 for (i=0; i < (ssize_t) number_colors; i++)
8227 color.blue=(
unsigned short) 0;
8228 if (map_info->blue_max != 0)
8229 color.blue=(
unsigned short) (((65535L*(i % (ssize_t)
8230 map_info->green_mult))/(ssize_t) map_info->blue_max));
8231 color.green=color.blue;
8232 color.red=color.blue;
8233 color.pixel=XStandardPixel(map_info,&color);
8237 for (i=0; i < (ssize_t) number_colors; i++)
8239 color.red=(
unsigned short) 0;
8240 if (map_info->red_max != 0)
8241 color.red=(
unsigned short) ((
size_t) ((65535L*(i/(ssize_t)
8242 map_info->red_mult))/(ssize_t) map_info->red_max));
8243 color.green=(
unsigned int) 0;
8244 if (map_info->green_max != 0)
8245 color.green=(
unsigned short) ((
size_t) ((65535L*((i/(ssize_t)
8246 map_info->green_mult) % (ssize_t) (map_info->green_max+1)))/
8247 (ssize_t) map_info->green_max));
8248 color.blue=(
unsigned short) 0;
8249 if (map_info->blue_max != 0)
8250 color.blue=(
unsigned short) ((
size_t) ((65535L*(i % (ssize_t)
8251 map_info->green_mult))/(ssize_t) map_info->blue_max));
8252 color.pixel=XStandardPixel(map_info,&color);
8255 if ((visual_info->klass == DirectColor) &&
8256 (colormap != XDefaultColormap(display,visual_info->screen)))
8257 (void) XStoreColors(display,colormap,colors,(
int) number_colors);
8259 for (i=0; i < (ssize_t) number_colors; i++)
8260 (
void) XAllocColor(display,colormap,&colors[i]);
8264 if ((visual_info->klass != DirectColor) &&
8265 (visual_info->klass != TrueColor))
8270 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8271 &pixel->foreground_color);
8272 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8273 &pixel->background_color);
8274 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8279 pixel->background_color.red=(~pixel->foreground_color.red);
8280 pixel->background_color.green=
8281 (~pixel->foreground_color.green);
8282 pixel->background_color.blue=
8283 (~pixel->foreground_color.blue);
8284 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8285 &pixel->background_color);
8287 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8288 &pixel->border_color);
8289 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8290 &pixel->matte_color);
8291 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8292 &pixel->highlight_color);
8293 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8294 &pixel->shadow_color);
8295 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8296 &pixel->depth_color);
8297 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8298 &pixel->trough_color);
8299 for (i=0; i < MaxNumberPens; i++)
8301 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8302 &pixel->pen_colors[i]);
8303 pixel->pixels[(ssize_t) image->colors+i]=pixel->pen_colors[i].pixel;
8305 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8307 colors=(XColor *) RelinquishMagickMemory(colors);
8308 if ((GetLogEventMask() & X11Event) != 0)
8310 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Standard Colormap:");
8311 (void) LogMagickEvent(X11Event,GetMagickModule(),
" colormap id: 0x%lx",
8312 map_info->colormap);
8313 (void) LogMagickEvent(X11Event,GetMagickModule(),
8314 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8315 map_info->green_max,map_info->blue_max);
8316 (void) LogMagickEvent(X11Event,GetMagickModule(),
8317 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8318 map_info->green_mult,map_info->blue_mult);
8359MagickPrivate
void XMakeWindow(Display *display,Window parent,
char **argv,
8360 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8361 XWindowInfo *window_info)
8363#define MinWindowSize 64
8371 static XTextProperty
8384 assert(display != (Display *) NULL);
8385 assert(window_info != (XWindowInfo *) NULL);
8386 if (IsEventLogging() != MagickFalse)
8387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8388 size_hints=XAllocSizeHints();
8389 if (size_hints == (XSizeHints *) NULL)
8390 ThrowXWindowFatalException(XServerFatalError,
"UnableToMakeXWindow",argv[0]);
8391 size_hints->flags=(int) window_info->flags;
8392 size_hints->x=window_info->x;
8393 size_hints->y=window_info->y;
8394 size_hints->width=(int) window_info->width;
8395 size_hints->height=(int) window_info->height;
8396 if (window_info->immutable != MagickFalse)
8401 size_hints->min_width=size_hints->width;
8402 size_hints->min_height=size_hints->height;
8403 size_hints->max_width=size_hints->width;
8404 size_hints->max_height=size_hints->height;
8405 size_hints->flags|=PMinSize;
8406 size_hints->flags|=PMaxSize;
8413 size_hints->min_width=(int) window_info->min_width;
8414 size_hints->min_height=(int) window_info->min_height;
8415 size_hints->flags|=PResizeInc;
8416 size_hints->width_inc=(int) window_info->width_inc;
8417 size_hints->height_inc=(int) window_info->height_inc;
8418#if !defined(PRE_R4_ICCCM)
8419 size_hints->flags|=PBaseSize;
8420 size_hints->base_width=size_hints->width_inc;
8421 size_hints->base_height=size_hints->height_inc;
8424 gravity=NorthWestGravity;
8425 if (window_info->geometry != (
char *) NULL)
8428 default_geometry[MagickPathExtent],
8429 geometry[MagickPathExtent];
8440 (void) FormatLocaleString(default_geometry,MagickPathExtent,
"%dx%d",
8441 size_hints->width,size_hints->height);
8442 (void) CopyMagickString(geometry,window_info->geometry,MagickPathExtent);
8444 while (strlen(p) != 0)
8446 if ((isspace((
int) ((
unsigned char) *p)) == 0) && (*p !=
'%'))
8449 (
void) memmove(p,p+1,(
size_t) (MagickPathExtent-(p-geometry)));
8451 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8452 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8453 &size_hints->width,&size_hints->height,&gravity);
8454 if ((flags & WidthValue) && (flags & HeightValue))
8455 size_hints->flags|=USSize;
8456 if ((flags & XValue) && (flags & YValue))
8458 size_hints->flags|=USPosition;
8459 window_info->x=size_hints->x;
8460 window_info->y=size_hints->y;
8463#if !defined(PRE_R4_ICCCM)
8464 size_hints->win_gravity=gravity;
8465 size_hints->flags|=PWinGravity;
8467 if (window_info->id == (Window) NULL)
8468 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8469 (
unsigned int) size_hints->width,(
unsigned int) size_hints->height,
8470 window_info->border_width,(
int) window_info->depth,InputOutput,
8471 window_info->visual,(
unsigned long) window_info->mask,
8472 &window_info->attributes);
8487 (void) XChangeWindowAttributes(display,window_info->id,(
unsigned long)
8488 window_info->mask,&window_info->attributes);
8489 mask=ConfigureNotify;
8490 while (XCheckTypedWindowEvent(display,window_info->id,(
int) mask,&sans_event)) ;
8491 window_changes.x=window_info->x;
8492 window_changes.y=window_info->y;
8493 window_changes.width=(int) window_info->width;
8494 window_changes.height=(int) window_info->height;
8495 mask=(MagickStatusType) (CWWidth | CWHeight);
8496 if (window_info->flags & USPosition)
8498 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8499 mask,&window_changes);
8501 if (window_info->id == (Window) NULL)
8502 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateWindow",
8504 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8505 if (status == False)
8506 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8508 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8509 if (status == False)
8510 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8511 window_info->icon_name);
8512 if (window_info->icon_geometry != (
char *) NULL)
8522 size_hints->flags|=USPosition;
8523 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8524 (
char *) NULL,0,size_hints,&manager_hints->icon_x,
8525 &manager_hints->icon_y,&width,&height,&gravity);
8526 if ((flags & XValue) && (flags & YValue))
8527 manager_hints->flags|=IconPositionHint;
8529 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8530 size_hints,manager_hints,class_hint);
8531 if (window_name.value != (
void *) NULL)
8533 (void) XFree((
void *) window_name.value);
8534 window_name.value=(
unsigned char *) NULL;
8535 window_name.nitems=0;
8537 if (icon_name.value != (
void *) NULL)
8539 (void) XFree((
void *) icon_name.value);
8540 icon_name.value=(
unsigned char *) NULL;
8543 atom_list[0]=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
8544 atom_list[1]=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
8545 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8546 (void) XFree((
void *) size_hints);
8547 if (window_info->shape != MagickFalse)
8549#if defined(MAGICKCORE_HAVE_SHAPE)
8559 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8560 window_info->shape=MagickFalse;
8562 window_info->shape=MagickFalse;
8565 window_info->shape=MagickFalse;
8566 if (window_info->shared_memory != MagickFalse)
8568#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8572 if (XShmQueryExtension(display) == 0)
8573 window_info->shared_memory=MagickFalse;
8575 window_info->shared_memory=MagickFalse;
8578 window_info->image=NewImageList();
8579 window_info->destroy=MagickFalse;
8615static const char *GetLocaleMonitorMessage(
const char *text)
8618 message[MagickPathExtent],
8619 tag[MagickPathExtent];
8627 (void) CopyMagickString(tag,text,MagickPathExtent);
8629 if (p != (
char *) NULL)
8631 (void) FormatLocaleString(message,MagickPathExtent,
"Monitor/%s",tag);
8632 locale_message=GetLocaleMessage(message);
8633 if (locale_message == message)
8635 return(locale_message);
8638MagickPrivate MagickBooleanType XMagickProgressMonitor(
const char *tag,
8639 const MagickOffsetType quantum,
const MagickSizeType span,
8640 void *magick_unused(client_data))
8645 windows=XSetWindows((XWindows *) ~0);
8646 if (windows == (XWindows *) NULL)
8648 if (windows->info.mapped != MagickFalse)
8649 XProgressMonitorWidget(windows->display,windows,
8650 GetLocaleMonitorMessage(tag),quantum,span);
8680MagickPrivate MagickBooleanType XQueryColorCompliance(
const char *target,
8687 *display = (Display *) NULL;
8698 assert(color != (XColor *) NULL);
8702 color->flags=(char) (DoRed | DoGreen | DoBlue);
8703 if ((target == (
char *) NULL) || (*target ==
'\0'))
8704 target=
"#ffffffffffff";
8708 if (display == (Display *) NULL)
8709 display=XOpenDisplay((
char *) NULL);
8710 if (display == (Display *) NULL)
8712 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",target);
8713 return(MagickFalse);
8715 colormap=XDefaultColormap(display,XDefaultScreen(display));
8716 status=XParseColor(display,colormap,(
char *) target,&xcolor);
8717 if (status == False)
8718 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",target)
8721 color->red=xcolor.red;
8722 color->green=xcolor.green;
8723 color->blue=xcolor.blue;
8724 color->flags=xcolor.flags;
8726 return(status != False ? MagickTrue : MagickFalse);
8760MagickPrivate
void XQueryPosition(Display *display,
const Window window,
int *x,
8773 assert(display != (Display *) NULL);
8774 assert(window != (Window) NULL);
8775 assert(x != (
int *) NULL);
8776 assert(y != (
int *) NULL);
8777 if (IsEventLogging() != MagickFalse)
8778 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8779 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8812MagickPrivate
void XRefreshWindow(Display *display,
const XWindowInfo *window,
8813 const XEvent *event)
8823 assert(display != (Display *) NULL);
8824 assert(window != (XWindowInfo *) NULL);
8825 if (IsEventLogging() != MagickFalse)
8826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8827 if (window->ximage == (XImage *) NULL)
8829 if (event != (XEvent *) NULL)
8836 width=(
unsigned int) event->xexpose.width;
8837 height=(
unsigned int) event->xexpose.height;
8849 width=window->width;
8850 height=window->height;
8851 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8852 if (window->matte_pixmap != (Pixmap) NULL)
8854#if defined(MAGICKCORE_HAVE_SHAPE)
8855 if (window->shape != MagickFalse)
8856 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8857 window->matte_pixmap,ShapeSet);
8864 if ((window->ximage->width-(x+window->x)) < (
int) width)
8865 width=(
unsigned int) (window->ximage->width-(x+window->x));
8866 if ((window->ximage->height-(y+window->y)) < (
int) height)
8867 height=(
unsigned int) (window->ximage->height-(y+window->y));
8871 if (window->matte_pixmap != (Pixmap) NULL)
8872 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8873 if (window->pixmap != (Pixmap) NULL)
8875 if (window->depth > 1)
8876 (void) XCopyArea(display,window->pixmap,window->id,
8877 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8879 (
void) XCopyPlane(display,window->pixmap,window->id,
8880 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8885#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8886 if (window->shared_memory)
8887 (void) XShmPutImage(display,window->id,window->annotate_context,
8888 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8890 if (window->shared_memory == MagickFalse)
8891 (void) XPutImage(display,window->id,window->annotate_context,
8892 window->ximage,x+window->x,y+window->y,x,y,width,height);
8894 if (window->matte_pixmap != (Pixmap) NULL)
8895 (void) XSetClipMask(display,window->annotate_context,None);
8896 (void) XFlush(display);
8928MagickExport MagickBooleanType XRemoteCommand(Display *display,
8929 const char *window,
const char *filename)
8938 assert(filename != (
char *) NULL);
8939 if (IsEventLogging() != MagickFalse)
8940 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
8941 if (display == (Display *) NULL)
8942 display=XOpenDisplay((
char *) NULL);
8943 if (display == (Display *) NULL)
8945 ThrowXWindowException(XServerError,
"UnableToOpenXServer",filename);
8946 return(MagickFalse);
8948 remote_atom=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
8949 remote_window=(Window) NULL;
8950 root_window=XRootWindow(display,XDefaultScreen(display));
8951 if (window != (
char *) NULL)
8956 if (isdigit((
int) ((
unsigned char) *window)) != 0)
8957 remote_window=XWindowByID(display,root_window,(Window)
8958 strtol((
char *) window,(
char **) NULL,0));
8959 if (remote_window == (Window) NULL)
8960 remote_window=XWindowByName(display,root_window,window);
8962 if (remote_window == (Window) NULL)
8963 remote_window=XWindowByProperty(display,root_window,remote_atom);
8964 if (remote_window == (Window) NULL)
8966 ThrowXWindowException(XServerError,
"UnableToConnectToRemoteDisplay",
8968 return(MagickFalse);
8973 remote_atom=XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
8974 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8975 PropModeReplace,(
unsigned char *) filename,(
int) strlen(filename));
8976 (void) XSync(display,MagickFalse);
9012MagickPrivate MagickBooleanType XRenderImage(
Image *image,
9024 *display = (Display *) NULL;
9029 static XAnnotateInfo
9038 static XResourceInfo
9044 static XStandardColormap
9050 if (display == (Display *) NULL)
9061 display=XOpenDisplay(draw_info->server_name);
9062 if (display == (Display *) NULL)
9064 ThrowXWindowException(XServerError,
"UnableToOpenXServer",
9065 draw_info->server_name);
9066 return(MagickFalse);
9071 (void) XSetErrorHandler(XError);
9072 image_info=AcquireImageInfo();
9073 client_name=GetClientName();
9074 resource_database=XGetResourceDatabase(display,client_name);
9075 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
9076 resource_info.close_server=MagickFalse;
9077 resource_info.colormap=PrivateColormap;
9078 resource_info.font=AcquireString(draw_info->font);
9079 resource_info.background_color=AcquireString(
"#ffffffffffff");
9080 resource_info.foreground_color=AcquireString(
"#000000000000");
9081 map_info=XAllocStandardColormap();
9082 visual_info=(XVisualInfo *) NULL;
9083 font_info=(XFontStruct *) NULL;
9084 pixel.pixels=(
unsigned long *) NULL;
9085 if (map_info == (XStandardColormap *) NULL)
9087 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
9089 return(MagickFalse);
9094 visual_info=XBestVisualInfo(display,map_info,&resource_info);
9095 if (visual_info == (XVisualInfo *) NULL)
9097 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9098 &resource_info,(XWindowInfo *) NULL);
9099 ThrowXWindowException(XServerError,
"UnableToGetVisual",
9101 return(MagickFalse);
9103 map_info->colormap=(Colormap) NULL;
9107 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9109 XGetPixelInfo(display,visual_info,map_info,&resource_info,(
Image *) NULL,
9111 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9115 font_info=XBestFont(display,&resource_info,MagickFalse);
9116 if (font_info == (XFontStruct *) NULL)
9118 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9119 &resource_info,(XWindowInfo *) NULL);
9120 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9122 return(MagickFalse);
9124 cache_info=(*draw_info);
9129 XGetAnnotateInfo(&annotate_info);
9130 annotate_info.stencil=ForegroundStencil;
9131 if (cache_info.font != draw_info->font)
9136 (void) XFreeFont(display,font_info);
9137 (void) CloneString(&resource_info.font,draw_info->font);
9138 font_info=XBestFont(display,&resource_info,MagickFalse);
9139 if (font_info == (XFontStruct *) NULL)
9141 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9143 return(MagickFalse);
9146 if (draw_info->debug != MagickFalse)
9147 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9148 "Font %s; pointsize %g",draw_info->font != (
char *) NULL ?
9149 draw_info->font :
"none",draw_info->pointsize);
9150 cache_info=(*draw_info);
9151 annotate_info.font_info=font_info;
9152 annotate_info.text=(
char *) draw_info->text;
9153 annotate_info.width=(
unsigned int) XTextWidth(font_info,draw_info->text,(
int)
9154 strlen(draw_info->text));
9155 annotate_info.height=(
unsigned int) (font_info->ascent+font_info->descent);
9156 metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
9157 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9158 metrics->ascent=(double) font_info->ascent+4;
9159 metrics->descent=(double) (-font_info->descent);
9160 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9161 metrics->height=(double) font_info->ascent+font_info->descent;
9162 metrics->max_advance=(double) font_info->max_bounds.width;
9163 metrics->bounds.x1=0.0;
9164 metrics->bounds.y1=metrics->descent;
9165 metrics->bounds.x2=metrics->ascent+metrics->descent;
9166 metrics->bounds.y2=metrics->ascent+metrics->descent;
9167 metrics->underline_position=(-2.0);
9168 metrics->underline_thickness=1.0;
9169 if (draw_info->render == MagickFalse)
9171 if (draw_info->fill.alpha == (
double) TransparentAlpha)
9176 width=annotate_info.width;
9177 height=annotate_info.height;
9178 if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
9179 (fabs(draw_info->affine.ry) >= MagickEpsilon))
9181 if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
9182 (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
9183 annotate_info.degrees=(double) (180.0/MagickPI)*
9184 atan2(draw_info->affine.rx,draw_info->affine.sx);
9186 (void) FormatLocaleString(annotate_info.geometry,MagickPathExtent,
9187 "%.20gx%.20g%+.20g%+.20g",(
double) width,(
double) height,
9188 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9189 draw_info->interline_spacing-0.5));
9190 pixel.pen_color.red=ScaleQuantumToShort(
9191 ClampToQuantum(draw_info->fill.red));
9192 pixel.pen_color.green=ScaleQuantumToShort(
9193 ClampToQuantum(draw_info->fill.green));
9194 pixel.pen_color.blue=ScaleQuantumToShort(
9195 ClampToQuantum(draw_info->fill.blue));
9196 status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
9199 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
9201 return(MagickFalse);
9232MagickExport
void XRetainWindowColors(Display *display,
const Window window)
9243 assert(display != (Display *) NULL);
9244 assert(window != (Window) NULL);
9245 if (IsEventLogging() != MagickFalse)
9246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9247 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
9248 if (property == (Atom) NULL)
9250 ThrowXWindowException(XServerError,
"UnableToCreateProperty",
9254 pixmap=XCreatePixmap(display,window,1,1,1);
9255 if (pixmap == (Pixmap) NULL)
9257 ThrowXWindowException(XServerError,
"UnableToCreateBitmap",
"");
9260 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9261 (
unsigned char *) &pixmap,1);
9262 (void) XSetCloseDownMode(display,RetainPermanent);
9295static Window XSelectWindow(Display *display,
RectangleInfo *crop_info)
9297#define MinimumCropArea (unsigned int) 9
9326 assert(display != (Display *) NULL);
9328 if (IsEventLogging() != MagickFalse)
9329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9330 root_window=XRootWindow(display,XDefaultScreen(display));
9331 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9332 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9333 context_values.function=GXinvert;
9334 context_values.plane_mask=
9335 context_values.background ^ context_values.foreground;
9336 context_values.subwindow_mode=IncludeInferiors;
9337 annotate_context=XCreateGC(display,root_window,(
size_t) (GCBackground |
9338 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9339 if (annotate_context == (GC) NULL)
9340 return((Window) NULL);
9344 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9345 XDefaultScreen(display)),(
char * )
"white",(
char * )
"black");
9346 status=XGrabPointer(display,root_window,MagickFalse,(
unsigned int)
9347 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9348 GrabModeAsync,root_window,target_cursor,CurrentTime);
9349 if (status != GrabSuccess)
9351 ThrowXWindowException(XServerError,
"UnableToGrabMouse",
"");
9352 return((Window) NULL);
9358 crop_info->height=0;
9360 target_window=(Window) NULL;
9363 (void) XGrabServer(display);
9366 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9367 (void) XDrawRectangle(display,root_window,annotate_context,
9368 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9369 (
unsigned int) crop_info->height-1);
9373 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9374 (void) XWindowEvent(display,root_window,ButtonPressMask |
9375 ButtonReleaseMask | ButtonMotionMask,&event);
9376 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9377 (void) XDrawRectangle(display,root_window,annotate_context,
9378 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9379 (
unsigned int) crop_info->height-1);
9384 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9385 event.xbutton.x,event.xbutton.y);
9386 if (target_window == (Window) NULL)
9387 target_window=root_window;
9388 x_offset=
event.xbutton.x_root;
9389 y_offset=
event.xbutton.y_root;
9390 crop_info->x=(ssize_t) x_offset;
9391 crop_info->y=(ssize_t) y_offset;
9393 crop_info->height=0;
9407 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9408 crop_info->x=(ssize_t) event.xmotion.x;
9409 crop_info->y=(ssize_t) event.xmotion.y;
9413 if ((
int) crop_info->x < x_offset)
9414 crop_info->width=(size_t) (x_offset-crop_info->x);
9417 crop_info->width=(size_t) (crop_info->x-x_offset);
9418 crop_info->x=(ssize_t) x_offset;
9420 if ((
int) crop_info->y < y_offset)
9421 crop_info->height=(size_t) (y_offset-crop_info->y);
9424 crop_info->height=(size_t) (crop_info->y-y_offset);
9425 crop_info->y=(ssize_t) y_offset;
9431 }
while ((target_window == (Window) NULL) || (presses > 0));
9432 (void) XUngrabServer(display);
9433 (void) XUngrabPointer(display,CurrentTime);
9434 (void) XFreeCursor(display,target_cursor);
9435 (void) XFreeGC(display,annotate_context);
9436 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9439 crop_info->height=0;
9441 if ((crop_info->width != 0) && (crop_info->height != 0))
9442 target_window=root_window;
9443 if (event.xbutton.button == Button3)
9444 target_window=(Window) NULL;
9445 return(target_window);
9477MagickPrivate
void XSetCursorState(Display *display,XWindows *windows,
9478 const MagickStatusType state)
9480 assert(display != (Display *) NULL);
9481 assert(windows != (XWindows *) NULL);
9482 if (IsEventLogging() != MagickFalse)
9483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9486 (void) XCheckDefineCursor(display,windows->image.id,
9487 windows->image.busy_cursor);
9488 (void) XCheckDefineCursor(display,windows->pan.id,
9489 windows->pan.busy_cursor);
9490 (void) XCheckDefineCursor(display,windows->magnify.id,
9491 windows->magnify.busy_cursor);
9492 (void) XCheckDefineCursor(display,windows->command.id,
9493 windows->command.busy_cursor);
9497 (void) XCheckDefineCursor(display,windows->image.id,
9498 windows->image.cursor);
9499 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9500 (void) XCheckDefineCursor(display,windows->magnify.id,
9501 windows->magnify.cursor);
9502 (void) XCheckDefineCursor(display,windows->command.id,
9503 windows->command.cursor);
9504 (void) XCheckDefineCursor(display,windows->command.id,
9505 windows->widget.cursor);
9506 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9508 windows->info.mapped=MagickFalse;
9534MagickPrivate XWindows *XSetWindows(XWindows *windows_info)
9537 *windows = (XWindows *) NULL;
9539 if (windows_info != (XWindows *) ~0)
9541 windows=(XWindows *) RelinquishMagickMemory(windows);
9542 windows=windows_info;
9569MagickPrivate
void XUserPreferences(XResourceInfo *resource_info)
9571#if defined(X11_PREFERENCES_PATH)
9573 cache[MagickPathExtent],
9574 filename[MagickPathExtent],
9575 specifier[MagickPathExtent];
9582 preferences_database;
9587 assert(resource_info != (XResourceInfo *) NULL);
9588 client_name=GetClientName();
9589 preferences_database=XrmGetStringDatabase(
"");
9590 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.backdrop",client_name);
9591 value=resource_info->backdrop ?
"True" :
"False";
9592 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9593 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.colormap",client_name);
9594 value=resource_info->colormap == SharedColormap ?
"Shared" :
"Private";
9595 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9596 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.confirmExit",
9598 value=resource_info->confirm_exit ?
"True" :
"False";
9599 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9600 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.confirmEdit",
9602 value=resource_info->confirm_edit ?
"True" :
"False";
9603 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9604 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.displayWarnings",
9606 value=resource_info->display_warnings ?
"True" :
"False";
9607 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9608 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.dither",client_name);
9609 value=resource_info->quantize_info->dither_method != NoDitherMethod ?
9611 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9612 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.gammaCorrect",
9614 value=resource_info->gamma_correct ?
"True" :
"False";
9615 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9616 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.undoCache",client_name);
9617 (void) FormatLocaleString(cache,MagickPathExtent,
"%.20g",(
double)
9618 resource_info->undo_cache);
9619 XrmPutStringResource(&preferences_database,specifier,cache);
9620 (void) FormatLocaleString(specifier,MagickPathExtent,
"%s.usePixmap",client_name);
9621 value=resource_info->use_pixmap ?
"True" :
"False";
9622 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9623 (void) FormatLocaleString(filename,MagickPathExtent,
"%s%src",
9624 X11_PREFERENCES_PATH,client_name);
9625 ExpandFilename(filename);
9626 XrmPutFileDatabase(preferences_database,filename);
9655static const char *XVisualClassName(
const int visual_class)
9657 switch (visual_class)
9659 case StaticGray:
return(
"StaticGray");
9660 case GrayScale:
return(
"GrayScale");
9661 case StaticColor:
return(
"StaticColor");
9662 case PseudoColor:
return(
"PseudoColor");
9663 case TrueColor:
return(
"TrueColor");
9664 case DirectColor:
return(
"DirectColor");
9666 return(
"unknown visual class");
9697MagickPrivate
void XWarning(
const ExceptionType magick_unused(warning),
9698 const char *reason,
const char *description)
9701 text[MagickPathExtent];
9706 if (reason == (
char *) NULL)
9708 (void) CopyMagickString(text,reason,MagickPathExtent);
9709 (void) ConcatenateMagickString(text,
":",MagickPathExtent);
9710 windows=XSetWindows((XWindows *) ~0);
9711 XNoticeWidget(windows->display,windows,text,(
char *) description);
9744MagickPrivate Window XWindowByID(Display *display,
const Window root_window,
9764 assert(display != (Display *) NULL);
9765 assert(root_window != (Window) NULL);
9766 if (IsEventLogging() != MagickFalse)
9767 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9769 return(XSelectWindow(display,&rectangle_info));
9770 if (root_window ==
id)
9771 return(root_window);
9772 status=XQueryTree(display,root_window,&child,&child,&children,
9774 if (status == False)
9775 return((Window) NULL);
9776 window=(Window) NULL;
9777 for (i=0; i < (int) number_children; i++)
9782 window=XWindowByID(display,children[i],
id);
9783 if (window != (Window) NULL)
9786 if (children != (Window *) NULL)
9787 (void) XFree((
void *) children);
9823MagickPrivate Window XWindowByName(Display *display,
const Window root_window,
9843 assert(display != (Display *) NULL);
9844 assert(root_window != (Window) NULL);
9845 assert(name != (
char *) NULL);
9846 if (IsEventLogging() != MagickFalse)
9847 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
9848 if (XGetWMName(display,root_window,&window_name) != 0)
9849 if (LocaleCompare((
char *) window_name.value,name) == 0)
9850 return(root_window);
9851 status=XQueryTree(display,root_window,&child,&child,&children,
9853 if (status == False)
9854 return((Window) NULL);
9855 window=(Window) NULL;
9856 for (i=0; i < (int) number_children; i++)
9861 window=XWindowByName(display,children[i],name);
9862 if (window != (Window) NULL)
9865 if (children != (Window *) NULL)
9866 (void) XFree((
void *) children);
9901MagickPrivate Window XWindowByProperty(Display *display,
const Window window,
9902 const Atom property)
9930 assert(display != (Display *) NULL);
9931 assert(window != (Window) NULL);
9932 assert(property != (Atom) NULL);
9933 if (IsEventLogging() != MagickFalse)
9934 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9935 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9936 if (status == False)
9937 return((Window) NULL);
9939 child=(Window) NULL;
9940 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9942 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9943 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9945 (void) XFree((
void *) data);
9946 if ((status == Success) && (type != (Atom) NULL))
9949 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9950 child=XWindowByProperty(display,children[i],property);
9951 if (children != (Window *) NULL)
9952 (void) XFree((
void *) children);
9987 assert(image_info != (
const ImageInfo *) NULL);
9988 assert(image_info->signature == MagickCoreSignature);
9991 assert(exception->signature == MagickCoreSignature);
9992 if (IsEventLogging() != MagickFalse)
9993 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
9994 image_info->filename);
9997 return((
Image *) NULL);
10032MagickPrivate MagickBooleanType XRenderImage(
Image *image,
10039 (void) ThrowMagickException(exception,GetMagickModule(),
10040 MissingDelegateError,
"DelegateLibrarySupportNotBuiltIn",
"'%s' (X11)",
10042 return(MagickFalse);
10064MagickPrivate MagickBooleanType XComponentGenesis(
void)
10066 return(MagickTrue);
10091MagickExport
void XGetImportInfo(
XImportInfo *ximage_info)
10094 ximage_info->frame=MagickFalse;
10095 ximage_info->borders=MagickFalse;
10096 ximage_info->screen=MagickFalse;
10097 ximage_info->descend=MagickTrue;
10098 ximage_info->silent=MagickFalse;