42 #include "magick/studio.h"
43 #include "magick/animate.h"
44 #include "magick/artifact.h"
45 #include "magick/blob.h"
46 #include "magick/cache.h"
47 #include "magick/client.h"
48 #include "magick/color.h"
49 #include "magick/color-private.h"
50 #include "magick/colormap.h"
51 #include "magick/composite.h"
52 #include "magick/display.h"
53 #include "magick/distort.h"
54 #include "magick/exception.h"
55 #include "magick/exception-private.h"
56 #include "magick/geometry.h"
57 #include "magick/identify.h"
58 #include "magick/image.h"
59 #include "magick/image-private.h"
60 #include "magick/list.h"
61 #include "magick/locale_.h"
62 #include "magick/log.h"
63 #include "magick/magick.h"
64 #include "magick/memory_.h"
65 #include "magick/memory-private.h"
66 #include "magick/monitor.h"
67 #include "magick/nt-base-private.h"
68 #include "magick/option.h"
69 #include "magick/quantize.h"
70 #include "magick/quantum.h"
71 #include "magick/quantum-private.h"
72 #include "magick/resource_.h"
73 #include "magick/resize.h"
74 #include "magick/statistic.h"
75 #include "magick/string_.h"
76 #include "magick/string-private.h"
77 #include "magick/token.h"
78 #include "magick/transform.h"
79 #include "magick/utility.h"
80 #include "magick/widget.h"
81 #include "magick/xwindow.h"
82 #include "magick/xwindow-private.h"
83 #include "magick/version.h"
87 #if defined(MAGICKCORE_X11_DELEGATE)
88 #include <X11/Xproto.h>
89 #include <X11/Xlocale.h>
90 #if defined(MAGICK_HAVE_POLL)
91 # include <sys/poll.h>
93 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
94 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
95 # include <machine/param.h>
99 #include <X11/extensions/XShm.h>
101 #if defined(MAGICKCORE_HAVE_SHAPE)
102 #include <X11/extensions/shape.h>
108 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
109 (color) : ((pow(((double) QuantumScale*(color)),1.0* \
110 PerceptibleReciprocal((double) blue_gamma))*QuantumRange)))
111 #define XGammaPixel(map,color) (size_t) (map->base_pixel+ \
112 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
114 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
116 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
118 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
119 (color) : ((pow(((double) QuantumScale*(color)),1.0* \
120 PerceptibleReciprocal((double) green_gamma))*QuantumRange)))
121 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
122 (color) : ((pow(((double) QuantumScale*(color)),1.0* \
123 PerceptibleReciprocal((double) red_gamma))*QuantumRange)))
124 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
125 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
126 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
127 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
129 #define AccentuateModulate ScaleCharToQuantum(80)
130 #define HighlightModulate ScaleCharToQuantum(125)
131 #define ShadowModulate ScaleCharToQuantum(135)
132 #define DepthModulate ScaleCharToQuantum(185)
133 #define TroughModulate ScaleCharToQuantum(110)
135 #define XLIB_ILLEGAL_ACCESS 1
137 #undef NorthWestGravity
139 #undef NorthEastGravity
143 #undef SouthWestGravity
145 #undef SouthEastGravity
152 #define XFD_SET fd_set
172 typedef struct _DiversityPacket
189 static MagickBooleanType
190 xerror_alert = MagickFalse;
196 *XVisualClassName(
const int);
198 static MagickRealType
203 static MagickBooleanType
204 XMakePixmap(Display *,
const XResourceInfo *,XWindowInfo *);
207 XMakeImageLSBFirst(
const XResourceInfo *,
const XWindowInfo *,
Image *,
209 XMakeImageMSBFirst(
const XResourceInfo *,
const XWindowInfo *,
Image *,
235 MagickExport
void DestroyXResources(
void)
244 *magick_windows[MaxXWindows];
250 windows=XSetWindows((XWindows *) ~0);
251 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
254 magick_windows[number_windows++]=(&windows->context);
255 magick_windows[number_windows++]=(&windows->group_leader);
256 magick_windows[number_windows++]=(&windows->backdrop);
257 magick_windows[number_windows++]=(&windows->icon);
258 magick_windows[number_windows++]=(&windows->image);
259 magick_windows[number_windows++]=(&windows->info);
260 magick_windows[number_windows++]=(&windows->magnify);
261 magick_windows[number_windows++]=(&windows->pan);
262 magick_windows[number_windows++]=(&windows->command);
263 magick_windows[number_windows++]=(&windows->widget);
264 magick_windows[number_windows++]=(&windows->popup);
265 for (i=0; i < (int) number_windows; i++)
267 if (magick_windows[i]->mapped != MagickFalse)
269 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
270 magick_windows[i]->screen);
271 magick_windows[i]->mapped=MagickFalse;
273 if (magick_windows[i]->name != (
char *) NULL)
274 magick_windows[i]->name=(
char *)
275 RelinquishMagickMemory(magick_windows[i]->name);
276 if (magick_windows[i]->icon_name != (
char *) NULL)
277 magick_windows[i]->icon_name=(
char *)
278 RelinquishMagickMemory(magick_windows[i]->icon_name);
279 if (magick_windows[i]->cursor != (Cursor) NULL)
281 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
282 magick_windows[i]->cursor=(Cursor) NULL;
284 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
286 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
287 magick_windows[i]->busy_cursor=(Cursor) NULL;
289 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
291 (void) XFreePixmap(windows->display,
292 magick_windows[i]->highlight_stipple);
293 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
295 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
297 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
298 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
300 if (magick_windows[i]->matte_image != (XImage *) NULL)
302 XDestroyImage(magick_windows[i]->matte_image);
303 magick_windows[i]->matte_image=(XImage *) NULL;
305 if (magick_windows[i]->ximage != (XImage *) NULL)
307 XDestroyImage(magick_windows[i]->ximage);
308 magick_windows[i]->ximage=(XImage *) NULL;
310 if (magick_windows[i]->pixmap != (Pixmap) NULL)
312 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
313 magick_windows[i]->pixmap=(Pixmap) NULL;
315 if (magick_windows[i]->
id != (Window) NULL)
317 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
318 magick_windows[i]->id=(Window) NULL;
320 if (magick_windows[i]->destroy != MagickFalse)
322 if (magick_windows[i]->image != (
Image *) NULL)
324 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
325 magick_windows[i]->image=NewImageList();
327 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
329 (void) XFreePixmap(windows->display,
330 magick_windows[i]->matte_pixmap);
331 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
334 if (magick_windows[i]->segment_info != (
void *) NULL)
336 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
340 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
341 if (segment_info != (XShmSegmentInfo *) NULL)
342 if (segment_info[0].shmid >= 0)
344 if (segment_info[0].shmaddr != NULL)
345 (void) shmdt(segment_info[0].shmaddr);
346 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
347 segment_info[0].shmaddr=NULL;
348 segment_info[0].shmid=(-1);
351 magick_windows[i]->segment_info=(
void *) RelinquishMagickMemory(
352 magick_windows[i]->segment_info);
355 windows->icon_resources=(XResourceInfo *)
356 RelinquishMagickMemory(windows->icon_resources);
357 if (windows->icon_pixel != (XPixelInfo *) NULL)
359 if (windows->icon_pixel->pixels != (
unsigned long *) NULL)
360 windows->icon_pixel->pixels=(
unsigned long *)
361 RelinquishMagickMemory(windows->icon_pixel->pixels);
362 if (windows->icon_pixel->annotate_context != (GC) NULL)
363 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
364 windows->icon_pixel=(XPixelInfo *)
365 RelinquishMagickMemory(windows->icon_pixel);
367 if (windows->pixel_info != (XPixelInfo *) NULL)
369 if (windows->pixel_info->pixels != (
unsigned long *) NULL)
370 windows->pixel_info->pixels=(
unsigned long *)
371 RelinquishMagickMemory(windows->pixel_info->pixels);
372 if (windows->pixel_info->annotate_context != (GC) NULL)
373 XFreeGC(windows->display,windows->pixel_info->annotate_context);
374 if (windows->pixel_info->widget_context != (GC) NULL)
375 XFreeGC(windows->display,windows->pixel_info->widget_context);
376 if (windows->pixel_info->highlight_context != (GC) NULL)
377 XFreeGC(windows->display,windows->pixel_info->highlight_context);
378 windows->pixel_info=(XPixelInfo *)
379 RelinquishMagickMemory(windows->pixel_info);
381 if (windows->font_info != (XFontStruct *) NULL)
383 XFreeFont(windows->display,windows->font_info);
384 windows->font_info=(XFontStruct *) NULL;
386 if (windows->class_hints != (XClassHint *) NULL)
388 if (windows->class_hints->res_name != (
char *) NULL)
389 windows->class_hints->res_name=DestroyString(
390 windows->class_hints->res_name);
391 if (windows->class_hints->res_class != (
char *) NULL)
392 windows->class_hints->res_class=DestroyString(
393 windows->class_hints->res_class);
394 XFree(windows->class_hints);
395 windows->class_hints=(XClassHint *) NULL;
397 if (windows->manager_hints != (XWMHints *) NULL)
399 XFree(windows->manager_hints);
400 windows->manager_hints=(XWMHints *) NULL;
402 if (windows->map_info != (XStandardColormap *) NULL)
404 XFree(windows->map_info);
405 windows->map_info=(XStandardColormap *) NULL;
407 if (windows->icon_map != (XStandardColormap *) NULL)
409 XFree(windows->icon_map);
410 windows->icon_map=(XStandardColormap *) NULL;
412 if (windows->visual_info != (XVisualInfo *) NULL)
414 XFree(windows->visual_info);
415 windows->visual_info=(XVisualInfo *) NULL;
417 if (windows->icon_visual != (XVisualInfo *) NULL)
419 XFree(windows->icon_visual);
420 windows->icon_visual=(XVisualInfo *) NULL;
422 (void) XSetWindows((XWindows *) NULL);
455 MagickExport MagickBooleanType XAnnotateImage(Display *display,
456 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,
Image *image)
497 assert(display != (Display *) NULL);
498 assert(pixel != (XPixelInfo *) NULL);
499 assert(annotate_info != (XAnnotateInfo *) NULL);
500 assert(image != (
Image *) NULL);
501 if (IsEventLogging() != MagickFalse)
502 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
506 root_window=XRootWindow(display,XDefaultScreen(display));
507 depth=(
unsigned int) XDefaultDepth(display,XDefaultScreen(display));
508 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
509 annotate_info->height,depth);
510 if (annotate_pixmap == (Pixmap) NULL)
515 context_values.background=0;
516 context_values.foreground=(size_t) (~0);
517 context_values.font=annotate_info->font_info->fid;
518 annotate_context=XCreateGC(display,root_window,(
unsigned long)
519 (GCBackground | GCFont | GCForeground),&context_values);
520 if (annotate_context == (GC) NULL)
525 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
526 (
int) annotate_info->font_info->ascent,annotate_info->text,
527 (int) strlen(annotate_info->text));
528 (void) XFreeGC(display,annotate_context);
532 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
533 annotate_info->height,AllPlanes,ZPixmap);
534 if (annotate_ximage == (XImage *) NULL)
536 (void) XFreePixmap(display,annotate_pixmap);
540 annotate_image=AcquireImage((
ImageInfo *) NULL);
541 if (annotate_image == (
Image *) NULL)
543 annotate_image->columns=annotate_info->width;
544 annotate_image->rows=annotate_info->height;
548 width=(
unsigned int) image->columns;
549 height=(
unsigned int) image->rows;
552 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
553 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
554 &annotate_image->background_color,&image->exception);
555 if (annotate_info->stencil == ForegroundStencil)
556 annotate_image->matte=MagickTrue;
557 exception=(&image->exception);
558 annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
559 for (y=0; y < (int) annotate_image->rows; y++)
567 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
568 annotate_image->columns,1,exception);
571 for (x=0; x < (int) annotate_image->columns; x++)
573 SetPixelOpacity(q,OpaqueOpacity);
574 if (XGetPixel(annotate_ximage,x,y) == 0)
579 SetPixelRed(q,ScaleShortToQuantum(pixel->box_color.red));
580 SetPixelGreen(q,ScaleShortToQuantum(pixel->box_color.green));
581 SetPixelBlue(q,ScaleShortToQuantum(pixel->box_color.blue));
582 if ((annotate_info->stencil == ForegroundStencil) ||
583 (annotate_info->stencil == OpaqueStencil))
584 SetPixelOpacity(q,TransparentOpacity);
591 SetPixelRed(q,ScaleShortToQuantum(pixel->pen_color.red));
592 SetPixelGreen(q,ScaleShortToQuantum(pixel->pen_color.green));
593 SetPixelBlue(q,ScaleShortToQuantum(pixel->pen_color.blue));
594 if (annotate_info->stencil == BackgroundStencil)
595 SetPixelOpacity(q,TransparentOpacity);
599 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
602 annotate_view=DestroyCacheView(annotate_view);
603 XDestroyImage(annotate_ximage);
607 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
608 if ((width != (
unsigned int) annotate_image->columns) ||
609 (height != (
unsigned int) annotate_image->rows))
612 image_geometry[MaxTextExtent];
617 (void) FormatLocaleString(image_geometry,MaxTextExtent,
"%ux%u",
619 (void) TransformImage(&annotate_image,(
char *) NULL,image_geometry);
621 if (annotate_info->degrees != 0.0)
636 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
637 if (rotate_image == (
Image *) NULL)
639 annotate_image=DestroyImage(annotate_image);
640 annotate_image=rotate_image;
644 normalized_degrees=annotate_info->degrees;
645 while (normalized_degrees < -45.0)
646 normalized_degrees+=360.0;
647 for (rotations=0; normalized_degrees > 45.0; rotations++)
648 normalized_degrees-=90.0;
649 switch (rotations % 4)
659 x-=(int) annotate_image->columns/2;
660 y+=(
int) annotate_image->columns/2;
668 x=x-(int) annotate_image->columns;
676 x=x-(int) annotate_image->columns/2;
677 y=y-(
int) (annotate_image->rows-(annotate_image->columns/2));
685 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
687 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
688 OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y);
690 annotate_image=DestroyImage(annotate_image);
727 static char **FontToList(
char *font)
742 if (font == (
char *) NULL)
743 return((
char **) NULL);
748 for (p=font; *p !=
'\0'; p++)
749 if ((*p ==
':') || (*p ==
';') || (*p ==
','))
751 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts+1UL,
sizeof(*fontlist));
752 if (fontlist == (
char **) NULL)
753 ThrowXWindowFatalException(ResourceLimitError,
"MemoryAllocationFailed",
756 for (i=0; i < (int) fonts; i++)
758 for (q=p; *q !=
'\0'; q++)
759 if ((*q ==
':') || (*q ==
';') || (*q ==
','))
761 fontlist[i]=(
char *) AcquireQuantumMemory((
size_t) (q-p)+1UL,
762 sizeof(*fontlist[i]));
763 if (fontlist[i] == (
char *) NULL)
764 ThrowXWindowFatalException(ResourceLimitError,
"MemoryAllocationFailed",
766 (void) CopyMagickString(fontlist[i],p,(
size_t) (q-p+1));
769 fontlist[i]=(
char *) NULL;
773 MagickExport XFontStruct *XBestFont(Display *display,
774 const XResourceInfo *resource_info,
const MagickBooleanType text_font)
779 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
780 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
781 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
782 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
783 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
784 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
791 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
792 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
793 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
807 font_info=(XFontStruct *) NULL;
808 font_name=resource_info->font;
809 if (text_font != MagickFalse)
810 font_name=resource_info->text_font;
811 if ((font_name != (
char *) NULL) && (*font_name !=
'\0'))
822 fontlist=FontToList(font_name);
823 if (fontlist != (
char **) NULL)
825 for (i=0; fontlist[i] != (
char *) NULL; i++)
827 if (font_info == (XFontStruct *) NULL)
828 font_info=XLoadQueryFont(display,fontlist[i]);
829 fontlist[i]=DestroyString(fontlist[i]);
831 fontlist=(
char **) RelinquishMagickMemory(fontlist);
833 if (font_info == (XFontStruct *) NULL)
834 ThrowXWindowException(XServerError,
"UnableToLoadFont",font_name);
840 if (text_font != MagickFalse)
842 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
844 while (*p != (
char *) NULL)
846 if (font_info != (XFontStruct *) NULL)
848 font_info=XLoadQueryFont(display,(
char *) *p);
881 MagickExport
void XBestIconSize(Display *display,XWindowInfo *window,
907 assert(display != (Display *) NULL);
908 assert(window != (XWindowInfo *) NULL);
909 assert(image != (
Image *) NULL);
910 if (IsEventLogging() != MagickFalse)
911 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
912 window->width=MaxIconSize;
913 window->height=MaxIconSize;
914 icon_size=(XIconSize *) NULL;
916 root_window=XRootWindow(display,window->screen);
917 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
918 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
920 if (icon_size == (XIconSize *) NULL)
925 icon_size=XAllocIconSize();
926 if (icon_size == (XIconSize *) NULL)
927 ThrowXWindowFatalException(ResourceLimitError,
928 "MemoryAllocationFailed",image->filename);
929 icon_size->min_width=1;
930 icon_size->max_width=MaxIconSize;
931 icon_size->min_height=1;
932 icon_size->max_height=MaxIconSize;
933 icon_size->width_inc=1;
934 icon_size->height_inc=1;
939 width=(
unsigned int) image->columns;
940 height=(
unsigned int) image->rows;
942 if (window->crop_geometry)
943 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
947 scale_factor=(MagickRealType) icon_size->max_width/width;
948 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
949 scale_factor=(MagickRealType) icon_size->max_height/height;
950 icon_width=(
unsigned int) icon_size->min_width;
951 while ((
int) icon_width < icon_size->max_width)
953 if (icon_width >= (
unsigned int) (scale_factor*width+0.5))
955 icon_width+=icon_size->width_inc;
957 icon_height=(
unsigned int) icon_size->min_height;
958 while ((
int) icon_height < icon_size->max_height)
960 if (icon_height >= (
unsigned int) (scale_factor*height+0.5))
962 icon_height+=icon_size->height_inc;
964 (void) XFree((
void *) icon_size);
965 window->width=icon_width;
966 window->height=icon_height;
1007 MagickExport
void XBestPixel(Display *display,
const Colormap colormap,
1008 XColor *colors,
unsigned int number_colors,XColor *color)
1032 assert(display != (Display *) NULL);
1033 assert(color != (XColor *) NULL);
1034 if (IsEventLogging() != MagickFalse)
1035 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1036 status=XAllocColor(display,colormap,color);
1037 if (status != False)
1039 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1040 if (query_server != MagickFalse)
1045 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
1046 if (colors == (XColor *) NULL)
1047 ThrowXWindowFatalException(ResourceLimitError,
1048 "MemoryAllocationFailed",
"...");
1049 for (i=0; i < (int) number_colors; i++)
1050 colors[i].pixel=(
size_t) i;
1051 if (number_colors > 256)
1053 (void) XQueryColors(display,colormap,colors,(
int) number_colors);
1055 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1058 for (i=0; i < (int) number_colors; i++)
1060 pixel.red=colors[i].red-(MagickRealType) color->red;
1061 distance=pixel.red*pixel.red;
1062 if (distance > min_distance)
1064 pixel.green=colors[i].green-(MagickRealType) color->green;
1065 distance+=pixel.green*pixel.green;
1066 if (distance > min_distance)
1068 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1069 distance+=pixel.blue*pixel.blue;
1070 if (distance > min_distance)
1072 min_distance=distance;
1073 color->pixel=colors[i].pixel;
1076 (void) XAllocColor(display,colormap,&colors[j]);
1077 if (query_server != MagickFalse)
1078 colors=(XColor *) RelinquishMagickMemory(colors);
1126 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1127 XStandardColormap *map_info,XResourceInfo *resource_info)
1129 #define MaxStandardColormaps 7
1130 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1131 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1132 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1133 (unsigned long) visual_info->colormap_size),1UL << visual_info->depth)
1161 assert(display != (Display *) NULL);
1162 assert(map_info != (XStandardColormap *) NULL);
1163 assert(resource_info != (XResourceInfo *) NULL);
1164 if (IsEventLogging() != MagickFalse)
1165 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1166 map_type=resource_info->map_type;
1167 visual_type=resource_info->visual_type;
1168 visual_mask=VisualScreenMask;
1169 visual_template.screen=XDefaultScreen(display);
1170 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1172 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1173 if (resource_info->colors <= (one << (
size_t) visual_template.depth))
1174 visual_mask|=VisualDepthMask;
1175 if (visual_type != (
char *) NULL)
1180 if (LocaleCompare(
"staticgray",visual_type) == 0)
1182 visual_mask|=VisualClassMask;
1183 visual_template.klass=StaticGray;
1186 if (LocaleCompare(
"grayscale",visual_type) == 0)
1188 visual_mask|=VisualClassMask;
1189 visual_template.klass=GrayScale;
1192 if (LocaleCompare(
"staticcolor",visual_type) == 0)
1194 visual_mask|=VisualClassMask;
1195 visual_template.klass=StaticColor;
1198 if (LocaleCompare(
"pseudocolor",visual_type) == 0)
1200 visual_mask|=VisualClassMask;
1201 visual_template.klass=PseudoColor;
1204 if (LocaleCompare(
"truecolor",visual_type) == 0)
1206 visual_mask|=VisualClassMask;
1207 visual_template.klass=TrueColor;
1210 if (LocaleCompare(
"directcolor",visual_type) == 0)
1212 visual_mask|=VisualClassMask;
1213 visual_template.klass=DirectColor;
1216 if (LocaleCompare(
"default",visual_type) == 0)
1218 visual_mask|=VisualIDMask;
1219 visual_template.visualid=XVisualIDFromVisual(
1220 XDefaultVisual(display,XDefaultScreen(display)));
1223 if (isdigit((
int) ((
unsigned char) *visual_type)) != 0)
1225 visual_mask|=VisualIDMask;
1226 visual_template.visualid=
1227 strtol(visual_type,(
char **) NULL,0);
1230 ThrowXWindowException(XServerError,
1231 "UnrecognizedVisualSpecifier",visual_type);
1237 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1239 visual_mask=VisualScreenMask | VisualIDMask;
1240 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1245 ThrowXWindowException(XServerWarning,
"UnableToGetVisual",visual_type);
1246 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1247 XDefaultScreen(display)));
1248 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1250 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1251 return((XVisualInfo *) NULL);
1252 ThrowXWindowException(XServerWarning,
"UsingDefaultVisual",
1253 XVisualClassName(visual_list->klass));
1255 resource_info->color_recovery=MagickFalse;
1256 if ((map_info != (XStandardColormap *) NULL) && (map_type != (
char *) NULL))
1262 map_name[MaxTextExtent];
1280 map_list=(XStandardColormap *) NULL;
1281 root_window=XRootWindow(display,XDefaultScreen(display));
1284 if (LocaleCompare(map_type,
"list") != 0)
1289 (void) FormatLocaleString((
char *) map_name,MaxTextExtent,
1290 "RGB_%s_MAP",map_type);
1291 LocaleUpper(map_name);
1292 map_property=XInternAtom(display,(
char *) map_name,MagickTrue);
1293 if (map_property != (Atom) NULL)
1294 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1300 *colormap[MaxStandardColormaps]=
1302 "_HP_RGB_SMOOTH_MAP_LIST",
1314 for (i=0; i < MaxStandardColormaps; i++)
1316 map_property=XInternAtom(display,(
char *) colormap[i],MagickTrue);
1317 if (map_property == (Atom) NULL)
1319 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1321 if (status != False)
1324 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1326 if (status == False)
1327 ThrowXWindowFatalException(XServerError,
"UnableToGetStandardColormap",
1332 *map_info=map_list[0];
1333 #if !defined(PRE_R4_ICCCM)
1334 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1335 for (i=0; i < number_maps; i++)
1336 for (j=0; j < number_visuals; j++)
1337 if (map_list[i].visualid ==
1338 XVisualIDFromVisual(visual_list[j].visual))
1340 *map_info=map_list[i];
1341 visual_template.visualid=XVisualIDFromVisual(
1342 visual_list[j].visual);
1345 if (map_info->visualid != visual_template.visualid)
1346 ThrowXWindowFatalException(XServerError,
1347 "UnableToMatchVisualToStandardColormap",map_type);
1349 if (map_info->colormap == (Colormap) NULL)
1350 ThrowXWindowFatalException(XServerError,
1351 "StandardColormapIsNotInitialized",map_type);
1352 (void) XFree((
void *) map_list);
1356 static const unsigned int
1373 visual_info=visual_list;
1375 for (i=1; i < number_visuals; i++)
1378 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1381 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1382 if (rank[p->klass] > rank[visual_info->klass])
1385 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1387 (void) XFree((
void *) visual_list);
1391 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1393 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1394 return((XVisualInfo *) NULL);
1395 return(visual_info);
1425 MagickExport
int XCheckDefineCursor(Display *display,Window window,
1428 assert(display != (Display *) NULL);
1429 if (IsEventLogging() != MagickFalse)
1430 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1431 if (window == XRootWindow(display,XDefaultScreen(display)))
1433 return(XDefineCursor(display,window,cursor));
1462 MagickExport
void XCheckRefreshWindows(Display *display,XWindows *windows)
1470 assert(display != (Display *) NULL);
1471 assert(windows != (XWindows *) NULL);
1472 if (IsEventLogging() != MagickFalse)
1473 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1474 XDelay(display,SuspendTime);
1475 id=windows->command.id;
1476 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1477 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1478 id=windows->image.id;
1479 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1480 XRefreshWindow(display,&windows->image,&event);
1481 XDelay(display,SuspendTime << 1);
1482 id=windows->command.id;
1483 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1484 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1485 id=windows->image.id;
1486 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1487 XRefreshWindow(display,&windows->image,&event);
1522 MagickExport
void XClientMessage(Display *display,
const Window window,
1523 const Atom protocol,
const Atom reason,
const Time timestamp)
1528 assert(display != (Display *) NULL);
1529 (void) memset(&client_event,0,
sizeof(client_event));
1530 client_event.type=ClientMessage;
1531 client_event.window=window;
1532 client_event.message_type=protocol;
1533 client_event.format=32;
1534 client_event.data.l[0]=(long) reason;
1535 client_event.data.l[1]=(long) timestamp;
1536 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1570 static Window XClientWindow(Display *display,Window target_window)
1592 assert(display != (Display *) NULL);
1593 if (IsEventLogging() != MagickFalse)
1594 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1595 state=XInternAtom(display,
"WM_STATE",MagickTrue);
1596 if (state == (Atom) NULL)
1597 return(target_window);
1599 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1600 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1601 if ((status == Success) && (type != (Atom) NULL))
1602 return(target_window);
1603 client_window=XWindowByProperty(display,target_window,state);
1604 if (client_window == (Window) NULL)
1605 return(target_window);
1606 return(client_window);
1627 MagickExport
void XComponentTerminus(
void)
1629 DestroyXResources();
1662 MagickExport
void XConfigureImageColormap(Display *display,
1663 XResourceInfo *resource_info,XWindows *windows,
Image *image)
1671 XSetCursorState(display,windows,MagickTrue);
1672 XCheckRefreshWindows(display,windows);
1673 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1674 windows->map_info,windows->pixel_info);
1675 colormap=windows->map_info->colormap;
1676 (void) XSetWindowColormap(display,windows->image.id,colormap);
1677 (void) XSetWindowColormap(display,windows->command.id,colormap);
1678 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1679 if (windows->magnify.mapped != MagickFalse)
1680 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1681 if (windows->pan.mapped != MagickFalse)
1682 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1683 XSetCursorState(display,windows,MagickFalse);
1684 XClientMessage(display,windows->image.id,windows->im_protocols,
1685 windows->im_update_colormap,CurrentTime);
1714 MagickExport
void XConstrainWindowPosition(Display *display,
1715 XWindowInfo *window_info)
1720 assert(display != (Display *) NULL);
1721 assert(window_info != (XWindowInfo *) NULL);
1722 if (IsEventLogging() != MagickFalse)
1723 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1724 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1725 if (window_info->x < 0)
1728 if (window_info->x > (
int) limit)
1729 window_info->x=(int) limit;
1730 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1731 if (window_info->y < 0)
1734 if (window_info->y > limit)
1735 window_info->y=limit;
1765 MagickExport
void XDelay(Display *display,
const size_t milliseconds)
1767 assert(display != (Display *) NULL);
1768 (void) XFlush(display);
1769 MagickDelay(milliseconds);
1795 MagickExport
void XDestroyResourceInfo(XResourceInfo *resource_info)
1797 if (resource_info->image_geometry != (
char *) NULL)
1798 resource_info->image_geometry=(
char *)
1799 RelinquishMagickMemory(resource_info->image_geometry);
1800 if (resource_info->quantize_info != (
QuantizeInfo *) NULL)
1801 resource_info->quantize_info=DestroyQuantizeInfo(
1802 resource_info->quantize_info);
1803 if (resource_info->client_name != (
char *) NULL)
1804 resource_info->client_name=(
char *)
1805 RelinquishMagickMemory(resource_info->client_name);
1806 if (resource_info->name != (
char *) NULL)
1807 resource_info->name=DestroyString(resource_info->name);
1808 (void) memset(resource_info,0,
sizeof(*resource_info));
1837 MagickExport
void XDestroyWindowColors(Display *display,Window window)
1859 assert(display != (Display *) NULL);
1860 if (IsEventLogging() != MagickFalse)
1861 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1862 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
1863 if (property == (Atom) NULL)
1864 ThrowXWindowFatalException(XServerError,
"UnableToCreateProperty",
1866 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1867 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1868 if (status != Success)
1870 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1872 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1873 (void) XDeleteProperty(display,window,property);
1876 (void) XFree((
void *) data);
1912 MagickExport
void XDisplayImageInfo(Display *display,
1913 const XResourceInfo *resource_info,XWindows *windows,
Image *undo_image,
1917 filename[MaxTextExtent],
1942 assert(display != (Display *) NULL);
1943 assert(resource_info != (XResourceInfo *) NULL);
1944 assert(windows != (XWindows *) NULL);
1945 assert(image != (
Image *) NULL);
1946 if (IsEventLogging() != MagickFalse)
1947 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1949 unique_file=AcquireUniqueFileResource(filename);
1950 if (unique_file != -1)
1951 file=fdopen(unique_file,
"w");
1952 if ((unique_file == -1) || (file == (FILE *) NULL))
1954 XNoticeWidget(display,windows,
"Unable to display image info",filename);
1957 if (resource_info->gamma_correct != MagickFalse)
1958 if (resource_info->display_gamma != (
char *) NULL)
1959 (void) FormatLocaleFile(file,
"Display\n gamma: %s\n\n",
1960 resource_info->display_gamma);
1964 (void) FormatLocaleFile(file,
"X\n visual: %s\n",
1965 XVisualClassName((
int) windows->image.storage_class));
1966 (void) FormatLocaleFile(file,
" depth: %d\n",windows->image.ximage->depth);
1967 if (windows->visual_info->colormap_size != 0)
1968 (void) FormatLocaleFile(file,
" colormap size: %d\n",
1969 windows->visual_info->colormap_size);
1970 if (resource_info->colormap== SharedColormap)
1971 (void) FormatLocaleFile(file,
" colormap type: Shared\n");
1973 (
void) FormatLocaleFile(file,
" colormap type: Private\n");
1974 (void) FormatLocaleFile(file,
" geometry: %dx%d\n",
1975 windows->image.ximage->width,windows->image.ximage->height);
1976 if (windows->image.crop_geometry != (
char *) NULL)
1977 (
void) FormatLocaleFile(file,
" crop geometry: %s\n",
1978 windows->image.crop_geometry);
1979 if (windows->image.pixmap == (Pixmap) NULL)
1980 (void) FormatLocaleFile(file,
" type: X Image\n");
1982 (
void) FormatLocaleFile(file,
" type: Pixmap\n");
1983 if (windows->image.shape != MagickFalse)
1984 (void) FormatLocaleFile(file,
" non-rectangular shape: True\n");
1986 (
void) FormatLocaleFile(file,
" non-rectangular shape: False\n");
1987 if (windows->image.shared_memory != MagickFalse)
1988 (void) FormatLocaleFile(file,
" shared memory: True\n");
1990 (
void) FormatLocaleFile(file,
" shared memory: False\n");
1991 (void) FormatLocaleFile(file,
"\n");
1992 if (resource_info->font != (
char *) NULL)
1993 (
void) FormatLocaleFile(file,
"Font: %s\n\n",resource_info->font);
1994 if (resource_info->text_font != (
char *) NULL)
1995 (void) FormatLocaleFile(file,
"Text font: %s\n\n",resource_info->text_font);
2000 for (levels=0; undo_image != (
Image *) NULL; levels++)
2002 number_pixels=undo_image->list->columns*undo_image->list->rows;
2004 undo_image=GetPreviousImageInList(undo_image);
2006 (void) FormatLocaleFile(file,
"Undo Edit Cache\n levels: %u\n",levels);
2007 (void) FormatLocaleFile(file,
" bytes: %.20gmb\n",(
double)
2008 ((bytes+(1 << 19)) >> 20));
2009 (void) FormatLocaleFile(file,
" limit: %.20gmb\n\n",(
double)
2010 resource_info->undo_cache);
2014 (void) IdentifyImage(image,file,MagickTrue);
2015 (void) fclose(file);
2016 text=FileToString(filename,~0UL,&image->exception);
2017 (void) RelinquishUniqueFileResource(filename);
2018 if (text == (
char *) NULL)
2020 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
2021 "UnableToDisplayImageInfo");
2024 textlist=StringToList(text);
2025 if (textlist != (
char **) NULL)
2028 title[MaxTextExtent];
2033 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2034 (void) FormatLocaleString(title,MaxTextExtent,
"Image Info: %s",
2036 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2037 (
char const **) textlist);
2038 for (i=0; textlist[i] != (
char *) NULL; i++)
2039 textlist[i]=DestroyString(textlist[i]);
2040 textlist=(
char **) RelinquishMagickMemory(textlist);
2042 text=DestroyString(text);
2073 static void XDitherImage(
Image *image,XImage *ximage)
2075 static const short int
2078 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2079 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2081 dither_green[2][16]=
2083 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2084 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2088 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2089 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2127 for (i=0; i < 2; i++)
2128 for (j=0; j < 16; j++)
2130 red_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2132 green_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2133 sizeof(*green_map));
2134 blue_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2140 for (i=0; i < 2; i++)
2141 for (j=0; j < 16; j++)
2142 for (x=0; x < 256; x++)
2147 value+=dither_red[i][j];
2148 red_map[i][j][x]=(
unsigned char)
2149 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2153 value+=dither_green[i][j];
2154 green_map[i][j][x]=(
unsigned char)
2155 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2159 value+=((size_t) dither_blue[i][j] << 1);
2160 blue_map[i][j][x]=(
unsigned char)
2161 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2166 scanline_pad=(
unsigned int) (ximage->bytes_per_line-
2167 ((
size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2171 image_view=AcquireVirtualCacheView(image,&image->exception);
2172 for (y=0; y < (int) image->rows; y++)
2174 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2178 for (x=0; x < (int) image->columns; x++)
2180 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(
int)
2181 ScaleQuantumToChar(GetPixelRed(p))] << 8));
2182 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(
int)
2183 ScaleQuantumToChar(GetPixelGreen(p))] << 8));
2184 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(
int)
2185 ScaleQuantumToChar(GetPixelBlue(p))] << 8));
2186 pixel=(size_t) (((
size_t) color.red & 0xe0) |
2187 (((size_t) color.green & 0xe0) >> 3) |
2188 (((
size_t) color.blue & 0xc0) >> 6));
2200 image_view=DestroyCacheView(image_view);
2204 for (i=0; i < 2; i++)
2205 for (j=0; j < 16; j++)
2207 green_map[i][j]=(
unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2208 blue_map[i][j]=(
unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2209 red_map[i][j]=(
unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2242 MagickExport MagickBooleanType XDrawImage(Display *display,
2243 const XPixelInfo *pixel,XDrawInfo *draw_info,
Image *image)
2284 assert(display != (Display *) NULL);
2285 assert(pixel != (XPixelInfo *) NULL);
2286 assert(draw_info != (XDrawInfo *) NULL);
2287 assert(image != (
Image *) NULL);
2288 if (IsEventLogging() != MagickFalse)
2289 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2293 root_window=XRootWindow(display,XDefaultScreen(display));
2294 depth=(
unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2295 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2296 draw_info->height,depth);
2297 if (draw_pixmap == (Pixmap) NULL)
2298 return(MagickFalse);
2302 context_values.background=(size_t) (~0);
2303 context_values.foreground=0;
2304 context_values.line_width=(int) draw_info->line_width;
2305 draw_context=XCreateGC(display,root_window,(
size_t)
2306 (GCBackground | GCForeground | GCLineWidth),&context_values);
2307 if (draw_context == (GC) NULL)
2308 return(MagickFalse);
2312 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2317 (void) XSetBackground(display,draw_context,0);
2318 (void) XSetForeground(display,draw_context,(
size_t) (~0));
2319 if (draw_info->stipple != (Pixmap) NULL)
2321 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2322 (void) XSetStipple(display,draw_context,draw_info->stipple);
2324 switch (draw_info->element)
2329 (void) XDrawLines(display,draw_pixmap,draw_context,
2330 draw_info->coordinate_info,(
int) draw_info->number_coordinates,
2336 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2337 draw_info->line_info.y1,draw_info->line_info.x2,
2338 draw_info->line_info.y2);
2341 case RectangleElement:
2343 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2344 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2345 (
unsigned int) draw_info->rectangle_info.width,
2346 (
unsigned int) draw_info->rectangle_info.height);
2349 case FillRectangleElement:
2351 (void) XFillRectangle(display,draw_pixmap,draw_context,
2352 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2353 (
unsigned int) draw_info->rectangle_info.width,
2354 (
unsigned int) draw_info->rectangle_info.height);
2358 case EllipseElement:
2360 (void) XDrawArc(display,draw_pixmap,draw_context,
2361 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2362 (
unsigned int) draw_info->rectangle_info.width,
2363 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2366 case FillCircleElement:
2367 case FillEllipseElement:
2369 (void) XFillArc(display,draw_pixmap,draw_context,
2370 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2371 (
unsigned int) draw_info->rectangle_info.width,
2372 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2375 case PolygonElement:
2380 coordinate_info=draw_info->coordinate_info;
2381 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2382 (
int) draw_info->number_coordinates,CoordModeOrigin);
2383 (void) XDrawLine(display,draw_pixmap,draw_context,
2384 coordinate_info[draw_info->number_coordinates-1].x,
2385 coordinate_info[draw_info->number_coordinates-1].y,
2386 coordinate_info[0].x,coordinate_info[0].y);
2389 case FillPolygonElement:
2391 (void) XFillPolygon(display,draw_pixmap,draw_context,
2392 draw_info->coordinate_info,(
int) draw_info->number_coordinates,Complex,
2397 (void) XFreeGC(display,draw_context);
2401 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2402 draw_info->height,AllPlanes,ZPixmap);
2403 if (draw_ximage == (XImage *) NULL)
2404 return(MagickFalse);
2405 (void) XFreePixmap(display,draw_pixmap);
2409 draw_image=AcquireImage((
ImageInfo *) NULL);
2410 if (draw_image == (
Image *) NULL)
2411 return(MagickFalse);
2412 draw_image->columns=draw_info->width;
2413 draw_image->rows=draw_info->height;
2417 width=(
unsigned int) image->columns;
2418 height=(
unsigned int) image->rows;
2421 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2422 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
2423 &draw_image->background_color,&image->exception);
2424 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2425 return(MagickFalse);
2426 draw_image->matte=MagickTrue;
2427 exception=(&image->exception);
2428 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2429 for (y=0; y < (int) draw_image->rows; y++)
2437 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2441 for (x=0; x < (int) draw_image->columns; x++)
2443 if (XGetPixel(draw_ximage,x,y) == 0)
2448 *q=draw_image->background_color;
2449 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2450 TransparentOpacity : OpaqueOpacity);
2457 SetPixelRed(q,ScaleShortToQuantum(pixel->pen_color.red));
2458 SetPixelGreen(q,ScaleShortToQuantum(pixel->pen_color.green));
2459 SetPixelBlue(q,ScaleShortToQuantum(pixel->pen_color.blue));
2460 SetPixelOpacity(q,(Quantum) (draw_info->stencil ==
2461 OpaqueStencil ? OpaqueOpacity : TransparentOpacity));
2465 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2468 draw_view=DestroyCacheView(draw_view);
2469 XDestroyImage(draw_ximage);
2473 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2474 if ((width != (
unsigned int) draw_image->columns) ||
2475 (height != (
unsigned int) draw_image->rows))
2478 image_geometry[MaxTextExtent];
2483 (void) FormatLocaleString(image_geometry,MaxTextExtent,
"%ux%u",
2485 (void) TransformImage(&draw_image,(
char *) NULL,image_geometry);
2487 if (draw_info->degrees != 0.0)
2501 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2502 if (rotate_image == (
Image *) NULL)
2503 return(MagickFalse);
2504 draw_image=DestroyImage(draw_image);
2505 draw_image=rotate_image;
2509 normalized_degrees=draw_info->degrees;
2510 while (normalized_degrees < -45.0)
2511 normalized_degrees+=360.0;
2512 for (rotations=0; normalized_degrees > 45.0; rotations++)
2513 normalized_degrees-=90.0;
2514 switch (rotations % 4)
2524 x=x-(int) draw_image->columns/2;
2525 y=y+(
int) draw_image->columns/2;
2533 x=x-(int) draw_image->columns;
2541 x=x-(int) draw_image->columns/2;
2542 y=y-(
int) (draw_image->rows-(draw_image->columns/2));
2550 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2551 for (y=0; y < (int) draw_image->rows; y++)
2559 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2563 for (x=0; x < (int) draw_image->columns; x++)
2565 if (q->opacity != (Quantum) TransparentOpacity)
2566 SetPixelOpacity(q,OpaqueOpacity);
2569 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2572 draw_view=DestroyCacheView(draw_view);
2573 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2574 if (draw_info->stencil == TransparentStencil)
2575 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
2580 (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2584 draw_image=DestroyImage(draw_image);
2617 #if defined(__cplusplus) || defined(c_plusplus)
2621 MagickExport
int XError(Display *display,XErrorEvent *error)
2623 assert(display != (Display *) NULL);
2624 assert(error != (XErrorEvent *) NULL);
2625 if (IsEventLogging() != MagickFalse)
2626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2628 xerror_alert=MagickTrue;
2629 switch (error->request_code)
2633 if ((
int) error->error_code == BadDrawable)
2634 return(MagickFalse);
2637 case X_GetWindowAttributes:
2640 if ((
int) error->error_code == BadWindow)
2641 return(MagickFalse);
2646 if ((
int) error->error_code == BadValue)
2647 return(MagickFalse);
2654 #if defined(__cplusplus) || defined(c_plusplus)
2698 MagickExport
void XFreeResources(Display *display,XVisualInfo *visual_info,
2699 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2700 XResourceInfo *resource_info,XWindowInfo *window_info)
2702 assert(display != (Display *) NULL);
2703 assert(resource_info != (XResourceInfo *) NULL);
2704 if (IsEventLogging() != MagickFalse)
2705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2706 if (window_info != (XWindowInfo *) NULL)
2711 if (window_info->ximage != (XImage *) NULL)
2712 XDestroyImage(window_info->ximage);
2713 if (window_info->id != (Window) NULL)
2718 if (window_info->id != XRootWindow(display,visual_info->screen))
2719 (
void) XDestroyWindow(display,window_info->id);
2720 if (window_info->annotate_context != (GC) NULL)
2721 (void) XFreeGC(display,window_info->annotate_context);
2722 if (window_info->highlight_context != (GC) NULL)
2723 (
void) XFreeGC(display,window_info->highlight_context);
2724 if (window_info->widget_context != (GC) NULL)
2725 (void) XFreeGC(display,window_info->widget_context);
2726 if (window_info->cursor != (Cursor) NULL)
2727 (
void) XFreeCursor(display,window_info->cursor);
2728 window_info->cursor=(Cursor) NULL;
2729 if (window_info->busy_cursor != (Cursor) NULL)
2730 (
void) XFreeCursor(display,window_info->busy_cursor);
2731 window_info->busy_cursor=(Cursor) NULL;
2737 if (font_info != (XFontStruct *) NULL)
2739 (void) XFreeFont(display,font_info);
2740 font_info=(XFontStruct *) NULL;
2742 if (map_info != (XStandardColormap *) NULL)
2747 if (resource_info->map_type == (
char *) NULL)
2748 (
void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2749 (void) XFree((
void *) map_info);
2754 if (visual_info != (XVisualInfo *) NULL)
2755 (
void) XFree((
void *) visual_info);
2756 if (resource_info->close_server != MagickFalse)
2757 (void) XCloseDisplay(display);
2793 MagickExport
void XFreeStandardColormap(Display *display,
2794 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2799 assert(display != (Display *) NULL);
2800 assert(visual_info != (XVisualInfo *) NULL);
2801 assert(map_info != (XStandardColormap *) NULL);
2802 if (IsEventLogging() != MagickFalse)
2803 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2804 (void) XFlush(display);
2805 if (map_info->colormap != (Colormap) NULL)
2807 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2808 (
void) XFreeColormap(display,map_info->colormap);
2810 if (pixel != (XPixelInfo *) NULL)
2811 if ((visual_info->klass != TrueColor) &&
2812 (visual_info->klass != DirectColor))
2813 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2814 (
int) pixel->colors,0);
2816 map_info->colormap=(Colormap) NULL;
2817 if (pixel != (XPixelInfo *) NULL)
2819 if (pixel->pixels != (
unsigned long *) NULL)
2820 pixel->pixels=(
unsigned long *) RelinquishMagickMemory(pixel->pixels);
2821 pixel->pixels=(
unsigned long *) NULL;
2847 MagickExport
void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2852 assert(annotate_info != (XAnnotateInfo *) NULL);
2853 if (IsEventLogging() != MagickFalse)
2854 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2857 annotate_info->width=0;
2858 annotate_info->height=0;
2859 annotate_info->stencil=ForegroundStencil;
2860 annotate_info->degrees=0.0;
2861 annotate_info->font_info=(XFontStruct *) NULL;
2862 annotate_info->text=(
char *) NULL;
2863 *annotate_info->geometry=
'\0';
2864 annotate_info->previous=(XAnnotateInfo *) NULL;
2865 annotate_info->next=(XAnnotateInfo *) NULL;
2866 (void) XSupportsLocale();
2867 (void) XSetLocaleModifiers(
"");
2898 MagickExport
void XGetMapInfo(
const XVisualInfo *visual_info,
2899 const Colormap colormap,XStandardColormap *map_info)
2904 assert(visual_info != (XVisualInfo *) NULL);
2905 assert(map_info != (XStandardColormap *) NULL);
2906 if (IsEventLogging() != MagickFalse)
2907 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2908 map_info->colormap=colormap;
2909 map_info->red_max=visual_info->red_mask;
2910 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2911 if (map_info->red_max != 0)
2912 while ((map_info->red_max & 0x01) == 0)
2914 map_info->red_max>>=1;
2915 map_info->red_mult<<=1;
2917 map_info->green_max=visual_info->green_mask;
2918 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2919 if (map_info->green_max != 0)
2920 while ((map_info->green_max & 0x01) == 0)
2922 map_info->green_max>>=1;
2923 map_info->green_mult<<=1;
2925 map_info->blue_max=visual_info->blue_mask;
2926 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2927 if (map_info->blue_max != 0)
2928 while ((map_info->blue_max & 0x01) == 0)
2930 map_info->blue_max>>=1;
2931 map_info->blue_mult<<=1;
2933 map_info->base_pixel=0;
2974 MagickExport
void XGetPixelPacket(Display *display,
2975 const XVisualInfo *visual_info,
const XStandardColormap *map_info,
2976 const XResourceInfo *resource_info,
Image *image,XPixelInfo *pixel)
2979 *PenColors[MaxNumberPens]=
3009 assert(display != (Display *) NULL);
3010 assert(visual_info != (XVisualInfo *) NULL);
3011 assert(map_info != (XStandardColormap *) NULL);
3012 assert(resource_info != (XResourceInfo *) NULL);
3013 assert(pixel != (XPixelInfo *) NULL);
3014 if (IsEventLogging() != MagickFalse)
3015 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3017 if (image != (
Image *) NULL)
3018 if (image->storage_class == PseudoClass)
3019 pixel->colors=(ssize_t) image->colors;
3020 packets=(
unsigned int)
3021 MagickMax((
int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3022 if (pixel->pixels != (
unsigned long *) NULL)
3023 pixel->pixels=(
unsigned long *) RelinquishMagickMemory(pixel->pixels);
3024 pixel->pixels=(
unsigned long *) AcquireQuantumMemory(packets,
3025 sizeof(*pixel->pixels));
3026 if (pixel->pixels == (
unsigned long *) NULL)
3027 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToGetPixelInfo",
3032 colormap=map_info->colormap;
3033 (void) XParseColor(display,colormap,(
char *) ForegroundColor,
3034 &pixel->foreground_color);
3035 status=XParseColor(display,colormap,resource_info->foreground_color,
3036 &pixel->foreground_color);
3037 if (status == False)
3038 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3039 resource_info->foreground_color);
3040 pixel->foreground_color.pixel=
3041 XStandardPixel(map_info,&pixel->foreground_color);
3042 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3046 (void) XParseColor(display,colormap,
"#d6d6d6d6d6d6",&pixel->background_color);
3047 status=XParseColor(display,colormap,resource_info->background_color,
3048 &pixel->background_color);
3049 if (status == False)
3050 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3051 resource_info->background_color);
3052 pixel->background_color.pixel=
3053 XStandardPixel(map_info,&pixel->background_color);
3054 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3058 (void) XParseColor(display,colormap,(
char *) BorderColor,
3059 &pixel->border_color);
3060 status=XParseColor(display,colormap,resource_info->border_color,
3061 &pixel->border_color);
3062 if (status == False)
3063 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3064 resource_info->border_color);
3065 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3066 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3070 pixel->matte_color=pixel->background_color;
3071 if (resource_info->matte_color != (
char *) NULL)
3076 status=XParseColor(display,colormap,resource_info->matte_color,
3077 &pixel->matte_color);
3078 if (status == False)
3079 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3080 resource_info->matte_color);
3081 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3082 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3087 pixel->highlight_color.red=(
unsigned short) (((MagickRealType)
3088 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3089 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3090 pixel->highlight_color.green=(
unsigned short) (((MagickRealType)
3091 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3092 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3093 pixel->highlight_color.blue=(
unsigned short) (((MagickRealType)
3094 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3095 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3096 pixel->highlight_color.pixel=
3097 XStandardPixel(map_info,&pixel->highlight_color);
3098 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3102 pixel->shadow_color.red=(
unsigned short) (((MagickRealType)
3103 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3104 pixel->shadow_color.green=(
unsigned short) (((MagickRealType)
3105 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3106 pixel->shadow_color.blue=(
unsigned short) (((MagickRealType)
3107 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3108 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3109 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3113 pixel->depth_color.red=(
unsigned short) (((MagickRealType)
3114 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3115 pixel->depth_color.green=(
unsigned short) (((MagickRealType)
3116 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3117 pixel->depth_color.blue=(
unsigned short) (((MagickRealType)
3118 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3119 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3120 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3124 pixel->trough_color.red=(
unsigned short) (((MagickRealType)
3125 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3126 pixel->trough_color.green=(
unsigned short) (((MagickRealType)
3127 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3128 pixel->trough_color.blue=(
unsigned short) (((MagickRealType)
3129 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3130 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3131 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3135 for (i=0; i < MaxNumberPens; i++)
3137 (void) XParseColor(display,colormap,(
char *) PenColors[i],
3138 &pixel->pen_colors[i]);
3139 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3140 &pixel->pen_colors[i]);
3141 if (status == False)
3142 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3143 resource_info->pen_colors[i]);
3144 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3145 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3147 pixel->box_color=pixel->background_color;
3148 pixel->pen_color=pixel->foreground_color;
3151 if (image != (
Image *) NULL)
3153 if ((resource_info->gamma_correct != MagickFalse) &&
3154 (image->gamma != 0.0))
3165 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3166 if ((flags & RhoValue) != 0)
3167 red_gamma=geometry_info.rho;
3168 green_gamma=red_gamma;
3169 if ((flags & SigmaValue) != 0)
3170 green_gamma=geometry_info.sigma;
3171 blue_gamma=red_gamma;
3172 if ((flags & XiValue) != 0)
3173 blue_gamma=geometry_info.xi;
3174 red_gamma*=image->gamma;
3175 green_gamma*=image->gamma;
3176 blue_gamma*=image->gamma;
3178 if (image->storage_class == PseudoClass)
3183 for (i=0; i < (ssize_t) image->colors; i++)
3184 pixel->pixels[i]=XGammaPixel(map_info,image->colormap+i);
3185 for (i=0; i < MaxNumberPens; i++)
3186 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3187 pixel->colors+=MaxNumberPens;
3226 MagickExport
char *XGetResourceClass(XrmDatabase database,
3227 const char *client_name,
const char *keyword,
char *resource_default)
3230 resource_class[MaxTextExtent],
3231 resource_name[MaxTextExtent];
3242 if (database == (XrmDatabase) NULL)
3243 return(resource_default);
3244 *resource_name=
'\0';
3245 *resource_class=
'\0';
3246 if (keyword != (
char *) NULL)
3255 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.%s",
3256 client_name,keyword);
3257 c=(int) (*client_name);
3258 if ((c >= XK_a) && (c <= XK_z))
3261 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3262 c-=(XK_agrave-XK_Agrave);
3264 if ((c >= XK_oslash) && (c <= XK_thorn))
3265 c-=(XK_oslash-XK_Ooblique);
3267 if ((k >= XK_a) && (k <= XK_z))
3270 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3271 k-=(XK_agrave-XK_Agrave);
3273 if ((k >= XK_oslash) && (k <= XK_thorn))
3274 k-=(XK_oslash-XK_Ooblique);
3275 (void) FormatLocaleString(resource_class,MaxTextExtent,
"%c%s.%c%s",c,
3276 client_name+1,k,keyword+1);
3278 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3280 if (status == False)
3281 return(resource_default);
3282 return(resource_value.addr);
3315 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3316 const char *client_name)
3319 filename[MaxTextExtent];
3331 if (display == (Display *) NULL)
3332 return((XrmDatabase) NULL);
3333 assert(client_name != (
char *) NULL);
3338 (void) XGetDefault(display,(
char *) client_name,
"dummy");
3339 resource_database=XrmGetDatabase(display);
3343 p=client_name+(strlen(client_name)-1);
3344 while ((p > client_name) && (*p !=
'/'))
3348 c=(int) (*client_name);
3349 if ((c >= XK_a) && (c <= XK_z))
3352 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3353 c-=(XK_agrave-XK_Agrave);
3355 if ((c >= XK_oslash) && (c <= XK_thorn))
3356 c-=(XK_oslash-XK_Ooblique);
3357 #if defined(X11_APPLICATION_PATH)
3358 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%c%s",
3359 X11_APPLICATION_PATH,c,client_name+1);
3360 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3362 if (XResourceManagerString(display) != (
char *) NULL)
3367 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3368 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3373 #if defined(X11_PREFERENCES_PATH)
3374 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%src",
3375 X11_PREFERENCES_PATH,client_name);
3376 ExpandFilename(filename);
3377 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3379 return(resource_database);
3413 MagickExport
void XGetResourceInfo(
const ImageInfo *image_info,
3414 XrmDatabase database,
const char *client_name,XResourceInfo *resource_info)
3423 assert(resource_info != (XResourceInfo *) NULL);
3424 if (IsEventLogging() != MagickFalse)
3425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3426 (void) memset(resource_info,0,
sizeof(*resource_info));
3427 resource_info->resource_database=database;
3428 resource_info->image_info=(
ImageInfo *) image_info;
3429 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3430 XMagickProgressMonitor,(
void *) NULL);
3431 resource_info->quantize_info=CloneQuantizeInfo((
QuantizeInfo *) NULL);
3432 resource_info->close_server=MagickTrue;
3433 resource_info->client_name=AcquireString(client_name);
3434 resource_value=XGetResourceClass(database,client_name,
"backdrop",
3436 resource_info->backdrop=IsMagickTrue(resource_value);
3437 resource_info->background_color=XGetResourceInstance(database,client_name,
3438 "background",(
char *)
"#d6d6d6d6d6d6");
3439 resource_info->border_color=XGetResourceInstance(database,client_name,
3440 "borderColor",BorderColor);
3441 resource_value=XGetResourceClass(database,client_name,
"borderWidth",
3443 resource_info->border_width=(
unsigned int) StringToUnsignedLong(
3445 resource_value=XGetResourceClass(database,client_name,
"colormap",
3447 resource_info->colormap=UndefinedColormap;
3448 if (LocaleCompare(
"private",resource_value) == 0)
3449 resource_info->colormap=PrivateColormap;
3450 if (LocaleCompare(
"shared",resource_value) == 0)
3451 resource_info->colormap=SharedColormap;
3452 if (resource_info->colormap == UndefinedColormap)
3453 ThrowXWindowException(OptionError,
"UnrecognizedColormapType",
3455 resource_value=XGetResourceClass(database,client_name,
3456 "colorRecovery",(
char *)
"False");
3457 resource_info->color_recovery=IsMagickTrue(resource_value);
3458 resource_value=XGetResourceClass(database,client_name,
"confirmExit",
3460 resource_info->confirm_exit=IsMagickTrue(resource_value);
3461 resource_value=XGetResourceClass(database,client_name,
"confirmEdit",
3463 resource_info->confirm_edit=IsMagickTrue(resource_value);
3464 resource_value=XGetResourceClass(database,client_name,
"delay",(
char *)
"1");
3465 resource_info->delay=(
unsigned int) StringToUnsignedLong(resource_value);
3466 resource_info->display_gamma=XGetResourceClass(database,client_name,
3467 "displayGamma",(
char *)
"2.2");
3468 resource_value=XGetResourceClass(database,client_name,
"displayWarnings",
3470 resource_info->display_warnings=IsMagickTrue(resource_value);
3471 resource_info->font=XGetResourceClass(database,client_name,
"font",
3473 resource_info->font=XGetResourceClass(database,client_name,
"fontList",
3474 resource_info->font);
3475 resource_info->font_name[0]=XGetResourceClass(database,client_name,
"font1",
3477 resource_info->font_name[1]=XGetResourceClass(database,client_name,
"font2",
3478 (
char *)
"variable");
3479 resource_info->font_name[2]=XGetResourceClass(database,client_name,
"font3",
3481 resource_info->font_name[3]=XGetResourceClass(database,client_name,
"font4",
3483 resource_info->font_name[4]=XGetResourceClass(database,client_name,
"font5",
3484 (
char *)
"7x13bold");
3485 resource_info->font_name[5]=XGetResourceClass(database,client_name,
"font6",
3486 (
char *)
"8x13bold");
3487 resource_info->font_name[6]=XGetResourceClass(database,client_name,
"font7",
3488 (
char *)
"9x15bold");
3489 resource_info->font_name[7]=XGetResourceClass(database,client_name,
"font8",
3491 resource_info->font_name[8]=XGetResourceClass(database,client_name,
"font9",
3493 resource_info->font_name[9]=XGetResourceClass(database,client_name,
"font0",
3495 resource_info->font_name[10]=XGetResourceClass(database,client_name,
"font0",
3497 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3498 "foreground",ForegroundColor);
3499 resource_value=XGetResourceClass(database,client_name,
"gammaCorrect",
3501 resource_info->gamma_correct=IsMagickTrue(resource_value);
3502 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3503 client_name,
"geometry",(
char *) NULL));
3504 resource_value=XGetResourceClass(database,client_name,
"gravity",
3506 resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3507 MagickFalse,resource_value);
3508 directory=getcwd(resource_info->home_directory,MaxTextExtent);
3510 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3511 "iconGeometry",(
char *) NULL);
3512 resource_value=XGetResourceClass(database,client_name,
"iconic",
3514 resource_info->iconic=IsMagickTrue(resource_value);
3515 resource_value=XGetResourceClass(database,client_name,
"immutable",
3516 LocaleCompare(client_name,
"PerlMagick") == 0 ? (
char *)
"True" :
3518 resource_info->immutable=IsMagickTrue(resource_value);
3519 resource_value=XGetResourceClass(database,client_name,
"magnify",
3521 resource_info->magnify=(
unsigned int) StringToUnsignedLong(resource_value);
3522 resource_info->map_type=XGetResourceClass(database,client_name,
"map",
3524 resource_info->matte_color=XGetResourceInstance(database,client_name,
3525 "mattecolor",(
char *) NULL);
3526 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3527 "name",(
char *) NULL));
3528 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,
"pen1",
3530 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,
"pen2",
3532 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,
"pen3",
3534 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,
"pen4",
3536 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,
"pen5",
3538 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,
"pen6",
3540 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,
"pen7",
3541 (
char *)
"magenta");
3542 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,
"pen8",
3544 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,
"pen9",
3546 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,
"pen0",
3548 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,
"pen0",
3550 resource_value=XGetResourceClass(database,client_name,
"pause",(
char *)
"0");
3551 resource_info->pause=(
unsigned int) StringToUnsignedLong(resource_value);
3552 resource_value=XGetResourceClass(database,client_name,
"quantum",(
char *)
"1");
3553 resource_info->quantum=StringToLong(resource_value);
3554 resource_info->text_font=XGetResourceClass(database,client_name,(
char *)
3555 "font",(
char *)
"fixed");
3556 resource_info->text_font=XGetResourceClass(database,client_name,
3557 "textFontList",resource_info->text_font);
3558 resource_info->title=XGetResourceClass(database,client_name,
"title",
3560 resource_value=XGetResourceClass(database,client_name,
"undoCache",
3562 resource_info->undo_cache=(
unsigned int) StringToUnsignedLong(resource_value);
3563 resource_value=XGetResourceClass(database,client_name,
"update",
3565 resource_info->update=IsMagickTrue(resource_value);
3566 resource_value=XGetResourceClass(database,client_name,
"usePixmap",
3568 resource_info->use_pixmap=IsMagickTrue(resource_value);
3569 resource_value=XGetResourceClass(database,client_name,
"sharedMemory",
3571 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3572 resource_info->visual_type=XGetResourceClass(database,client_name,
"visual",
3574 resource_info->window_group=XGetResourceClass(database,client_name,
3575 "windowGroup",(
char *) NULL);
3576 resource_info->window_id=XGetResourceClass(database,client_name,
"window",
3578 resource_info->write_filename=XGetResourceClass(database,client_name,
3579 "writeFilename",(
char *) NULL);
3580 resource_info->debug=(GetLogEventMask() & X11Event) != 0 ? MagickTrue :
3618 MagickExport
char *XGetResourceInstance(XrmDatabase database,
3619 const char *client_name,
const char *keyword,
const char *resource_default)
3623 resource_name[MaxTextExtent];
3631 if (database == (XrmDatabase) NULL)
3632 return((
char *) resource_default);
3633 *resource_name=
'\0';
3634 if (keyword != (
char *) NULL)
3635 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.%s",client_name,
3637 status=XrmGetResource(database,resource_name,
"ImageMagick",&resource_type,
3639 if (status == False)
3640 return((
char *) resource_default);
3641 return(resource_value.addr);
3671 MagickExport
char *XGetScreenDensity(Display *display)
3674 density[MaxTextExtent];
3683 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3684 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3685 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3686 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3687 (void) FormatLocaleString(density,MaxTextExtent,
"%gx%g",x_density,
3689 return(GetPageGeometry(density));
3727 static Window XGetSubwindow(Display *display,Window window,
int x,
int y)
3740 assert(display != (Display *) NULL);
3741 source_window=XRootWindow(display,XDefaultScreen(display));
3742 if (window == (Window) NULL)
3743 return(source_window);
3744 target_window=window;
3747 status=XTranslateCoordinates(display,source_window,window,x,y,
3748 &x_offset,&y_offset,&target_window);
3751 if (target_window == (Window) NULL)
3753 source_window=window;
3754 window=target_window;
3758 if (target_window == (Window) NULL)
3759 target_window=window;
3760 return(target_window);
3793 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3794 XWindows *windows,
char *name)
3827 assert(display != (Display *) NULL);
3828 assert(name != (
char *) NULL);
3829 if (IsEventLogging() != MagickFalse)
3830 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
3832 target_window=XSelectWindow(display,&crop_info);
3833 if (target_window == (Window) NULL)
3834 return(MagickFalse);
3835 root_window=XRootWindow(display,XDefaultScreen(display));
3836 client_window=target_window;
3837 if (target_window != root_window)
3845 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3846 if (status != False)
3848 client_window=XClientWindow(display,target_window);
3849 target_window=client_window;
3855 status=XGetWindowAttributes(display,target_window,&window_attributes);
3856 if ((status == False) || (window_attributes.map_state != IsViewable))
3857 return(MagickFalse);
3861 (void) XTranslateCoordinates(display,root_window,target_window,
3862 (
int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3863 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3864 if (ximage == (XImage *) NULL)
3865 return(MagickFalse);
3866 color.pixel=XGetPixel(ximage,0,0);
3867 XDestroyImage(ximage);
3871 (void) XQueryColor(display,window_attributes.colormap,&color);
3872 pixel.red=ScaleShortToQuantum(color.red);
3873 pixel.green=ScaleShortToQuantum(color.green);
3874 pixel.blue=ScaleShortToQuantum(color.blue);
3875 pixel.opacity=OpaqueOpacity;
3876 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3877 &windows->image.image->exception);
3920 static Image *XGetWindowImage(Display *display,
const Window window,
3921 const unsigned int borders,
const unsigned int level)
3935 typedef struct _WindowInfo
3996 assert(display != (Display *) NULL);
3997 if (IsEventLogging() != MagickFalse)
3998 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3999 status=XGetWindowAttributes(display,window,&window_attributes);
4000 if ((status == False) || (window_attributes.map_state != IsViewable))
4001 return((
Image *) NULL);
4005 root_window=XRootWindow(display,XDefaultScreen(display));
4006 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4008 crop_info.x=(ssize_t) x_offset;
4009 crop_info.y=(ssize_t) y_offset;
4010 crop_info.width=(size_t) window_attributes.width;
4011 crop_info.height=(
size_t) window_attributes.height;
4012 if (borders != MagickFalse)
4017 crop_info.x-=(ssize_t) window_attributes.border_width;
4018 crop_info.y-=(ssize_t) window_attributes.border_width;
4019 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4020 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4025 if (crop_info.x < 0)
4027 crop_info.width+=crop_info.x;
4030 if (crop_info.y < 0)
4032 crop_info.height+=crop_info.y;
4035 display_width=XDisplayWidth(display,XDefaultScreen(display));
4036 if ((
int) (crop_info.x+crop_info.width) > display_width)
4037 crop_info.width=(size_t) (display_width-crop_info.x);
4038 display_height=XDisplayHeight(display,XDefaultScreen(display));
4039 if ((
int) (crop_info.y+crop_info.height) > display_height)
4040 crop_info.height=(size_t) (display_height-crop_info.y);
4044 if (number_windows >= max_windows)
4050 if (window_info == (WindowInfo *) NULL)
4051 window_info=(WindowInfo *) AcquireQuantumMemory((
size_t) max_windows,
4052 sizeof(*window_info));
4054 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(
size_t)
4055 max_windows,
sizeof(*window_info));
4057 if (window_info == (WindowInfo *) NULL)
4058 ThrowXWindowFatalException(ResourceLimitError,
4059 "MemoryAllocationFailed",
"...");
4060 id=number_windows++;
4061 window_info[id].window=window;
4062 window_info[id].visual=window_attributes.visual;
4063 window_info[id].colormap=window_attributes.colormap;
4064 window_info[id].bounds.x1=(short) crop_info.x;
4065 window_info[
id].bounds.y1=(
short) crop_info.y;
4066 window_info[id].bounds.x2=(short) (crop_info.x+(
int) crop_info.width-1);
4067 window_info[id].bounds.y2=(short) (crop_info.y+(
int) crop_info.height-1);
4068 crop_info.x-=x_offset;
4069 crop_info.y-=y_offset;
4070 window_info[id].crop_info=crop_info;
4082 status=XQueryTree(display,window,&root_window,&window_info[
id].parent,
4083 &children,&number_children);
4084 for (i=0; i < id; i++)
4085 if ((window_info[i].window == window_info[
id].parent) &&
4086 (window_info[i].visual == window_info[
id].visual) &&
4087 (window_info[i].colormap == window_info[
id].colormap))
4089 if ((window_info[
id].bounds.x1 < window_info[i].bounds.x1) ||
4090 (window_info[
id].bounds.x2 > window_info[i].bounds.x2) ||
4091 (window_info[
id].bounds.y1 < window_info[i].bounds.y1) ||
4092 (window_info[
id].bounds.y2 > window_info[i].bounds.y2))
4101 if ((status == True) && (number_children != 0))
4103 for (i=0; i < (int) number_children; i++)
4104 (
void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4105 (void) XFree((
void *) children);
4151 image=NewImageList();
4152 for (
id=0;
id < number_windows;
id++)
4157 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4158 (window_info[
id].bounds.x1 <= window_info[0].bounds.x2) &&
4159 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4160 (window_info[
id].bounds.y1 <= window_info[0].bounds.y2)) ?
4161 MagickTrue : MagickFalse;
4165 for (j=0; j < id; j++)
4166 if ((window_info[
id].visual == window_info[j].visual) &&
4167 (window_info[id].colormap == window_info[j].colormap))
4169 if ((window_info[
id].bounds.x1 >= window_info[j].bounds.x1) &&
4170 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4171 (window_info[
id].bounds.y1 >= window_info[j].bounds.y1) &&
4172 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4175 if (
import == MagickFalse)
4180 ximage=XGetImage(display,window_info[
id].window,(
int)
4181 window_info[
id].crop_info.x,(
int) window_info[
id].crop_info.y,
4182 (
unsigned int) window_info[
id].crop_info.width,(
unsigned int)
4183 window_info[
id].crop_info.height,AllPlanes,ZPixmap);
4184 if (ximage == (XImage *) NULL)
4190 colors=(XColor *) NULL;
4191 if (window_info[
id].colormap != (Colormap) NULL)
4199 number_colors=(
unsigned int) window_info[
id].visual->map_entries;
4200 for (p=colormap_info; p != (
ColormapInfo *) NULL; p=p->next)
4201 if (p->colormap == window_info[
id].colormap)
4208 colors=(XColor *) AcquireQuantumMemory(number_colors,
4210 if (colors == (XColor *) NULL)
4212 XDestroyImage(ximage);
4213 return((
Image *) NULL);
4215 if ((window_info[
id].visual->klass != DirectColor) &&
4216 (window_info[
id].visual->klass != TrueColor))
4217 for (i=0; i < (int) number_colors; i++)
4219 colors[i].pixel=(size_t) i;
4238 red_bit=window_info[id].visual->red_mask &
4239 (~(window_info[id].visual->red_mask)+1);
4240 green_bit=window_info[id].visual->green_mask &
4241 (~(window_info[id].visual->green_mask)+1);
4242 blue_bit=window_info[id].visual->blue_mask &
4243 (~(window_info[id].visual->blue_mask)+1);
4244 for (i=0; i < (int) number_colors; i++)
4246 colors[i].pixel=(
unsigned long) (red | green | blue);
4249 if (red > window_info[
id].visual->red_mask)
4252 if (green > window_info[
id].visual->green_mask)
4255 if (blue > window_info[
id].visual->blue_mask)
4259 (void) XQueryColors(display,window_info[
id].colormap,colors,
4260 (
int) number_colors);
4266 return((
Image *) NULL);
4267 p->colormap=window_info[id].colormap;
4269 p->next=colormap_info;
4277 composite_image=AcquireImage((
ImageInfo *) NULL);
4278 if (composite_image == (
Image *) NULL)
4280 XDestroyImage(ximage);
4281 return((
Image *) NULL);
4286 if ((window_info[
id].visual->klass != TrueColor) &&
4287 (window_info[
id].visual->klass != DirectColor))
4288 composite_image->storage_class=PseudoClass;
4289 composite_image->columns=(size_t) ximage->width;
4290 composite_image->rows=(
size_t) ximage->height;
4291 exception=(&composite_image->exception);
4292 composite_view=AcquireAuthenticCacheView(composite_image,exception);
4293 switch (composite_image->storage_class)
4313 red_mask=window_info[id].visual->red_mask;
4315 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4320 green_mask=window_info[id].visual->green_mask;
4322 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4327 blue_mask=window_info[id].visual->blue_mask;
4329 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4337 if ((number_colors != 0) &&
4338 (window_info[
id].visual->klass == DirectColor))
4339 for (y=0; y < (int) composite_image->rows; y++)
4341 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4342 composite_image->columns,1,exception);
4345 for (x=0; x < (int) composite_image->columns; x++)
4347 pixel=XGetPixel(ximage,x,y);
4348 index=(pixel >> red_shift) & red_mask;
4349 SetPixelRed(q,ScaleShortToQuantum(
4350 colors[index].red));
4351 index=(pixel >> green_shift) & green_mask;
4352 SetPixelGreen(q,ScaleShortToQuantum(
4353 colors[index].green));
4354 index=(pixel >> blue_shift) & blue_mask;
4355 SetPixelBlue(q,ScaleShortToQuantum(
4356 colors[index].blue));
4359 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4363 for (y=0; y < (int) composite_image->rows; y++)
4365 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4366 composite_image->columns,1,exception);
4369 for (x=0; x < (int) composite_image->columns; x++)
4371 pixel=XGetPixel(ximage,x,y);
4372 color=(pixel >> red_shift) & red_mask;
4374 color=(65535UL*color)/red_mask;
4375 SetPixelRed(q,ScaleShortToQuantum((
unsigned short)
4377 color=(pixel >> green_shift) & green_mask;
4378 if (green_mask != 0)
4379 color=(65535UL*color)/green_mask;
4380 SetPixelGreen(q,ScaleShortToQuantum((
unsigned short)
4382 color=(pixel >> blue_shift) & blue_mask;
4384 color=(65535UL*color)/blue_mask;
4385 SetPixelBlue(q,ScaleShortToQuantum((
unsigned short)
4389 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4399 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4401 XDestroyImage(ximage);
4402 composite_image=DestroyImage(composite_image);
4403 return((
Image *) NULL);
4405 if (colors == (XColor *) NULL)
4407 for (i=0; i < (int) composite_image->colors; i++)
4409 composite_image->colormap[colors[i].pixel].red=
4410 ScaleShortToQuantum(colors[i].red);
4411 composite_image->colormap[colors[i].pixel].green=
4412 ScaleShortToQuantum(colors[i].green);
4413 composite_image->colormap[colors[i].pixel].blue=
4414 ScaleShortToQuantum(colors[i].blue);
4419 for (y=0; y < (int) composite_image->rows; y++)
4421 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4422 composite_image->columns,1,exception);
4425 indexes=GetCacheViewAuthenticIndexQueue(composite_view);
4426 for (x=0; x < (int) composite_image->columns; x++)
4428 index=(IndexPacket) XGetPixel(ximage,x,y);
4429 SetPixelIndex(indexes+x,index);
4430 SetPixelRGBO(q,composite_image->colormap+(ssize_t)
4434 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4440 composite_view=DestroyCacheView(composite_view);
4441 XDestroyImage(ximage);
4442 if (image == (
Image *) NULL)
4444 image=composite_image;
4450 (void) XTranslateCoordinates(display,window_info[
id].window,window,0,0,
4451 &x_offset,&y_offset,&child);
4452 x_offset-=(int) crop_info.x;
4455 y_offset-=(int) crop_info.y;
4458 (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4459 x_offset,(ssize_t) y_offset);
4460 composite_image=DestroyImage(composite_image);
4467 next=colormap_info->next;
4468 colormap_info->colors=(XColor *)
4469 RelinquishMagickMemory(colormap_info->colors);
4470 colormap_info=(
ColormapInfo *) RelinquishMagickMemory(colormap_info);
4476 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4482 return((
Image *) NULL);
4523 MagickExport
void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4524 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4525 XResourceInfo *resource_info,XWindowInfo *window)
4530 assert(display != (Display *) NULL);
4531 assert(visual_info != (XVisualInfo *) NULL);
4532 assert(map_info != (XStandardColormap *) NULL);
4533 assert(pixel != (XPixelInfo *) NULL);
4534 assert(resource_info != (XResourceInfo *) NULL);
4535 assert(window != (XWindowInfo *) NULL);
4536 if (IsEventLogging() != MagickFalse)
4537 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4538 if (window->id != (Window) NULL)
4540 if (window->cursor != (Cursor) NULL)
4541 (
void) XFreeCursor(display,window->cursor);
4542 if (window->busy_cursor != (Cursor) NULL)
4543 (void) XFreeCursor(display,window->busy_cursor);
4544 if (window->highlight_stipple != (Pixmap) NULL)
4545 (
void) XFreePixmap(display,window->highlight_stipple);
4546 if (window->shadow_stipple != (Pixmap) NULL)
4547 (void) XFreePixmap(display,window->shadow_stipple);
4548 if (window->name == (
char *) NULL)
4549 window->name=AcquireString(
"");
4550 if (window->icon_name == (
char *) NULL)
4551 window->icon_name=AcquireString(
"");
4558 window->id=(Window) NULL;
4559 if (window->name == (
char *) NULL)
4560 window->name=AcquireString(
"");
4561 if (window->icon_name == (
char *) NULL)
4562 window->icon_name=AcquireString(
"");
4563 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4564 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4565 window->ximage=(XImage *) NULL;
4566 window->matte_image=(XImage *) NULL;
4567 window->pixmap=(Pixmap) NULL;
4568 window->matte_pixmap=(Pixmap) NULL;
4569 window->mapped=MagickFalse;
4570 window->stasis=MagickFalse;
4571 window->shared_memory=MagickTrue;
4572 window->segment_info=(
void *) NULL;
4573 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4578 if (window->segment_info == (
void *) NULL)
4579 window->segment_info=AcquireCriticalMemory(2*
sizeof(*segment_info));
4580 segment_info=(XShmSegmentInfo *) window->segment_info;
4581 segment_info[0].shmid=(-1);
4582 segment_info[0].shmaddr=(
char *) NULL;
4583 segment_info[1].shmid=(-1);
4584 segment_info[1].shmaddr=(
char *) NULL;
4591 window->screen=visual_info->screen;
4592 window->root=XRootWindow(display,visual_info->screen);
4593 window->visual=visual_info->visual;
4594 window->storage_class=(
unsigned int) visual_info->klass;
4595 window->depth=(
unsigned int) visual_info->depth;
4596 window->visual_info=visual_info;
4597 window->map_info=map_info;
4598 window->pixel_info=pixel;
4599 window->font_info=font_info;
4600 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4601 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4602 window->geometry=(
char *) NULL;
4603 window->icon_geometry=(
char *) NULL;
4604 if (resource_info->icon_geometry != (
char *) NULL)
4605 (
void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4606 window->crop_geometry=(
char *) NULL;
4607 window->flags=(size_t) PSize;
4610 window->min_width=1;
4611 window->min_height=1;
4612 window->width_inc=1;
4613 window->height_inc=1;
4614 window->border_width=resource_info->border_width;
4615 window->annotate_context=pixel->annotate_context;
4616 window->highlight_context=pixel->highlight_context;
4617 window->widget_context=pixel->widget_context;
4618 window->shadow_stipple=(Pixmap) NULL;
4619 window->highlight_stipple=(Pixmap) NULL;
4620 window->use_pixmap=MagickTrue;
4621 window->immutable=MagickFalse;
4622 window->shape=MagickFalse;
4624 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4625 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4626 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4627 window->attributes.background_pixel=pixel->background_color.pixel;
4628 window->attributes.background_pixmap=(Pixmap) NULL;
4629 window->attributes.bit_gravity=ForgetGravity;
4630 window->attributes.backing_store=WhenMapped;
4631 window->attributes.save_under=MagickTrue;
4632 window->attributes.border_pixel=pixel->border_color.pixel;
4633 window->attributes.colormap=map_info->colormap;
4634 window->attributes.cursor=window->cursor;
4635 window->attributes.do_not_propagate_mask=NoEventMask;
4636 window->attributes.event_mask=NoEventMask;
4637 window->attributes.override_redirect=MagickFalse;
4638 window->attributes.win_gravity=NorthWestGravity;
4639 window->orphan=MagickFalse;
4674 MagickExport
void XHighlightEllipse(Display *display,Window window,
4677 assert(display != (Display *) NULL);
4678 assert(window != (Window) NULL);
4679 assert(annotate_context != (GC) NULL);
4681 if (IsEventLogging() != MagickFalse)
4682 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4683 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4685 (void) XDrawArc(display,window,annotate_context,(
int) highlight_info->x,
4686 (int) highlight_info->y,(
unsigned int) highlight_info->width-1,
4687 (
unsigned int) highlight_info->height-1,0,360*64);
4688 (void) XDrawArc(display,window,annotate_context,(
int) highlight_info->x+1,
4689 (int) highlight_info->y+1,(
unsigned int) highlight_info->width-3,
4690 (
unsigned int) highlight_info->height-3,0,360*64);
4725 MagickExport
void XHighlightLine(Display *display,Window window,
4726 GC annotate_context,
const XSegment *highlight_info)
4728 assert(display != (Display *) NULL);
4729 assert(window != (Window) NULL);
4730 assert(annotate_context != (GC) NULL);
4731 assert(highlight_info != (XSegment *) NULL);
4732 if (IsEventLogging() != MagickFalse)
4733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4734 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4735 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4770 MagickExport
void XHighlightRectangle(Display *display,Window window,
4773 assert(display != (Display *) NULL);
4774 assert(window != (Window) NULL);
4775 assert(annotate_context != (GC) NULL);
4777 if (IsEventLogging() != MagickFalse)
4778 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4779 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4781 (void) XDrawRectangle(display,window,annotate_context,(
int) highlight_info->x,
4782 (int) highlight_info->y,(
unsigned int) highlight_info->width-1,
4783 (
unsigned int) highlight_info->height-1);
4784 (void) XDrawRectangle(display,window,annotate_context,(
int) highlight_info->x+
4785 1,(int) highlight_info->y+1,(
unsigned int) highlight_info->width-3,
4786 (
unsigned int) highlight_info->height-3);
4849 assert(image_info != (
const ImageInfo *) NULL);
4850 assert(image_info->signature == MagickCoreSignature);
4852 if (IsEventLogging() != MagickFalse)
4853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
4854 image_info->filename);
4855 display=XOpenDisplay(image_info->server_name);
4856 if (display == (Display *) NULL)
4857 ThrowXWindowFatalException(XServerError,
"UnableToOpenXServer",
4858 XDisplayName(image_info->server_name));
4862 (void) XSetErrorHandler(XError);
4870 root=XRootWindow(display,XDefaultScreen(display));
4871 target=(Window) NULL;
4872 if (*image_info->filename !=
'\0')
4874 if (LocaleCompare(image_info->filename,
"root") == 0)
4881 if (isdigit((
int) ((
unsigned char) *image_info->filename)) != 0)
4882 target=XWindowByID(display,root,(Window)
4883 strtol(image_info->filename,(
char **) NULL,0));
4884 if (target == (Window) NULL)
4885 target=XWindowByName(display,root,image_info->filename);
4886 if (target == (Window) NULL)
4887 ThrowXWindowException(XServerError,
"NoWindowWithSpecifiedIDExists",
4888 image_info->filename);
4894 prior_target=target;
4895 if (target == (Window) NULL)
4896 target=XSelectWindow(display,&crop_info);
4897 if (target == (Window) NULL)
4898 ThrowXWindowException(XServerError,
"UnableToReadXWindowImage",
4899 image_info->filename);
4906 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4907 if (status != False)
4917 status=XQueryTree(display,target,&root,&parent,&children,&d);
4918 if ((status != False) && (children != (Window *) NULL))
4919 (void) XFree((
char *) children);
4920 if ((status == False) || (parent == (Window) NULL) ||
4928 client=XClientWindow(display,target);
4929 if (ximage_info->frame == MagickFalse)
4931 if ((ximage_info->frame == MagickFalse) &&
4932 (prior_target != MagickFalse))
4933 target=prior_target;
4936 if (ximage_info->screen != MagickFalse)
4950 status=XGetWindowAttributes(display,target,&window_attributes);
4951 if (status == False)
4953 (void) XCloseDisplay(display);
4954 ThrowXWindowFatalException(XServerError,
4955 "UnableToReadXWindowAttributes",image_info->filename);
4957 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4958 crop_info.x=(ssize_t) x;
4959 crop_info.y=(ssize_t) y;
4960 crop_info.width=(size_t) window_attributes.width;
4961 crop_info.height=(
size_t) window_attributes.height;
4962 if (ximage_info->borders != 0)
4967 crop_info.x-=window_attributes.border_width;
4968 crop_info.y-=window_attributes.border_width;
4969 crop_info.width+=window_attributes.border_width << 1;
4970 crop_info.height+=window_attributes.border_width << 1;
4978 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4979 if ((status == True) && (number_windows > 0))
4981 ximage_info->descend=MagickTrue;
4982 (void) XFree ((
char *) children);
4984 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
4985 if (number_colormaps > 0)
4987 if (number_colormaps > 1)
4988 ximage_info->descend=MagickTrue;
4989 (void) XFree((
char *) colormaps);
4994 if (ximage_info->silent == MagickFalse)
4995 (void) XBell(display,0);
4999 (void) XGrabServer(display);
5000 image=XGetWindowImage(display,target,ximage_info->borders,
5001 ximage_info->descend ? 1U : 0U);
5002 (void) XUngrabServer(display);
5003 if (image == (
Image *) NULL)
5004 ThrowXWindowException(XServerError,
"UnableToReadXWindowImage",
5005 image_info->filename)
5008 (void) CopyMagickString(image->filename,image_info->filename,
5010 if ((crop_info.width != 0) && (crop_info.height != 0))
5018 crop_image=CropImage(image,&crop_info,&image->exception);
5019 if (crop_image != (
Image *) NULL)
5021 image=DestroyImage(image);
5025 status=XGetWMName(display,target,&window_name);
5028 if (*image_info->filename ==
'\0')
5029 (void) CopyMagickString(image->filename,(
char *) window_name.value,
5030 (size_t) window_name.nitems+1);
5031 (void) XFree((
void *) window_name.value);
5034 if (ximage_info->silent == MagickFalse)
5039 (void) XBell(display,0);
5040 (void) XBell(display,0);
5042 (void) XCloseDisplay(display);
5074 MagickExport XWindows *XInitializeWindows(Display *display,
5075 XResourceInfo *resource_info)
5086 windows=(XWindows *) AcquireMagickMemory(
sizeof(*windows));
5087 if (windows == (XWindows *) NULL)
5088 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5090 (void) memset(windows,0,
sizeof(*windows));
5091 windows->pixel_info=(XPixelInfo *) AcquireQuantumMemory(1,
5092 sizeof(*windows->pixel_info));
5093 windows->icon_pixel=(XPixelInfo *) AcquireQuantumMemory(1,
5094 sizeof(*windows->icon_pixel));
5095 windows->icon_resources=(XResourceInfo *) AcquireQuantumMemory(1,
5096 sizeof(*windows->icon_resources));
5097 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5098 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5099 (windows->icon_resources == (XResourceInfo *) NULL))
5100 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5105 windows->display=display;
5106 windows->wm_protocols=XInternAtom(display,
"WM_PROTOCOLS",MagickFalse);
5107 windows->wm_delete_window=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
5108 windows->wm_take_focus=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
5109 windows->im_protocols=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
5110 windows->im_remote_command=
5111 XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
5112 windows->im_update_widget=XInternAtom(display,
"IM_UPDATE_WIDGET",MagickFalse);
5113 windows->im_update_colormap=
5114 XInternAtom(display,
"IM_UPDATE_COLORMAP",MagickFalse);
5115 windows->im_former_image=XInternAtom(display,
"IM_FORMER_IMAGE",MagickFalse);
5116 windows->im_next_image=XInternAtom(display,
"IM_NEXT_IMAGE",MagickFalse);
5117 windows->im_retain_colors=XInternAtom(display,
"IM_RETAIN_COLORS",MagickFalse);
5118 windows->im_exit=XInternAtom(display,
"IM_EXIT",MagickFalse);
5119 windows->dnd_protocols=XInternAtom(display,
"DndProtocol",MagickFalse);
5120 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5121 (void) XSynchronize(display,MagickFalse);
5123 if ((GetLogEventMask() & X11Event) != 0)
5125 (void) XSynchronize(display,MagickTrue);
5126 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Version: %s",
5127 GetMagickVersion((
size_t *) NULL));
5128 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Protocols:");
5129 (void) LogMagickEvent(X11Event,GetMagickModule(),
5130 " Window Manager: 0x%lx",windows->wm_protocols);
5131 (void) LogMagickEvent(X11Event,GetMagickModule(),
5132 " delete window: 0x%lx",windows->wm_delete_window);
5133 (void) LogMagickEvent(X11Event,GetMagickModule(),
" take focus: 0x%lx",
5134 windows->wm_take_focus);
5135 (void) LogMagickEvent(X11Event,GetMagickModule(),
" ImageMagick: 0x%lx",
5136 windows->im_protocols);
5137 (void) LogMagickEvent(X11Event,GetMagickModule(),
5138 " remote command: 0x%lx",windows->im_remote_command);
5139 (void) LogMagickEvent(X11Event,GetMagickModule(),
5140 " update widget: 0x%lx",windows->im_update_widget);
5141 (void) LogMagickEvent(X11Event,GetMagickModule(),
5142 " update colormap: 0x%lx",windows->im_update_colormap);
5143 (void) LogMagickEvent(X11Event,GetMagickModule(),
5144 " former image: 0x%lx",windows->im_former_image);
5145 (void) LogMagickEvent(X11Event,GetMagickModule(),
" next image: 0x%lx",
5146 windows->im_next_image);
5147 (void) LogMagickEvent(X11Event,GetMagickModule(),
5148 " retain colors: 0x%lx",windows->im_retain_colors);
5149 (void) LogMagickEvent(X11Event,GetMagickModule(),
" exit: 0x%lx",
5151 (void) LogMagickEvent(X11Event,GetMagickModule(),
" Drag and Drop: 0x%lx",
5152 windows->dnd_protocols);
5157 windows->map_info=XAllocStandardColormap();
5158 windows->icon_map=XAllocStandardColormap();
5159 if ((windows->map_info == (XStandardColormap *) NULL) ||
5160 (windows->icon_map == (XStandardColormap *) NULL))
5161 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5163 windows->map_info->colormap=(Colormap) NULL;
5164 windows->icon_map->colormap=(Colormap) NULL;
5165 windows->pixel_info->pixels=(
unsigned long *) NULL;
5166 windows->pixel_info->annotate_context=(GC) NULL;
5167 windows->pixel_info->highlight_context=(GC) NULL;
5168 windows->pixel_info->widget_context=(GC) NULL;
5169 windows->font_info=(XFontStruct *) NULL;
5170 windows->icon_pixel->annotate_context=(GC) NULL;
5171 windows->icon_pixel->pixels=(
unsigned long *) NULL;
5175 *windows->icon_resources=(*resource_info);
5176 windows->icon_resources->visual_type=(
char *)
"default";
5177 windows->icon_resources->colormap=SharedColormap;
5178 windows->visual_info=
5179 XBestVisualInfo(display,windows->map_info,resource_info);
5180 windows->icon_visual=
5181 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5182 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5183 (windows->icon_visual == (XVisualInfo *) NULL))
5184 ThrowXWindowFatalException(XServerFatalError,
"UnableToGetVisual",
5185 resource_info->visual_type);
5186 if ((GetLogEventMask() & X11Event) != 0)
5188 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Visual:");
5189 (void) LogMagickEvent(X11Event,GetMagickModule(),
" visual id: 0x%lx",
5190 windows->visual_info->visualid);
5191 (void) LogMagickEvent(X11Event,GetMagickModule(),
" class: %s",
5192 XVisualClassName(windows->visual_info->klass));
5193 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d planes",
5194 windows->visual_info->depth);
5195 (void) LogMagickEvent(X11Event,GetMagickModule(),
5196 " size of colormap: %d entries",windows->visual_info->colormap_size);
5197 (void) LogMagickEvent(X11Event,GetMagickModule(),
5198 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5199 windows->visual_info->red_mask,windows->visual_info->green_mask,
5200 windows->visual_info->blue_mask);
5201 (void) LogMagickEvent(X11Event,GetMagickModule(),
5202 " significant bits in color: %d bits",
5203 windows->visual_info->bits_per_rgb);
5208 windows->class_hints=XAllocClassHint();
5209 windows->manager_hints=XAllocWMHints();
5210 if ((windows->class_hints == (XClassHint *) NULL) ||
5211 (windows->manager_hints == (XWMHints *) NULL))
5212 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5217 root_window=XRootWindow(display,windows->visual_info->screen);
5218 windows->group_leader.id=(Window) NULL;
5219 if (resource_info->window_group != (
char *) NULL)
5221 if (isdigit((
int) ((
unsigned char) *resource_info->window_group)) != 0)
5222 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5223 strtol((
char *) resource_info->window_group,(
char **) NULL,0));
5224 if (windows->group_leader.id == (Window) NULL)
5225 windows->group_leader.id=
5226 XWindowByName(display,root_window,resource_info->window_group);
5265 MagickExport Cursor XMakeCursor(Display *display,Window window,
5266 Colormap colormap,
char *background_color,
char *foreground_color)
5268 #define scope_height 17
5269 #define scope_x_hot 8
5270 #define scope_y_hot 8
5271 #define scope_width 17
5273 static const unsigned char
5276 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5277 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5278 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5279 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5280 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5284 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5285 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5286 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5287 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5288 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5302 assert(display != (Display *) NULL);
5303 assert(window != (Window) NULL);
5304 assert(colormap != (Colormap) NULL);
5305 assert(background_color != (
char *) NULL);
5306 assert(foreground_color != (
char *) NULL);
5307 if (IsEventLogging() != MagickFalse)
5308 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",background_color);
5309 source=XCreateBitmapFromData(display,window,(
char *) scope_bits,scope_width,
5311 mask=XCreateBitmapFromData(display,window,(
char *) scope_mask_bits,
5312 scope_width,scope_height);
5313 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5314 ThrowXWindowFatalException(XServerError,
"UnableToCreatePixmap",
"...");
5315 (void) XParseColor(display,colormap,background_color,&background);
5316 (void) XParseColor(display,colormap,foreground_color,&foreground);
5317 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5318 scope_x_hot,scope_y_hot);
5319 (void) XFreePixmap(display,source);
5320 (void) XFreePixmap(display,mask);
5362 MagickExport MagickBooleanType XMakeImage(Display *display,
5363 const XResourceInfo *resource_info,XWindowInfo *window,
Image *image,
5364 unsigned int width,
unsigned int height)
5366 #define CheckOverflowException(length,width,height) \
5367 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5380 assert(display != (Display *) NULL);
5381 assert(resource_info != (XResourceInfo *) NULL);
5382 assert(window != (XWindowInfo *) NULL);
5384 assert(height != 0);
5385 magick_unreferenced(length);
5386 if (IsEventLogging() != MagickFalse)
5387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
5388 if ((window->width == 0) || (window->height == 0))
5389 return(MagickFalse);
5393 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5394 (void) XFlush(display);
5395 depth=(int) window->depth;
5396 if (window->destroy)
5397 window->image=DestroyImage(window->image);
5398 window->image=image;
5399 window->destroy=MagickFalse;
5400 if (window->image != (
Image *) NULL)
5402 if (window->crop_geometry != (
char *) NULL)
5413 window->image->page.x=0;
5414 window->image->page.y=0;
5415 (void) ParsePageGeometry(window->image,window->crop_geometry,
5416 &crop_info,&image->exception);
5417 crop_image=CropImage(window->image,&crop_info,&image->exception);
5418 if (crop_image != (
Image *) NULL)
5420 if (window->image != image)
5421 window->image=DestroyImage(window->image);
5422 window->image=crop_image;
5423 window->destroy=MagickTrue;
5426 if ((width != (
unsigned int) window->image->columns) ||
5427 (height != (
unsigned int) window->image->rows))
5435 resize_image=NewImageList();
5436 if ((window->pixel_info->colors == 0) &&
5437 (window->image->rows > (
unsigned long) XDisplayHeight(display,window->screen)) &&
5438 (window->image->columns > (
unsigned long) XDisplayWidth(display,window->screen)))
5439 resize_image=ResizeImage(window->image,width,height,
5440 image->filter,image->blur,&image->exception);
5443 if (window->image->storage_class == PseudoClass)
5444 resize_image=SampleImage(window->image,width,height,
5447 resize_image=ThumbnailImage(window->image,width,height,
5450 if (resize_image != (
Image *) NULL)
5452 if (window->image != image)
5453 window->image=DestroyImage(window->image);
5454 window->image=resize_image;
5455 window->destroy=MagickTrue;
5458 width=(
unsigned int) window->image->columns;
5459 assert((
size_t) width == window->image->columns);
5460 height=(
unsigned int) window->image->rows;
5461 assert((
size_t) height == window->image->rows);
5466 ximage=(XImage *) NULL;
5467 format=(depth == 1) ? XYBitmap : ZPixmap;
5468 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5469 if (window->shared_memory != MagickFalse)
5474 segment_info=(XShmSegmentInfo *) window->segment_info;
5475 segment_info[1].shmid=(-1);
5476 segment_info[1].shmaddr=(
char *) NULL;
5477 ximage=XShmCreateImage(display,window->visual,(
unsigned int) depth,format,
5478 (
char *) NULL,&segment_info[1],width,height);
5480 if (ximage == (XImage *) NULL)
5481 window->shared_memory=MagickFalse;
5484 length=(size_t) ximage->bytes_per_line*ximage->height;
5485 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5486 window->shared_memory=MagickFalse;
5488 if (window->shared_memory != MagickFalse)
5489 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5490 if (window->shared_memory != MagickFalse)
5491 segment_info[1].shmaddr=(
char *) shmat(segment_info[1].shmid,0,0);
5492 if (segment_info[1].shmid < 0)
5493 window->shared_memory=MagickFalse;
5494 if (window->shared_memory != MagickFalse)
5495 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5498 if (ximage != (XImage *) NULL)
5499 XDestroyImage(ximage);
5500 ximage=(XImage *) NULL;
5501 if (segment_info[1].shmaddr)
5503 (void) shmdt(segment_info[1].shmaddr);
5504 segment_info[1].shmaddr=(
char *) NULL;
5506 if (segment_info[1].shmid >= 0)
5508 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5509 segment_info[1].shmid=(-1);
5517 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5518 if (window->shared_memory)
5526 (void) XSync(display,MagickFalse);
5527 xerror_alert=MagickFalse;
5528 segment_info=(XShmSegmentInfo *) window->segment_info;
5529 ximage->data=segment_info[1].shmaddr;
5530 segment_info[1].readOnly=MagickFalse;
5531 status=XShmAttach(display,&segment_info[1]);
5532 if (status != False)
5533 (void) XSync(display,MagickFalse);
5534 if ((status == False) || (xerror_alert != MagickFalse))
5536 window->shared_memory=MagickFalse;
5537 if (status != False)
5538 XShmDetach(display,&segment_info[1]);
5540 XDestroyImage(ximage);
5541 ximage=(XImage *) NULL;
5542 if (segment_info[1].shmid >= 0)
5544 if (segment_info[1].shmaddr != NULL)
5545 (void) shmdt(segment_info[1].shmaddr);
5546 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5547 segment_info[1].shmid=(-1);
5548 segment_info[1].shmaddr=(
char *) NULL;
5553 if (window->shared_memory == MagickFalse)
5554 ximage=XCreateImage(display,window->visual,(
unsigned int) depth,format,0,
5555 (
char *) NULL,width,height,XBitmapPad(display),0);
5556 if (ximage == (XImage *) NULL)
5561 (void) XCheckDefineCursor(display,window->id,window->cursor);
5562 return(MagickFalse);
5564 length=(size_t) ximage->bytes_per_line*ximage->height;
5565 if ((GetLogEventMask() & X11Event) != 0)
5567 (void) LogMagickEvent(X11Event,GetMagickModule(),
"XImage:");
5568 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %dx%d",
5569 ximage->width,ximage->height);
5570 (void) LogMagickEvent(X11Event,GetMagickModule(),
" format: %d",
5572 (void) LogMagickEvent(X11Event,GetMagickModule(),
" byte order: %d",
5573 ximage->byte_order);
5574 (void) LogMagickEvent(X11Event,GetMagickModule(),
5575 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5576 ximage->bitmap_bit_order,ximage->bitmap_pad);
5577 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d",
5579 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bytes per line: %d",
5580 ximage->bytes_per_line);
5581 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bits per pixel: %d",
5582 ximage->bits_per_pixel);
5583 (void) LogMagickEvent(X11Event,GetMagickModule(),
5584 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5585 ximage->green_mask,ximage->blue_mask);
5587 if (window->shared_memory == MagickFalse)
5589 if (ximage->format == XYBitmap)
5591 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5592 ximage->bytes_per_line,(size_t) ximage->depth*ximage->height);
5593 if (ximage->data != (
char *) NULL)
5594 (
void) memset(ximage->data,0,(
size_t)
5595 ximage->bytes_per_line*ximage->depth*ximage->height);
5599 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5600 ximage->bytes_per_line,(size_t) ximage->height);
5601 if (ximage->data != (
char *) NULL)
5602 (
void) memset(ximage->data,0,(
size_t)
5603 ximage->bytes_per_line*ximage->height);
5606 if (ximage->data == (
char *) NULL)
5611 XDestroyImage(ximage);
5612 ximage=(XImage *) NULL;
5613 (void) XCheckDefineCursor(display,window->id,window->cursor);
5614 return(MagickFalse);
5616 if (window->ximage != (XImage *) NULL)
5621 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5622 #
if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5623 if (window->segment_info != (XShmSegmentInfo *) NULL)
5628 segment_info=(XShmSegmentInfo *) window->segment_info;
5629 if (segment_info[0].shmid >= 0)
5631 (void) XSync(display,MagickFalse);
5632 (void) XShmDetach(display,&segment_info[0]);
5633 (void) XSync(display,MagickFalse);
5634 if (segment_info[0].shmaddr != (
char *) NULL)
5635 (
void) shmdt(segment_info[0].shmaddr);
5636 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5637 segment_info[0].shmid=(-1);
5638 segment_info[0].shmaddr=(
char *) NULL;
5639 window->ximage->data=(
char *) NULL;
5643 if (window->ximage->data != (
char *) NULL)
5644 free(window->ximage->data);
5645 window->ximage->data=(
char *) NULL;
5646 XDestroyImage(window->ximage);
5647 window->ximage=(XImage *) NULL;
5649 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5650 if (window->segment_info != (XShmSegmentInfo *) NULL)
5655 segment_info=(XShmSegmentInfo *) window->segment_info;
5656 segment_info[0]=segment_info[1];
5659 window->ximage=ximage;
5660 matte_image=(XImage *) NULL;
5661 if ((window->shape != MagickFalse) && (window->image != (
Image *) NULL))
5662 if ((window->image->matte != MagickFalse) &&
5663 ((int) width <= XDisplayWidth(display,window->screen)) &&
5664 ((
int) height <= XDisplayHeight(display,window->screen)))
5669 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5670 (
char *) NULL,width,height,XBitmapPad(display),0);
5671 if ((GetLogEventMask() & X11Event) != 0)
5673 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Matte Image:");
5674 (void) LogMagickEvent(X11Event,GetMagickModule(),
5675 " width, height: %dx%d",matte_image->width,matte_image->height);
5677 if (matte_image != (XImage *) NULL)
5682 matte_image->data=(
char *) malloc((
size_t)
5683 matte_image->bytes_per_line*matte_image->depth*
5684 matte_image->height);
5685 if (matte_image->data == (
char *) NULL)
5687 XDestroyImage(matte_image);
5688 matte_image=(XImage *) NULL;
5692 if (window->matte_image != (XImage *) NULL)
5697 if (window->matte_image->data != (
char *) NULL)
5698 free(window->matte_image->data);
5699 window->matte_image->data=(
char *) NULL;
5700 XDestroyImage(window->matte_image);
5701 window->matte_image=(XImage *) NULL;
5703 window->matte_image=matte_image;
5704 if (window->matte_pixmap != (Pixmap) NULL)
5706 (void) XFreePixmap(display,window->matte_pixmap);
5707 window->matte_pixmap=(Pixmap) NULL;
5708 #if defined(MAGICKCORE_HAVE_SHAPE)
5709 if (window->shape != MagickFalse)
5710 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5713 window->stasis=MagickFalse;
5717 if (window->image != (
Image *) NULL)
5719 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5720 (ximage->bitmap_bit_order == LSBFirst)))
5721 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5724 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5727 if (window->matte_image != (XImage *) NULL)
5732 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5733 if (window->matte_pixmap != (Pixmap) NULL)
5744 context_values.background=1;
5745 context_values.foreground=0;
5746 graphics_context=XCreateGC(display,window->matte_pixmap,
5747 (
size_t) (GCBackground | GCForeground),&context_values);
5748 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5749 window->matte_image,0,0,0,0,width,height);
5750 (void) XFreeGC(display,graphics_context);
5751 #if defined(MAGICKCORE_HAVE_SHAPE)
5752 if (window->shape != MagickFalse)
5753 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5754 window->matte_pixmap,ShapeSet);
5758 (void) XMakePixmap(display,resource_info,window);
5762 (void) XCheckDefineCursor(display,window->id,window->cursor);
5802 static void XMakeImageLSBFirst(
const XResourceInfo *resource_info,
5803 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image)
5840 assert(resource_info != (XResourceInfo *) NULL);
5841 assert(window != (XWindowInfo *) NULL);
5842 assert(image != (
Image *) NULL);
5843 if (IsEventLogging() != MagickFalse)
5844 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5846 if ((window->immutable == MagickFalse) &&
5847 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5850 size[MaxTextExtent];
5858 image_info=AcquireImageInfo();
5859 (void) CopyMagickString(image_info->filename,
5860 resource_info->image_info->texture != (
char *) NULL ?
5861 resource_info->image_info->texture :
"pattern:checkerboard",
5863 (void) FormatLocaleString(size,MaxTextExtent,
"%.20gx%.20g",(
double)
5864 image->columns,(double) image->rows);
5865 image_info->size=ConstantString(size);
5866 pattern=ReadImage(image_info,&image->exception);
5867 image_info=DestroyImageInfo(image_info);
5868 if (pattern != (
Image *) NULL)
5870 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5871 if (canvas == (
Image *) NULL)
5873 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5874 pattern=DestroyImage(pattern);
5877 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
5878 ximage->bits_per_pixel) >> 3));
5879 map_info=window->map_info;
5880 pixels=window->pixel_info->pixels;
5881 q=(
unsigned char *) ximage->data;
5883 canvas_view=AcquireVirtualCacheView(canvas,&canvas->exception);
5884 if (ximage->format == XYBitmap)
5896 background=(
unsigned char)
5897 (XPixelIntensity(&window->pixel_info->foreground_color) <
5898 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5899 foreground=(
unsigned char)
5900 (XPixelIntensity(&window->pixel_info->background_color) <
5901 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5902 polarity=(
unsigned short) ((GetPixelIntensity(image,
5903 &canvas->colormap[0])) < (QuantumRange/2.0) ? 1 : 0);
5904 if (canvas->colors == 2)
5905 polarity=GetPixelIntensity(canvas,&canvas->colormap[0]) <
5906 GetPixelIntensity(canvas,&canvas->colormap[1]);
5907 for (y=0; y < (int) canvas->rows; y++)
5909 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5910 &canvas->exception);
5913 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5916 for (x=0; x < (int) canvas->columns; x++)
5919 if (GetPixelIndex(indexes+x) == (IndexPacket) polarity)
5937 if (window->pixel_info->colors != 0)
5938 switch (ximage->bits_per_pixel)
5948 for (y=0; y < (int) canvas->rows; y++)
5950 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
5951 canvas->columns,1,&canvas->exception);
5954 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5956 for (x=0; x < (int) canvas->columns; x++)
5958 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0x0f;
5963 *q=(
unsigned char) pixel;
5969 *q|=(
unsigned char) (pixel << 2);
5975 *q|=(
unsigned char) (pixel << 4);
5981 *q|=(
unsigned char) (pixel << 6);
6000 for (y=0; y < (int) canvas->rows; y++)
6002 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6003 canvas->columns,1,&canvas->exception);
6006 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6008 for (x=0; x < (int) canvas->columns; x++)
6010 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0xf;
6015 *q=(
unsigned char) pixel;
6021 *q|=(
unsigned char) (pixel << 4);
6038 if ((resource_info->color_recovery != MagickFalse) &&
6039 (resource_info->quantize_info->dither != MagickFalse))
6041 XDitherImage(canvas,ximage);
6044 for (y=0; y < (int) canvas->rows; y++)
6046 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6047 canvas->columns,1,&canvas->exception);
6050 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6051 for (x=0; x < (int) canvas->columns; x++)
6053 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6054 *q++=(
unsigned char) pixel;
6071 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6072 for (y=0; y < (int) canvas->rows; y++)
6074 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6075 canvas->columns,1,&canvas->exception);
6078 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6079 for (x=0; x < (int) canvas->columns; x++)
6081 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6082 for (k=0; k < (int) bytes_per_pixel; k++)
6084 *q++=(
unsigned char) (pixel & 0xff);
6094 switch (ximage->bits_per_pixel)
6104 for (y=0; y < (int) canvas->rows; y++)
6107 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6108 canvas->columns,1,&canvas->exception);
6111 for (x=0; x < (int) canvas->columns; x++)
6113 pixel=XGammaPixel(map_info,p);
6119 *q=(
unsigned char) pixel;
6125 *q|=(
unsigned char) (pixel << 2);
6131 *q|=(
unsigned char) (pixel << 4);
6137 *q|=(
unsigned char) (pixel << 6);
6157 for (y=0; y < (int) canvas->rows; y++)
6159 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6160 canvas->columns,1,&canvas->exception);
6164 for (x=0; x < (int) canvas->columns; x++)
6166 pixel=XGammaPixel(map_info,p);
6172 *q=(
unsigned char) pixel;
6178 *q|=(
unsigned char) (pixel << 4);
6196 if ((resource_info->color_recovery != MagickFalse) &&
6197 (resource_info->quantize_info->dither != MagickFalse))
6199 XDitherImage(canvas,ximage);
6202 for (y=0; y < (int) canvas->rows; y++)
6204 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6205 canvas->columns,1,&canvas->exception);
6208 for (x=0; x < (int) canvas->columns; x++)
6210 pixel=XGammaPixel(map_info,p);
6211 *q++=(
unsigned char) pixel;
6220 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6221 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6222 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6223 (map_info->blue_mult == 1))
6228 for (y=0; y < (int) canvas->rows; y++)
6230 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6231 canvas->columns,1,&canvas->exception);
6234 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6235 (blue_gamma != 1.0))
6240 for (x=(
int) canvas->columns-1; x >= 0; x--)
6242 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6243 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6244 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6250 for (x=(
int) canvas->columns-1; x >= 0; x--)
6252 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6253 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6254 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6261 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6262 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6263 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6264 (map_info->blue_mult == 65536L))
6269 for (y=0; y < (int) canvas->rows; y++)
6271 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6272 canvas->columns,1,&canvas->exception);
6275 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6276 (blue_gamma != 1.0))
6281 for (x=(
int) canvas->columns-1; x >= 0; x--)
6283 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6284 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6285 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6291 for (x=(
int) canvas->columns-1; x >= 0; x--)
6293 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6294 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6295 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6312 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6313 for (y=0; y < (int) canvas->rows; y++)
6315 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6316 canvas->columns,1,&canvas->exception);
6319 for (x=0; x < (int) canvas->columns; x++)
6321 pixel=XGammaPixel(map_info,p);
6322 for (k=0; k < (int) bytes_per_pixel; k++)
6324 *q++=(
unsigned char) (pixel & 0xff);
6335 if (matte_image != (XImage *) NULL)
6340 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6341 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6342 q=(
unsigned char *) matte_image->data;
6343 for (y=0; y < (int) canvas->rows; y++)
6345 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6346 &canvas->exception);
6351 for (x=(
int) canvas->columns-1; x >= 0; x--)
6354 if (GetPixelOpacity(p) > (QuantumRange/2))
6370 canvas_view=DestroyCacheView(canvas_view);
6371 if (canvas != image)
6372 canvas=DestroyImage(canvas);
6411 static void XMakeImageMSBFirst(
const XResourceInfo *resource_info,
6412 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image)
6449 assert(resource_info != (XResourceInfo *) NULL);
6450 assert(window != (XWindowInfo *) NULL);
6451 assert(image != (
Image *) NULL);
6452 if (IsEventLogging() != MagickFalse)
6453 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6455 if ((window->immutable != MagickFalse) &&
6456 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6459 size[MaxTextExtent];
6467 image_info=AcquireImageInfo();
6468 (void) CopyMagickString(image_info->filename,
6469 resource_info->image_info->texture != (
char *) NULL ?
6470 resource_info->image_info->texture :
"pattern:checkerboard",
6472 (void) FormatLocaleString(size,MaxTextExtent,
"%.20gx%.20g",(
double)
6473 image->columns,(double) image->rows);
6474 image_info->size=ConstantString(size);
6475 pattern=ReadImage(image_info,&image->exception);
6476 image_info=DestroyImageInfo(image_info);
6477 if (pattern != (
Image *) NULL)
6479 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6480 if (canvas == (
Image *) NULL)
6482 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6483 pattern=DestroyImage(pattern);
6486 scanline_pad=(
unsigned int) (ximage->bytes_per_line-
6487 ((ximage->width*ximage->bits_per_pixel) >> 3));
6488 map_info=window->map_info;
6489 pixels=window->pixel_info->pixels;
6490 q=(
unsigned char *) ximage->data;
6492 canvas_view=AcquireVirtualCacheView(canvas,&canvas->exception);
6493 if (ximage->format == XYBitmap)
6505 background=(
unsigned char)
6506 (XPixelIntensity(&window->pixel_info->foreground_color) <
6507 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6508 foreground=(
unsigned char)
6509 (XPixelIntensity(&window->pixel_info->background_color) <
6510 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6511 polarity=(
unsigned short) ((GetPixelIntensity(image,
6512 &canvas->colormap[0])) < (QuantumRange/2.0) ? 1 : 0);
6513 if (canvas->colors == 2)
6514 polarity=GetPixelIntensity(canvas,&canvas->colormap[0]) <
6515 GetPixelIntensity(canvas,&canvas->colormap[1]);
6516 for (y=0; y < (int) canvas->rows; y++)
6518 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6519 &canvas->exception);
6522 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6525 for (x=(
int) canvas->columns-1; x >= 0; x--)
6528 if (GetPixelIndex(indexes+x) == (IndexPacket) polarity)
6546 if (window->pixel_info->colors != 0)
6547 switch (ximage->bits_per_pixel)
6557 for (y=0; y < (int) canvas->rows; y++)
6559 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6560 canvas->columns,1,&canvas->exception);
6563 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6565 for (x=0; x < (int) canvas->columns; x++)
6567 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0xf;
6572 *q=(
unsigned char) (pixel << 6);
6578 *q|=(
unsigned char) (pixel << 4);
6584 *q|=(
unsigned char) (pixel << 2);
6590 *q|=(
unsigned char) pixel;
6609 for (y=0; y < (int) canvas->rows; y++)
6611 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6612 canvas->columns,1,&canvas->exception);
6615 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6617 for (x=0; x < (int) canvas->columns; x++)
6619 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0xf;
6624 *q=(
unsigned char) (pixel << 4);
6630 *q|=(
unsigned char) pixel;
6647 if (resource_info->color_recovery &&
6648 resource_info->quantize_info->dither)
6650 XDitherImage(canvas,ximage);
6653 for (y=0; y < (int) canvas->rows; y++)
6655 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6656 canvas->columns,1,&canvas->exception);
6659 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6660 for (x=0; x < (int) canvas->columns; x++)
6662 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6663 *q++=(
unsigned char) pixel;
6678 channel[
sizeof(size_t)];
6683 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6684 for (y=0; y < (int) canvas->rows; y++)
6686 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6687 canvas->columns,1,&canvas->exception);
6690 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6691 for (x=0; x < (int) canvas->columns; x++)
6693 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6694 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
6696 channel[k]=(
unsigned char) pixel;
6699 for (k=0; k < (int) bytes_per_pixel; k++)
6708 switch (ximage->bits_per_pixel)
6718 for (y=0; y < (int) canvas->rows; y++)
6720 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6721 canvas->columns,1,&canvas->exception);
6725 for (x=(
int) canvas->columns-1; x >= 0; x--)
6727 pixel=XGammaPixel(map_info,p);
6733 *q=(
unsigned char) (pixel << 6);
6739 *q|=(
unsigned char) (pixel << 4);
6745 *q|=(
unsigned char) (pixel << 2);
6751 *q|=(
unsigned char) pixel;
6771 for (y=0; y < (int) canvas->rows; y++)
6773 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6774 canvas->columns,1,&canvas->exception);
6778 for (x=(
int) canvas->columns-1; x >= 0; x--)
6780 pixel=XGammaPixel(map_info,p);
6786 *q=(
unsigned char) (pixel << 4);
6792 *q|=(
unsigned char) pixel;
6810 if (resource_info->color_recovery &&
6811 resource_info->quantize_info->dither)
6813 XDitherImage(canvas,ximage);
6816 for (y=0; y < (int) canvas->rows; y++)
6818 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6819 canvas->columns,1,&canvas->exception);
6822 for (x=(
int) canvas->columns-1; x >= 0; x--)
6824 pixel=XGammaPixel(map_info,p);
6825 *q++=(
unsigned char) pixel;
6834 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6835 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6836 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6837 (map_info->blue_mult == 1))
6842 for (y=0; y < (int) canvas->rows; y++)
6844 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6845 canvas->columns,1,&canvas->exception);
6848 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6849 (blue_gamma != 1.0))
6854 for (x=(
int) canvas->columns-1; x >= 0; x--)
6857 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6858 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6859 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6864 for (x=(
int) canvas->columns-1; x >= 0; x--)
6867 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6868 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6869 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6875 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6876 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6877 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6878 (map_info->blue_mult == 65536L))
6883 for (y=0; y < (int) canvas->rows; y++)
6885 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6886 canvas->columns,1,&canvas->exception);
6889 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6890 (blue_gamma != 1.0))
6895 for (x=(
int) canvas->columns-1; x >= 0; x--)
6898 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6899 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6900 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6905 for (x=(
int) canvas->columns-1; x >= 0; x--)
6908 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6909 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6910 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6926 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6927 for (y=0; y < (int) canvas->rows; y++)
6929 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6930 canvas->columns,1,&canvas->exception);
6933 for (x=(
int) canvas->columns-1; x >= 0; x--)
6935 pixel=XGammaPixel(map_info,p);
6936 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
6938 *q++=(
unsigned char) (pixel & 0xff);
6949 if (matte_image != (XImage *) NULL)
6954 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6955 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6956 q=(
unsigned char *) matte_image->data;
6957 for (y=0; y < (int) canvas->rows; y++)
6959 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6960 &canvas->exception);
6965 for (x=(
int) canvas->columns-1; x >= 0; x--)
6968 if (GetPixelOpacity(p) > (QuantumRange/2))
6984 canvas_view=DestroyCacheView(canvas_view);
6985 if (canvas != image)
6986 canvas=DestroyImage(canvas);
7014 MagickExport
void XMakeMagnifyImage(Display *display,XWindows *windows)
7017 tuple[MaxTextExtent];
7039 previous_magnify = 0;
7059 assert(display != (Display *) NULL);
7060 assert(windows != (XWindows *) NULL);
7061 if (IsEventLogging() != MagickFalse)
7062 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7064 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7066 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7068 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7070 while (magnify > windows->magnify.width)
7072 while (magnify > windows->magnify.height)
7077 if (previous_magnify != 0)
7078 magnify=previous_magnify;
7080 if (magnify != previous_magnify)
7092 while ((1 << i) <= (int) magnify)
7094 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7095 "Magnify %.20gX",(
double) i);
7096 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7097 if (status != False)
7099 XSetWMName(display,windows->magnify.id,&window_name);
7100 XSetWMIconName(display,windows->magnify.id,&window_name);
7101 (void) XFree((
void *) window_name.value);
7104 previous_magnify=magnify;
7105 ximage=windows->image.ximage;
7106 width=(
unsigned int) windows->magnify.ximage->width;
7107 height=(
unsigned int) windows->magnify.ximage->height;
7108 if ((windows->magnify.x < 0) ||
7109 (windows->magnify.x >= windows->image.ximage->width))
7110 windows->magnify.x=windows->image.ximage->width >> 1;
7111 x=windows->magnify.x-((width/magnify) >> 1);
7115 if (x > (
int) (ximage->width-(width/magnify)))
7116 x=ximage->width-width/magnify;
7117 if ((windows->magnify.y < 0) ||
7118 (windows->magnify.y >= windows->image.ximage->height))
7119 windows->magnify.y=windows->image.ximage->height >> 1;
7120 y=windows->magnify.y-((height/magnify) >> 1);
7124 if (y > (
int) (ximage->height-(height/magnify)))
7125 y=ximage->height-height/magnify;
7126 q=(
unsigned char *) windows->magnify.ximage->data;
7127 scanline_pad=(
unsigned int) (windows->magnify.ximage->bytes_per_line-
7128 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7129 if (ximage->bits_per_pixel < 8)
7144 pixel_info=windows->magnify.pixel_info;
7145 switch (ximage->bitmap_bit_order)
7154 if (ximage->format == XYBitmap)
7156 background=(
unsigned char)
7157 (XPixelIntensity(&pixel_info->foreground_color) <
7158 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7159 foreground=(
unsigned char)
7160 (XPixelIntensity(&pixel_info->background_color) <
7161 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7162 if (windows->magnify.depth > 1)
7163 Swap(background,foreground);
7165 for (i=0; i < (ssize_t) height; i+=magnify)
7170 for (j=0; j < magnify; j++)
7172 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7173 ((x*ximage->bits_per_pixel) >> 3);
7174 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7177 for (k=0; k < width; k+=magnify)
7182 for (l=0; l < magnify; l++)
7187 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7190 if (*p & (0x01 << (p_bit+plane)))
7203 p_bit+=ximage->bits_per_pixel;
7210 *q=byte >> (8-q_bit);
7226 if (ximage->format == XYBitmap)
7228 background=(
unsigned char)
7229 (XPixelIntensity(&pixel_info->foreground_color) <
7230 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7231 foreground=(
unsigned char)
7232 (XPixelIntensity(&pixel_info->background_color) <
7233 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7234 if (windows->magnify.depth > 1)
7235 Swap(background,foreground);
7237 for (i=0; i < (ssize_t) height; i+=magnify)
7242 for (j=0; j < magnify; j++)
7244 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7245 ((x*ximage->bits_per_pixel) >> 3);
7246 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7249 for (k=0; k < width; k+=magnify)
7254 for (l=0; l < magnify; l++)
7259 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7262 if (*p & (0x80 >> (p_bit+plane)))
7275 p_bit+=ximage->bits_per_pixel;
7282 *q=byte << (8-q_bit);
7293 switch (ximage->bits_per_pixel)
7301 for (i=0; i < (ssize_t) height; i+=magnify)
7306 for (j=0; j < magnify; j++)
7308 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7309 ((x*ximage->bits_per_pixel) >> 3);
7310 for (k=0; k < width; k+=magnify)
7315 for (l=0; l < magnify; l++)
7334 bytes_per_pixel=(
unsigned int) ximage->bits_per_pixel >> 3;
7335 for (i=0; i < (ssize_t) height; i+=magnify)
7340 for (j=0; j < magnify; j++)
7342 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7343 ((x*ximage->bits_per_pixel) >> 3);
7344 for (k=0; k < width; k+=magnify)
7349 for (l=0; l < magnify; l++)
7350 for (m=0; m < bytes_per_pixel; m++)
7364 x=windows->magnify.x-((width/magnify) >> 1);
7366 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7368 if (x > (
int) (ximage->width-(width/magnify)))
7369 x=(
int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7372 y=windows->magnify.y-((height/magnify) >> 1);
7374 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7376 if (y > (
int) (ximage->height-(height/magnify)))
7377 y=(
int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7380 if ((x != 0) || (y != 0))
7381 (void) XFillRectangle(display,windows->magnify.pixmap,
7382 windows->magnify.annotate_context,0,0,width,height);
7383 (void) XPutImage(display,windows->magnify.pixmap,
7384 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7386 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7387 (magnify <= (height >> 1))))
7395 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7396 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7397 highlight_info.width=magnify;
7398 highlight_info.height=magnify;
7399 (void) XDrawRectangle(display,windows->magnify.pixmap,
7400 windows->magnify.highlight_context,(
int) highlight_info.x,
7401 (int) highlight_info.y,(
unsigned int) highlight_info.width-1,
7402 (
unsigned int) highlight_info.height-1);
7404 (void) XDrawRectangle(display,windows->magnify.pixmap,
7405 windows->magnify.annotate_context,(
int) highlight_info.x+1,
7406 (int) highlight_info.y+1,(
unsigned int) highlight_info.width-3,
7407 (
unsigned int) highlight_info.height-3);
7412 (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
7413 windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
7414 &windows->image.image->exception);
7415 (void) FormatLocaleString(tuple,MaxTextExtent,
"%d,%d: ",
7416 windows->magnify.x,windows->magnify.y);
7417 (void) ConcatenateMagickString(tuple,
"(",MaxTextExtent);
7418 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7419 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7420 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7421 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7422 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7423 if (pixel.colorspace == CMYKColorspace)
7425 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7426 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7428 if (pixel.matte != MagickFalse)
7430 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7431 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7433 (void) ConcatenateMagickString(tuple,
")",MaxTextExtent);
7434 height=(
unsigned int) windows->magnify.font_info->ascent+
7435 windows->magnify.font_info->descent;
7436 x=windows->magnify.font_info->max_bounds.width >> 1;
7437 y=windows->magnify.font_info->ascent+(height >> 2);
7438 (void) XDrawImageString(display,windows->magnify.pixmap,
7439 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7440 GetColorTuple(&pixel,MagickTrue,tuple);
7442 (void) XDrawImageString(display,windows->magnify.pixmap,
7443 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7444 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7445 &windows->image.image->exception);
7447 (void) XDrawImageString(display,windows->magnify.pixmap,
7448 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7452 magnify_window=windows->magnify;
7455 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7487 static MagickBooleanType XMakePixmap(Display *display,
7488 const XResourceInfo *resource_info,XWindowInfo *window)
7494 assert(display != (Display *) NULL);
7495 assert(resource_info != (XResourceInfo *) NULL);
7496 assert(window != (XWindowInfo *) NULL);
7497 if (IsEventLogging() != MagickFalse)
7498 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7499 (void) resource_info;
7500 if (window->pixmap != (Pixmap) NULL)
7505 (void) XFreePixmap(display,window->pixmap);
7506 window->pixmap=(Pixmap) NULL;
7508 if (window->use_pixmap == MagickFalse)
7509 return(MagickFalse);
7510 if (window->ximage == (XImage *) NULL)
7511 return(MagickFalse);
7515 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7516 (void) XFlush(display);
7520 width=(
unsigned int) window->ximage->width;
7521 height=(
unsigned int) window->ximage->height;
7522 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7523 if (window->pixmap == (Pixmap) NULL)
7528 (void) XCheckDefineCursor(display,window->id,window->cursor);
7529 return(MagickFalse);
7534 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7535 if (window->shared_memory)
7536 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7537 window->ximage,0,0,0,0,width,height,MagickTrue);
7539 if (window->shared_memory == MagickFalse)
7540 (void) XPutImage(display,window->pixmap,window->annotate_context,
7541 window->ximage,0,0,0,0,width,height);
7542 if ((GetLogEventMask() & X11Event) != 0)
7544 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Pixmap:");
7545 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %ux%u",
7551 (void) XCheckDefineCursor(display,window->id,window->cursor);
7592 #if defined(__cplusplus) || defined(c_plusplus)
7596 static inline MagickRealType DiversityPixelIntensity(
7597 const DiversityPacket *pixel)
7602 intensity=0.298839*pixel->red+0.586811*pixel->green+0.114350*pixel->blue;
7606 static int IntensityCompare(
const void *x,
const void *y)
7615 color_1=(DiversityPacket *) x;
7616 color_2=(DiversityPacket *) y;
7617 diversity=(int) (DiversityPixelIntensity(color_2)-
7618 DiversityPixelIntensity(color_1));
7622 static int PopularityCompare(
const void *x,
const void *y)
7628 color_1=(DiversityPacket *) x;
7629 color_2=(DiversityPacket *) y;
7630 return((
int) color_2->count-(int) color_1->count);
7633 #if defined(__cplusplus) || defined(c_plusplus)
7637 static inline Quantum ScaleXToQuantum(
const size_t x,
7640 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7643 MagickExport
void XMakeStandardColormap(Display *display,
7644 XVisualInfo *visual_info,XResourceInfo *resource_info,
Image *image,
7645 XStandardColormap *map_info,XPixelInfo *pixel)
7674 assert(display != (Display *) NULL);
7675 assert(visual_info != (XVisualInfo *) NULL);
7676 assert(map_info != (XStandardColormap *) NULL);
7677 assert(resource_info != (XResourceInfo *) NULL);
7678 assert(pixel != (XPixelInfo *) NULL);
7679 if (IsEventLogging() != MagickFalse)
7680 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7681 exception=(&image->exception);
7682 if (resource_info->map_type != (
char *) NULL)
7687 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7689 number_colors=(
unsigned int) (map_info->base_pixel+
7690 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7691 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7692 if ((image->matte == MagickFalse) &&
7693 (resource_info->color_recovery == MagickFalse) &&
7694 resource_info->quantize_info->dither &&
7695 (number_colors < MaxColormapSize))
7706 affinity_image=AcquireImage((
ImageInfo *) NULL);
7707 if (affinity_image == (
Image *) NULL)
7708 ThrowXWindowFatalException(ResourceLimitFatalError,
7709 "UnableToDitherImage",image->filename);
7710 affinity_image->columns=number_colors;
7711 affinity_image->rows=1;
7715 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7719 for (i=0; i < (ssize_t) number_colors; i++)
7722 if (map_info->red_max != 0)
7723 SetPixelRed(q,ScaleXToQuantum((
size_t) (i/
7724 map_info->red_mult),map_info->red_max));
7726 if (map_info->green_max != 0)
7727 SetPixelGreen(q,ScaleXToQuantum((
size_t) ((i/
7728 map_info->green_mult) % (map_info->green_max+1)),
7729 map_info->green_max));
7731 if (map_info->blue_max != 0)
7732 SetPixelBlue(q,ScaleXToQuantum((
size_t) (i %
7733 map_info->green_mult),map_info->blue_max));
7734 SetPixelOpacity(q,TransparentOpacity);
7737 (void) SyncAuthenticPixels(affinity_image,exception);
7738 (void) RemapImage(resource_info->quantize_info,image,
7741 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7743 (void) SetImageStorageClass(image,DirectClass);
7744 affinity_image=DestroyImage(affinity_image);
7746 if ((GetLogEventMask() & X11Event) != 0)
7748 (void) LogMagickEvent(X11Event,GetMagickModule(),
7749 "Standard Colormap:");
7750 (void) LogMagickEvent(X11Event,GetMagickModule(),
7751 " colormap id: 0x%lx",map_info->colormap);
7752 (void) LogMagickEvent(X11Event,GetMagickModule(),
7753 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7754 map_info->green_max,map_info->blue_max);
7755 (void) LogMagickEvent(X11Event,GetMagickModule(),
7756 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7757 map_info->green_mult,map_info->blue_mult);
7761 if ((visual_info->klass != DirectColor) &&
7762 (visual_info->klass != TrueColor))
7763 if ((image->storage_class == DirectClass) ||
7764 ((int) image->colors > visual_info->colormap_size))
7772 quantize_info=(*resource_info->quantize_info);
7773 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7774 (
void) QuantizeImage(&quantize_info,image);
7779 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7780 colormap=XDefaultColormap(display,visual_info->screen);
7781 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7782 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7783 visual_info->visual,visual_info->klass == DirectColor ?
7784 AllocAll : AllocNone);
7785 if (colormap == (Colormap) NULL)
7786 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToCreateColormap",
7791 XGetMapInfo(visual_info,colormap,map_info);
7792 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7796 switch (visual_info->klass)
7804 number_colors=image->colors;
7805 colors=(XColor *) AcquireQuantumMemory((
size_t)
7806 visual_info->colormap_size,
sizeof(*colors));
7807 if (colors == (XColor *) NULL)
7808 ThrowXWindowFatalException(ResourceLimitFatalError,
7809 "UnableToCreateColormap",image->filename);
7811 color.flags=(char) (DoRed | DoGreen | DoBlue);
7812 for (i=0; i < (ssize_t) image->colors; i++)
7814 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7815 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7816 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7817 if (visual_info->klass != StaticColor)
7819 gray_value=(
unsigned short) XPixelIntensity(&color);
7820 color.red=gray_value;
7821 color.green=gray_value;
7822 color.blue=gray_value;
7824 status=XAllocColor(display,colormap,&color);
7825 if (status == False)
7827 colormap=XCopyColormapAndFree(display,colormap);
7828 (void) XAllocColor(display,colormap,&color);
7830 pixel->pixels[i]=color.pixel;
7844 number_colors=image->colors;
7845 colors=(XColor *) AcquireQuantumMemory((
size_t)
7846 visual_info->colormap_size,
sizeof(*colors));
7847 if (colors == (XColor *) NULL)
7848 ThrowXWindowFatalException(ResourceLimitFatalError,
7849 "UnableToCreateColormap",image->filename);
7853 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7854 (void) XAllocColor(display,colormap,&pixel->background_color);
7855 (void) XAllocColor(display,colormap,&pixel->border_color);
7856 (void) XAllocColor(display,colormap,&pixel->matte_color);
7857 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7858 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7859 (void) XAllocColor(display,colormap,&pixel->depth_color);
7860 (void) XAllocColor(display,colormap,&pixel->trough_color);
7861 for (i=0; i < MaxNumberPens; i++)
7862 (
void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7866 colormap_type=resource_info->colormap;
7867 status=XAllocColorCells(display,colormap,MagickFalse,(
unsigned long *)
7868 NULL,0,pixel->pixels,(
unsigned int) image->colors);
7869 if (status != False)
7870 colormap_type=PrivateColormap;
7871 if (colormap_type == SharedColormap)
7894 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7895 sizeof(*diversity));
7896 if (diversity == (DiversityPacket *) NULL)
7897 ThrowXWindowFatalException(ResourceLimitFatalError,
7898 "UnableToCreateColormap",image->filename);
7899 for (i=0; i < (ssize_t) image->colors; i++)
7901 diversity[i].red=image->colormap[i].red;
7902 diversity[i].green=image->colormap[i].green;
7903 diversity[i].blue=image->colormap[i].blue;
7904 diversity[i].index=(
unsigned short) i;
7905 diversity[i].count=0;
7907 image_view=AcquireAuthenticCacheView(image,exception);
7908 for (y=0; y < (int) image->rows; y++)
7916 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7917 image->columns,1,exception);
7920 indexes=GetCacheViewAuthenticIndexQueue(image_view);
7921 for (x=(
int) image->columns-1; x >= 0; x--)
7922 diversity[(ssize_t) GetPixelIndex(indexes+x)].count++;
7924 image_view=DestroyCacheView(image_view);
7928 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
7930 for (i=0; i < (ssize_t) image->colors; )
7932 diversity[i].count<<=4;
7933 i+=MagickMax((
int) (image->colors >> 4),2);
7935 diversity[image->colors-1].count<<=4;
7936 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
7942 color.flags=(char) (DoRed | DoGreen | DoBlue);
7943 for (i=0; i < (ssize_t) image->colors; i++)
7945 index=diversity[i].index;
7947 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7949 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7951 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7952 if (visual_info->klass != PseudoColor)
7954 gray_value=(
unsigned short) XPixelIntensity(&color);
7955 color.red=gray_value;
7956 color.green=gray_value;
7957 color.blue=gray_value;
7959 status=XAllocColor(display,colormap,&color);
7960 if (status == False)
7962 pixel->pixels[index]=color.pixel;
7968 server_colors=(XColor *) AcquireQuantumMemory((
size_t)
7969 visual_info->colormap_size,
sizeof(*server_colors));
7970 if (server_colors == (XColor *) NULL)
7971 ThrowXWindowFatalException(ResourceLimitFatalError,
7972 "UnableToCreateColormap",image->filename);
7973 for (x=visual_info->colormap_size-1; x >= 0; x--)
7974 server_colors[x].pixel=(size_t) x;
7975 (void) XQueryColors(display,colormap,server_colors,
7976 (
int) MagickMin((
unsigned int) visual_info->colormap_size,256));
7980 for (; i < (ssize_t) image->colors; i++)
7982 index=diversity[i].index;
7984 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7986 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7988 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7989 if (visual_info->klass != PseudoColor)
7991 gray_value=(
unsigned short) XPixelIntensity(&color);
7992 color.red=gray_value;
7993 color.green=gray_value;
7994 color.blue=gray_value;
7996 XBestPixel(display,colormap,server_colors,(
unsigned int)
7997 visual_info->colormap_size,&color);
7998 pixel->pixels[index]=color.pixel;
8001 if ((
int) image->colors < visual_info->colormap_size)
8006 retain_colors=MagickMin((
unsigned int)
8007 (visual_info->colormap_size-image->colors),256);
8008 for (i=0; i < (ssize_t) retain_colors; i++)
8009 *p++=server_colors[i];
8010 number_colors+=retain_colors;
8012 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8013 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8019 if (status == False)
8024 colormap=XCreateColormap(display,
8025 XRootWindow(display,visual_info->screen),visual_info->visual,
8027 if (colormap == (Colormap) NULL)
8028 ThrowXWindowFatalException(ResourceLimitFatalError,
8029 "UnableToCreateColormap",image->filename);
8030 map_info->colormap=colormap;
8031 if ((
int) image->colors < visual_info->colormap_size)
8037 retain_colors=MagickMin((
unsigned int)
8038 (visual_info->colormap_size-image->colors),256);
8039 p=colors+image->colors;
8040 for (i=0; i < (ssize_t) retain_colors; i++)
8042 p->pixel=(
unsigned long) i;
8045 (void) XQueryColors(display,
8046 XDefaultColormap(display,visual_info->screen),
8047 colors+image->colors,(int) retain_colors);
8051 (void) XAllocColorCells(display,colormap,MagickFalse,
8052 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8054 p=colors+image->colors;
8055 for (i=0; i < (ssize_t) retain_colors; i++)
8057 p->pixel=pixel->pixels[i];
8060 (void) XStoreColors(display,colormap,colors+image->colors,
8061 (
int) retain_colors);
8062 number_colors+=retain_colors;
8064 (void) XAllocColorCells(display,colormap,MagickFalse,
8065 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8072 color.flags=(char) (DoRed | DoGreen | DoBlue);
8073 for (i=0; i < (ssize_t) image->colors; i++)
8075 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8076 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8077 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8078 if (visual_info->klass != PseudoColor)
8080 gray_value=(
unsigned short) XPixelIntensity(&color);
8081 color.red=gray_value;
8082 color.green=gray_value;
8083 color.blue=gray_value;
8085 color.pixel=pixel->pixels[i];
8088 (void) XStoreColors(display,colormap,colors,(
int) image->colors);
8101 number_colors=(
unsigned int) ((map_info->red_max*map_info->red_mult)+
8102 (map_info->green_max*map_info->green_mult)+
8103 (map_info->blue_max*map_info->blue_mult)+1);
8104 linear_colormap=(number_colors > 4096) ||
8105 (((
int) (map_info->red_max+1) == visual_info->colormap_size) &&
8106 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8107 ((
int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8108 MagickTrue : MagickFalse;
8109 if (linear_colormap != MagickFalse)
8110 number_colors=(size_t) visual_info->colormap_size;
8114 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
8115 if (colors == (XColor *) NULL)
8116 ThrowXWindowFatalException(ResourceLimitFatalError,
8117 "UnableToCreateColormap",image->filename);
8122 color.flags=(char) (DoRed | DoGreen | DoBlue);
8123 if (linear_colormap != MagickFalse)
8124 for (i=0; i < (ssize_t) number_colors; i++)
8126 color.blue=(
unsigned short) 0;
8127 if (map_info->blue_max != 0)
8128 color.blue=(
unsigned short) ((
size_t)
8129 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8130 color.green=color.blue;
8131 color.red=color.blue;
8132 color.pixel=XStandardPixel(map_info,&color);
8136 for (i=0; i < (ssize_t) number_colors; i++)
8138 color.red=(
unsigned short) 0;
8139 if (map_info->red_max != 0)
8140 color.red=(
unsigned short) ((
size_t)
8141 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8142 color.green=(
unsigned int) 0;
8143 if (map_info->green_max != 0)
8144 color.green=(
unsigned short) ((
size_t)
8145 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8146 map_info->green_max));
8147 color.blue=(
unsigned short) 0;
8148 if (map_info->blue_max != 0)
8149 color.blue=(
unsigned short) ((
size_t)
8150 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8151 color.pixel=XStandardPixel(map_info,&color);
8154 if ((visual_info->klass == DirectColor) &&
8155 (colormap != XDefaultColormap(display,visual_info->screen)))
8156 (void) XStoreColors(display,colormap,colors,(
int) number_colors);
8158 for (i=0; i < (ssize_t) number_colors; i++)
8159 (
void) XAllocColor(display,colormap,&colors[i]);
8163 if ((visual_info->klass != DirectColor) &&
8164 (visual_info->klass != TrueColor))
8169 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8170 &pixel->foreground_color);
8171 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8172 &pixel->background_color);
8173 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8178 pixel->background_color.red=(~pixel->foreground_color.red);
8179 pixel->background_color.green=
8180 (~pixel->foreground_color.green);
8181 pixel->background_color.blue=
8182 (~pixel->foreground_color.blue);
8183 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8184 &pixel->background_color);
8186 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8187 &pixel->border_color);
8188 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8189 &pixel->matte_color);
8190 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8191 &pixel->highlight_color);
8192 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8193 &pixel->shadow_color);
8194 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8195 &pixel->depth_color);
8196 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8197 &pixel->trough_color);
8198 for (i=0; i < MaxNumberPens; i++)
8200 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8201 &pixel->pen_colors[i]);
8202 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8204 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8206 colors=(XColor *) RelinquishMagickMemory(colors);
8207 if ((GetLogEventMask() & X11Event) != 0)
8209 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Standard Colormap:");
8210 (void) LogMagickEvent(X11Event,GetMagickModule(),
" colormap id: 0x%lx",
8211 map_info->colormap);
8212 (void) LogMagickEvent(X11Event,GetMagickModule(),
8213 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8214 map_info->green_max,map_info->blue_max);
8215 (void) LogMagickEvent(X11Event,GetMagickModule(),
8216 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8217 map_info->green_mult,map_info->blue_mult);
8258 MagickExport
void XMakeWindow(Display *display,Window parent,
char **argv,
8259 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8260 XWindowInfo *window_info)
8262 #define MinWindowSize 64
8270 static XTextProperty
8283 assert(display != (Display *) NULL);
8284 assert(window_info != (XWindowInfo *) NULL);
8285 if (IsEventLogging() != MagickFalse)
8286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8287 size_hints=XAllocSizeHints();
8288 if (size_hints == (XSizeHints *) NULL)
8289 ThrowXWindowFatalException(XServerFatalError,
"UnableToMakeXWindow",argv[0]);
8290 size_hints->flags=(int) window_info->flags;
8291 size_hints->x=window_info->x;
8292 size_hints->y=window_info->y;
8293 size_hints->width=(
int) window_info->width;
8294 size_hints->height=(int) window_info->height;
8295 if (window_info->immutable != MagickFalse)
8300 size_hints->min_width=size_hints->width;
8301 size_hints->min_height=size_hints->height;
8302 size_hints->max_width=size_hints->width;
8303 size_hints->max_height=size_hints->height;
8304 size_hints->flags|=PMinSize;
8305 size_hints->flags|=PMaxSize;
8312 size_hints->min_width=(int) window_info->min_width;
8313 size_hints->min_height=(
int) window_info->min_height;
8314 size_hints->flags|=PResizeInc;
8315 size_hints->width_inc=(int) window_info->width_inc;
8316 size_hints->height_inc=(
int) window_info->height_inc;
8317 #if !defined(PRE_R4_ICCCM)
8318 size_hints->flags|=PBaseSize;
8319 size_hints->base_width=size_hints->width_inc;
8320 size_hints->base_height=size_hints->height_inc;
8323 gravity=NorthWestGravity;
8324 if (window_info->geometry != (
char *) NULL)
8327 default_geometry[MaxTextExtent],
8328 geometry[MaxTextExtent];
8339 (void) FormatLocaleString(default_geometry,MaxTextExtent,
"%dx%d",
8340 size_hints->width,size_hints->height);
8341 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8343 while (strlen(p) != 0)
8345 if ((isspace((
int) ((
unsigned char) *p)) == 0) && (*p !=
'%'))
8348 (
void) memmove(p,p+1,MaxTextExtent-(p-geometry));
8350 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8351 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8352 &size_hints->width,&size_hints->height,&gravity);
8353 if ((flags & WidthValue) && (flags & HeightValue))
8354 size_hints->flags|=USSize;
8355 if ((flags & XValue) && (flags & YValue))
8357 size_hints->flags|=USPosition;
8358 window_info->x=size_hints->x;
8359 window_info->y=size_hints->y;
8362 #if !defined(PRE_R4_ICCCM)
8363 size_hints->win_gravity=gravity;
8364 size_hints->flags|=PWinGravity;
8366 if (window_info->id == (Window) NULL)
8367 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8368 (
unsigned int) size_hints->width,(
unsigned int) size_hints->height,
8369 window_info->border_width,(
int) window_info->depth,InputOutput,
8370 window_info->visual,(
unsigned long) window_info->mask,
8371 &window_info->attributes);
8386 (void) XChangeWindowAttributes(display,window_info->id,(
unsigned long)
8387 window_info->mask,&window_info->attributes);
8388 mask=ConfigureNotify;
8389 while (XCheckTypedWindowEvent(display,window_info->id,(
int) mask,&sans_event)) ;
8390 window_changes.x=window_info->x;
8391 window_changes.y=window_info->y;
8392 window_changes.width=(int) window_info->width;
8393 window_changes.height=(
int) window_info->height;
8394 mask=(MagickStatusType) (CWWidth | CWHeight);
8395 if (window_info->flags & USPosition)
8397 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8398 mask,&window_changes);
8400 if (window_info->id == (Window) NULL)
8401 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateWindow",
8403 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8404 if (status == False)
8405 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8407 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8408 if (status == False)
8409 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8410 window_info->icon_name);
8411 if (window_info->icon_geometry != (
char *) NULL)
8421 size_hints->flags|=USPosition;
8422 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8423 (
char *) NULL,0,size_hints,&manager_hints->icon_x,
8424 &manager_hints->icon_y,&width,&height,&gravity);
8425 if ((flags & XValue) && (flags & YValue))
8426 manager_hints->flags|=IconPositionHint;
8428 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8429 size_hints,manager_hints,class_hint);
8430 if (window_name.value != (
void *) NULL)
8432 (void) XFree((
void *) window_name.value);
8433 window_name.value=(
unsigned char *) NULL;
8434 window_name.nitems=0;
8436 if (icon_name.value != (
void *) NULL)
8438 (void) XFree((
void *) icon_name.value);
8439 icon_name.value=(
unsigned char *) NULL;
8442 atom_list[0]=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
8443 atom_list[1]=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
8444 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8445 (void) XFree((
void *) size_hints);
8446 if (window_info->shape != MagickFalse)
8448 #if defined(MAGICKCORE_HAVE_SHAPE)
8458 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8459 window_info->shape=MagickFalse;
8461 window_info->shape=MagickFalse;
8464 window_info->shape=MagickFalse;
8465 if (window_info->shared_memory != MagickFalse)
8467 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8471 if (XShmQueryExtension(display) == 0)
8472 window_info->shared_memory=MagickFalse;
8474 window_info->shared_memory=MagickFalse;
8477 window_info->image=NewImageList();
8478 window_info->destroy=MagickFalse;
8514 static const char *GetLocaleMonitorMessage(
const char *text)
8517 message[MaxTextExtent],
8526 (void) CopyMagickString(tag,text,MaxTextExtent);
8528 if (p != (
char *) NULL)
8530 (void) FormatLocaleString(message,MaxTextExtent,
"Monitor/%s",tag);
8531 locale_message=GetLocaleMessage(message);
8532 if (locale_message == message)
8534 return(locale_message);
8537 MagickExport MagickBooleanType XMagickProgressMonitor(
const char *tag,
8538 const MagickOffsetType quantum,
const MagickSizeType span,
8539 void *magick_unused(client_data))
8544 magick_unreferenced(client_data);
8546 windows=XSetWindows((XWindows *) ~0);
8547 if (windows == (XWindows *) NULL)
8549 if (windows->info.mapped != MagickFalse)
8550 XProgressMonitorWidget(windows->display,windows,
8551 GetLocaleMonitorMessage(tag),quantum,span);
8581 MagickExport MagickBooleanType XQueryColorDatabase(
const char *target,
8588 *display = (Display *) NULL;
8599 assert(color != (XColor *) NULL);
8603 color->flags=(char) (DoRed | DoGreen | DoBlue);
8604 if ((target == (
char *) NULL) || (*target ==
'\0'))
8605 target=
"#ffffffffffff";
8609 if (display == (Display *) NULL)
8610 display=XOpenDisplay((
char *) NULL);
8611 if (display == (Display *) NULL)
8612 ThrowXWindowFatalException(XServerError,
"ColorIsNotKnownToServer",target);
8613 colormap=XDefaultColormap(display,XDefaultScreen(display));
8614 status=XParseColor(display,colormap,(
char *) target,&xcolor);
8615 if (status == False)
8616 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",target)
8619 color->red=xcolor.red;
8620 color->green=xcolor.green;
8621 color->blue=xcolor.blue;
8622 color->flags=xcolor.flags;
8624 return(status != False ? MagickTrue : MagickFalse);
8658 MagickExport
void XQueryPosition(Display *display,
const Window window,
int *x,
int *y)
8670 assert(display != (Display *) NULL);
8671 assert(window != (Window) NULL);
8672 assert(x != (
int *) NULL);
8673 assert(y != (
int *) NULL);
8674 if (IsEventLogging() != MagickFalse)
8675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8676 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8709 MagickExport
void XRefreshWindow(Display *display,
const XWindowInfo *window,
8710 const XEvent *event)
8720 assert(display != (Display *) NULL);
8721 assert(window != (XWindowInfo *) NULL);
8722 if (IsEventLogging() != MagickFalse)
8723 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8724 if (window->ximage == (XImage *) NULL)
8726 if (event != (XEvent *) NULL)
8733 width=(
unsigned int) event->xexpose.width;
8734 height=(
unsigned int)
event->xexpose.height;
8746 width=window->width;
8747 height=window->height;
8748 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8749 if (window->matte_pixmap != (Pixmap) NULL)
8751 #if defined(MAGICKCORE_HAVE_SHAPE)
8752 if (window->shape != MagickFalse)
8753 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8754 window->matte_pixmap,ShapeSet);
8761 if ((window->ximage->width-(x+window->x)) < (
int) width)
8762 width=(
unsigned int) (window->ximage->width-(x+window->x));
8763 if ((window->ximage->height-(y+window->y)) < (int) height)
8764 height=(
unsigned int) (window->ximage->height-(y+window->y));
8768 if (window->matte_pixmap != (Pixmap) NULL)
8769 (
void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8770 if (window->pixmap != (Pixmap) NULL)
8772 if (window->depth > 1)
8773 (void) XCopyArea(display,window->pixmap,window->id,
8774 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8776 (
void) XCopyPlane(display,window->pixmap,window->id,
8777 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8782 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8783 if (window->shared_memory)
8784 (void) XShmPutImage(display,window->id,window->annotate_context,
8785 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8787 if (window->shared_memory == MagickFalse)
8788 (void) XPutImage(display,window->id,window->annotate_context,
8789 window->ximage,x+window->x,y+window->y,x,y,width,height);
8791 if (window->matte_pixmap != (Pixmap) NULL)
8792 (
void) XSetClipMask(display,window->annotate_context,None);
8793 (void) XFlush(display);
8825 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8826 const char *window,
const char *filename)
8835 assert(filename != (
char *) NULL);
8836 if (IsEventLogging() != MagickFalse)
8837 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
8838 if (display == (Display *) NULL)
8839 display=XOpenDisplay((
char *) NULL);
8840 if (display == (Display *) NULL)
8842 ThrowXWindowException(XServerError,
"UnableToOpenXServer",filename);
8843 return(MagickFalse);
8845 remote_atom=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
8846 remote_window=(Window) NULL;
8847 root_window=XRootWindow(display,XDefaultScreen(display));
8848 if (window != (
char *) NULL)
8853 if (isdigit((
int) ((
unsigned char) *window)) != 0)
8854 remote_window=XWindowByID(display,root_window,(Window)
8855 strtol((
char *) window,(
char **) NULL,0));
8856 if (remote_window == (Window) NULL)
8857 remote_window=XWindowByName(display,root_window,window);
8859 if (remote_window == (Window) NULL)
8860 remote_window=XWindowByProperty(display,root_window,remote_atom);
8861 if (remote_window == (Window) NULL)
8863 ThrowXWindowException(XServerError,
"UnableToConnectToRemoteDisplay",
8865 return(MagickFalse);
8870 remote_atom=XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
8871 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8872 PropModeReplace,(
unsigned char *) filename,(int) strlen(filename));
8873 (void) XSync(display,MagickFalse);
8907 MagickPrivate MagickBooleanType XRenderImage(
Image *image,
8917 *display = (Display *) NULL;
8953 display=XOpenDisplay(draw_info->server_name);
8954 if (display == (Display *) NULL)
8956 ThrowXWindowException(XServerError,
"UnableToOpenXServer",
8957 draw_info->server_name);
8958 return(MagickFalse);
8963 (void) XSetErrorHandler(XError);
8964 image_info=AcquireImageInfo();
8965 client_name=GetClientName();
8966 resource_database=XGetResourceDatabase(display,client_name);
8967 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
8968 resource_info.close_server=MagickFalse;
8969 resource_info.colormap=PrivateColormap;
8970 resource_info.font=AcquireString(draw_info->font);
8971 resource_info.background_color=AcquireString(
"#ffffffffffff");
8972 resource_info.foreground_color=AcquireString(
"#000000000000");
8973 map_info=XAllocStandardColormap();
8974 visual_info=(XVisualInfo *) NULL;
8975 font_info=(XFontStruct *) NULL;
8976 pixel.pixels=(
unsigned long *) NULL;
8977 if (map_info == (XStandardColormap *) NULL)
8979 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
8981 return(MagickFalse);
8986 visual_info=XBestVisualInfo(display,map_info,&resource_info);
8987 if (visual_info == (XVisualInfo *) NULL)
8989 XFreeResources(display,visual_info,map_info,&pixel,font_info,
8990 &resource_info,(XWindowInfo *) NULL);
8991 ThrowXWindowException(XServerError,
"UnableToGetVisual",image->filename);
8992 return(MagickFalse);
8994 map_info->colormap=(Colormap) NULL;
8998 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9000 XGetPixelPacket(display,visual_info,map_info,&resource_info,(
Image *) NULL,
9002 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9006 font_info=XBestFont(display,&resource_info,MagickFalse);
9007 if (font_info == (XFontStruct *) NULL)
9009 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9010 &resource_info,(XWindowInfo *) NULL);
9011 ThrowXWindowException(XServerError,
"UnableToLoadFont",draw_info->font);
9012 return(MagickFalse);
9014 cache_info=(*draw_info);
9018 XGetAnnotateInfo(&annotate_info);
9019 annotate_info.stencil=ForegroundStencil;
9020 if (cache_info.font != draw_info->font)
9025 (void) XFreeFont(display,font_info);
9026 (void) CloneString(&resource_info.font,draw_info->font);
9027 font_info=XBestFont(display,&resource_info,MagickFalse);
9028 if (font_info == (XFontStruct *) NULL)
9030 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9032 return(MagickFalse);
9035 if (draw_info->debug != MagickFalse)
9036 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9037 "Font %s; pointsize %g",draw_info->font != (
char *) NULL ?
9038 draw_info->font :
"none",draw_info->pointsize);
9039 cache_info=(*draw_info);
9040 annotate_info.font_info=font_info;
9041 annotate_info.text=(
char *) draw_info->text;
9042 annotate_info.width=(
unsigned int) XTextWidth(font_info,draw_info->text,(
int)
9043 strlen(draw_info->text));
9044 annotate_info.height=(
unsigned int) font_info->ascent+font_info->descent;
9045 metrics->pixels_per_em.x=(
double) font_info->max_bounds.width;
9046 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9047 metrics->ascent=(
double) font_info->ascent+4;
9048 metrics->descent=(double) (-font_info->descent);
9049 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9050 metrics->height=font_info->ascent+font_info->descent;
9051 metrics->max_advance=(double) font_info->max_bounds.width;
9052 metrics->bounds.x1=0.0;
9053 metrics->bounds.y1=metrics->descent;
9054 metrics->bounds.x2=metrics->ascent+metrics->descent;
9055 metrics->bounds.y2=metrics->ascent+metrics->descent;
9056 metrics->underline_position=(-2.0);
9057 metrics->underline_thickness=1.0;
9058 if (draw_info->render == MagickFalse)
9060 if (draw_info->fill.opacity == TransparentOpacity)
9065 width=annotate_info.width;
9066 height=annotate_info.height;
9067 if ((draw_info->affine.rx != 0.0) || (draw_info->affine.ry != 0.0))
9069 if (((draw_info->affine.sx-draw_info->affine.sy) == 0.0) &&
9070 ((draw_info->affine.rx+draw_info->affine.ry) == 0.0))
9071 annotate_info.degrees=(180.0/MagickPI)*
9072 atan2(draw_info->affine.rx,draw_info->affine.sx);
9074 (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent,
9075 "%.20gx%.20g%+.20g%+.20g",(
double) width,(double) height,
9076 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9077 draw_info->interline_spacing-0.5));
9078 pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red);
9079 pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green);
9080 pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue);
9081 status=XAnnotateImage(display,&pixel,&annotate_info,image);
9084 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
9086 return(MagickFalse);
9117 MagickExport
void XRetainWindowColors(Display *display,
const Window window)
9128 assert(display != (Display *) NULL);
9129 assert(window != (Window) NULL);
9130 if (IsEventLogging() != MagickFalse)
9131 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9132 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
9133 if (property == (Atom) NULL)
9134 ThrowXWindowFatalException(XServerError,
"UnableToCreateProperty",
9136 pixmap=XCreatePixmap(display,window,1,1,1);
9137 if (pixmap == (Pixmap) NULL)
9138 ThrowXWindowFatalException(XServerError,
"UnableToCreateBitmap",
"");
9139 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9140 (
unsigned char *) &pixmap,1);
9141 (void) XSetCloseDownMode(display,RetainPermanent);
9174 static Window XSelectWindow(Display *display,
RectangleInfo *crop_info)
9176 #define MinimumCropArea (unsigned int) 9
9205 assert(display != (Display *) NULL);
9207 if (IsEventLogging() != MagickFalse)
9208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9209 root_window=XRootWindow(display,XDefaultScreen(display));
9210 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9211 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9212 context_values.function=GXinvert;
9213 context_values.plane_mask=
9214 context_values.background ^ context_values.foreground;
9215 context_values.subwindow_mode=IncludeInferiors;
9216 annotate_context=XCreateGC(display,root_window,(
size_t) (GCBackground |
9217 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9218 if (annotate_context == (GC) NULL)
9219 return(MagickFalse);
9223 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9224 XDefaultScreen(display)),(
char * )
"white",(
char * )
"black");
9225 status=XGrabPointer(display,root_window,MagickFalse,(
unsigned int)
9226 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9227 GrabModeAsync,root_window,target_cursor,CurrentTime);
9228 if (status != GrabSuccess)
9229 ThrowXWindowFatalException(XServerError,
"UnableToGrabMouse",
"");
9234 crop_info->height=0;
9236 target_window=(Window) NULL;
9239 (void) XGrabServer(display);
9242 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9243 (
void) XDrawRectangle(display,root_window,annotate_context,
9244 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9245 (
unsigned int) crop_info->height-1);
9249 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9250 (void) XWindowEvent(display,root_window,ButtonPressMask |
9251 ButtonReleaseMask | ButtonMotionMask,&event);
9252 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9253 (
void) XDrawRectangle(display,root_window,annotate_context,
9254 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9255 (
unsigned int) crop_info->height-1);
9260 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9261 event.xbutton.x,event.xbutton.y);
9262 if (target_window == (Window) NULL)
9263 target_window=root_window;
9264 x_offset=
event.xbutton.x_root;
9265 y_offset=
event.xbutton.y_root;
9266 crop_info->x=(ssize_t) x_offset;
9267 crop_info->y=(ssize_t) y_offset;
9269 crop_info->height=0;
9283 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9284 crop_info->x=(ssize_t) event.xmotion.x;
9285 crop_info->y=(ssize_t)
event.xmotion.y;
9289 if ((
int) crop_info->x < x_offset)
9290 crop_info->width=(
size_t) (x_offset-crop_info->x);
9293 crop_info->width=(size_t) (crop_info->x-x_offset);
9294 crop_info->x=(ssize_t) x_offset;
9296 if ((
int) crop_info->y < y_offset)
9297 crop_info->height=(
size_t) (y_offset-crop_info->y);
9300 crop_info->height=(size_t) (crop_info->y-y_offset);
9301 crop_info->y=(ssize_t) y_offset;
9307 }
while ((target_window == (Window) NULL) || (presses > 0));
9308 (void) XUngrabServer(display);
9309 (void) XUngrabPointer(display,CurrentTime);
9310 (void) XFreeCursor(display,target_cursor);
9311 (void) XFreeGC(display,annotate_context);
9312 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9315 crop_info->height=0;
9317 if ((crop_info->width != 0) && (crop_info->height != 0))
9318 target_window=root_window;
9319 return(target_window);
9351 MagickExport
void XSetCursorState(Display *display,XWindows *windows,
9352 const MagickStatusType state)
9354 assert(display != (Display *) NULL);
9355 assert(windows != (XWindows *) NULL);
9356 if (IsEventLogging() != MagickFalse)
9357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9360 (void) XCheckDefineCursor(display,windows->image.id,
9361 windows->image.busy_cursor);
9362 (void) XCheckDefineCursor(display,windows->pan.id,
9363 windows->pan.busy_cursor);
9364 (void) XCheckDefineCursor(display,windows->magnify.id,
9365 windows->magnify.busy_cursor);
9366 (void) XCheckDefineCursor(display,windows->command.id,
9367 windows->command.busy_cursor);
9371 (void) XCheckDefineCursor(display,windows->image.id,
9372 windows->image.cursor);
9373 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9374 (void) XCheckDefineCursor(display,windows->magnify.id,
9375 windows->magnify.cursor);
9376 (void) XCheckDefineCursor(display,windows->command.id,
9377 windows->command.cursor);
9378 (void) XCheckDefineCursor(display,windows->command.id,
9379 windows->widget.cursor);
9380 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9382 windows->info.mapped=MagickFalse;
9408 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9411 *windows = (XWindows *) NULL;
9413 if (windows_info != (XWindows *) ~0)
9415 windows=(XWindows *) RelinquishMagickMemory(windows);
9416 windows=windows_info;
9443 MagickExport
void XUserPreferences(XResourceInfo *resource_info)
9445 #if defined(X11_PREFERENCES_PATH)
9447 cache[MaxTextExtent],
9448 filename[MaxTextExtent],
9449 specifier[MaxTextExtent];
9456 preferences_database;
9461 assert(resource_info != (XResourceInfo *) NULL);
9462 client_name=GetClientName();
9463 preferences_database=XrmGetStringDatabase(
"");
9464 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.backdrop",client_name);
9465 value=resource_info->backdrop ?
"True" :
"False";
9466 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9467 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.colormap",client_name);
9468 value=resource_info->colormap == SharedColormap ?
"Shared" :
"Private";
9469 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9470 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.confirmExit",
9472 value=resource_info->confirm_exit ?
"True" :
"False";
9473 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9474 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.confirmEdit",
9476 value=resource_info->confirm_edit ?
"True" :
"False";
9477 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9478 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.displayWarnings",
9480 value=resource_info->display_warnings ?
"True" :
"False";
9481 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9482 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.dither",client_name);
9483 value=resource_info->quantize_info->dither ?
"True" :
"False";
9484 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9485 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.gammaCorrect",
9487 value=resource_info->gamma_correct ?
"True" :
"False";
9488 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9489 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.undoCache",client_name);
9490 (void) FormatLocaleString(cache,MaxTextExtent,
"%.20g",(
double)
9491 resource_info->undo_cache);
9492 XrmPutStringResource(&preferences_database,specifier,cache);
9493 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.usePixmap",client_name);
9494 value=resource_info->use_pixmap ?
"True" :
"False";
9495 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9496 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%src",
9497 X11_PREFERENCES_PATH,client_name);
9498 ExpandFilename(filename);
9499 XrmPutFileDatabase(preferences_database,filename);
9528 static const char *XVisualClassName(
const int visual_class)
9530 switch (visual_class)
9532 case StaticGray:
return(
"StaticGray");
9533 case GrayScale:
return(
"GrayScale");
9534 case StaticColor:
return(
"StaticColor");
9535 case PseudoColor:
return(
"PseudoColor");
9536 case TrueColor:
return(
"TrueColor");
9537 case DirectColor:
return(
"DirectColor");
9539 return(
"unknown visual class");
9570 MagickExport
void XWarning(
const ExceptionType magick_unused(warning),
9571 const char *reason,
const char *description)
9574 text[MaxTextExtent];
9579 magick_unreferenced(warning);
9581 if (reason == (
char *) NULL)
9583 (void) CopyMagickString(text,reason,MaxTextExtent);
9584 (void) ConcatenateMagickString(text,
":",MaxTextExtent);
9585 windows=XSetWindows((XWindows *) ~0);
9586 XNoticeWidget(windows->display,windows,text,(
char *) description);
9619 MagickExport Window XWindowByID(Display *display,
const Window root_window,
9639 assert(display != (Display *) NULL);
9640 assert(root_window != (Window) NULL);
9641 if (IsEventLogging() != MagickFalse)
9642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9644 return(XSelectWindow(display,&rectangle_info));
9645 if (root_window ==
id)
9646 return(root_window);
9647 status=XQueryTree(display,root_window,&child,&child,&children,
9649 if (status == False)
9650 return((Window) NULL);
9651 window=(Window) NULL;
9652 for (i=0; i < (int) number_children; i++)
9657 window=XWindowByID(display,children[i],
id);
9658 if (window != (Window) NULL)
9661 if (children != (Window *) NULL)
9662 (void) XFree((
void *) children);
9698 MagickExport Window XWindowByName(Display *display,
const Window root_window,
9718 assert(display != (Display *) NULL);
9719 assert(root_window != (Window) NULL);
9720 assert(name != (
char *) NULL);
9721 if (IsEventLogging() != MagickFalse)
9722 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
9723 if (XGetWMName(display,root_window,&window_name) != 0)
9724 if (LocaleCompare((
char *) window_name.value,name) == 0)
9725 return(root_window);
9726 status=XQueryTree(display,root_window,&child,&child,&children,
9728 if (status == False)
9729 return((Window) NULL);
9730 window=(Window) NULL;
9731 for (i=0; i < (int) number_children; i++)
9736 window=XWindowByName(display,children[i],name);
9737 if (window != (Window) NULL)
9740 if (children != (Window *) NULL)
9741 (void) XFree((
void *) children);
9776 MagickExport Window XWindowByProperty(Display *display,
const Window window,
9777 const Atom property)
9805 assert(display != (Display *) NULL);
9806 assert(window != (Window) NULL);
9807 assert(property != (Atom) NULL);
9808 if (IsEventLogging() != MagickFalse)
9809 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9810 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9811 if (status == False)
9812 return((Window) NULL);
9814 child=(Window) NULL;
9815 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9817 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9818 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9820 (void) XFree((
void *) data);
9821 if ((status == Success) && (type != (Atom) NULL))
9824 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9825 child=XWindowByProperty(display,children[i],property);
9826 if (children != (Window *) NULL)
9827 (
void) XFree((
void *) children);
9859 assert(image_info != (
const ImageInfo *) NULL);
9860 assert(image_info->signature == MagickCoreSignature);
9862 if (IsEventLogging() != MagickFalse)
9863 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
9864 image_info->filename);
9866 return((
Image *) NULL);
9899 MagickPrivate MagickBooleanType XRenderImage(
Image *image,
9905 (void) ThrowMagickException(&image->exception,GetMagickModule(),
9906 MissingDelegateError,
"DelegateLibrarySupportNotBuiltIn",
"`%s' (X11)",
9908 return(MagickFalse);
9930 MagickExport MagickBooleanType XComponentGenesis(
void)
9957 MagickExport
void XGetImportInfo(
XImportInfo *ximage_info)
9960 ximage_info->frame=MagickFalse;
9961 ximage_info->borders=MagickFalse;
9962 ximage_info->screen=MagickFalse;
9963 ximage_info->descend=MagickTrue;
9964 ximage_info->silent=MagickFalse;