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((QuantumScale*(double) (color)),1.0* \
110 PerceptibleReciprocal((double) blue_gamma))*(double) 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((QuantumScale*(double) (color)),1.0* \
120 PerceptibleReciprocal((double) green_gamma))*(double) QuantumRange)))
121 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
122 (color) : ((pow(((double) QuantumScale*(double) (color)),1.0* \
123 PerceptibleReciprocal((double) red_gamma))*(double) 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;
454 MagickExport MagickBooleanType XAnnotateImage(Display *display,
455 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,
Image *image)
496 assert(display != (Display *) NULL);
497 assert(pixel != (XPixelInfo *) NULL);
498 assert(annotate_info != (XAnnotateInfo *) NULL);
499 assert(image != (
Image *) NULL);
500 if (IsEventLogging() != MagickFalse)
501 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
505 root_window=XRootWindow(display,XDefaultScreen(display));
506 depth=(
unsigned int) XDefaultDepth(display,XDefaultScreen(display));
507 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
508 annotate_info->height,depth);
509 if (annotate_pixmap == (Pixmap) NULL)
514 context_values.background=0;
515 context_values.foreground=(size_t) (~0);
516 context_values.font=annotate_info->font_info->fid;
517 annotate_context=XCreateGC(display,root_window,(
unsigned long)
518 (GCBackground | GCFont | GCForeground),&context_values);
519 if (annotate_context == (GC) NULL)
524 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
525 (
int) annotate_info->font_info->ascent,annotate_info->text,
526 (int) strlen(annotate_info->text));
527 (void) XFreeGC(display,annotate_context);
531 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
532 annotate_info->height,AllPlanes,ZPixmap);
533 if (annotate_ximage == (XImage *) NULL)
535 (void) XFreePixmap(display,annotate_pixmap);
539 annotate_image=AcquireImage((
ImageInfo *) NULL);
540 if (annotate_image == (
Image *) NULL)
542 annotate_image->columns=annotate_info->width;
543 annotate_image->rows=annotate_info->height;
547 width=(
unsigned int) image->columns;
548 height=(
unsigned int) image->rows;
551 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
552 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
553 &annotate_image->background_color,&image->exception);
554 if (annotate_info->stencil == ForegroundStencil)
555 annotate_image->matte=MagickTrue;
556 exception=(&image->exception);
557 annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
558 for (y=0; y < (int) annotate_image->rows; y++)
566 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
567 annotate_image->columns,1,exception);
570 for (x=0; x < (int) annotate_image->columns; x++)
572 SetPixelOpacity(q,OpaqueOpacity);
573 if (XGetPixel(annotate_ximage,x,y) == 0)
578 SetPixelRed(q,ScaleShortToQuantum(pixel->box_color.red));
579 SetPixelGreen(q,ScaleShortToQuantum(pixel->box_color.green));
580 SetPixelBlue(q,ScaleShortToQuantum(pixel->box_color.blue));
581 if ((annotate_info->stencil == ForegroundStencil) ||
582 (annotate_info->stencil == OpaqueStencil))
583 SetPixelOpacity(q,TransparentOpacity);
590 SetPixelRed(q,ScaleShortToQuantum(pixel->pen_color.red));
591 SetPixelGreen(q,ScaleShortToQuantum(pixel->pen_color.green));
592 SetPixelBlue(q,ScaleShortToQuantum(pixel->pen_color.blue));
593 if (annotate_info->stencil == BackgroundStencil)
594 SetPixelOpacity(q,TransparentOpacity);
598 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
601 annotate_view=DestroyCacheView(annotate_view);
602 XDestroyImage(annotate_ximage);
606 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
607 if ((width != (
unsigned int) annotate_image->columns) ||
608 (height != (
unsigned int) annotate_image->rows))
611 image_geometry[MaxTextExtent];
616 (void) FormatLocaleString(image_geometry,MaxTextExtent,
"%ux%u",
618 (void) TransformImage(&annotate_image,(
char *) NULL,image_geometry);
620 if (annotate_info->degrees != 0.0)
635 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
636 if (rotate_image == (
Image *) NULL)
638 annotate_image=DestroyImage(annotate_image);
639 annotate_image=rotate_image;
643 normalized_degrees=annotate_info->degrees;
644 while (normalized_degrees < -45.0)
645 normalized_degrees+=360.0;
646 for (rotations=0; normalized_degrees > 45.0; rotations++)
647 normalized_degrees-=90.0;
648 switch (rotations % 4)
658 x-=(int) annotate_image->columns/2;
659 y+=(
int) annotate_image->columns/2;
667 x=x-(int) annotate_image->columns;
675 x=x-(int) annotate_image->columns/2;
676 y=y-(
int) (annotate_image->rows-(annotate_image->columns/2));
684 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
686 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
687 OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y);
689 annotate_image=DestroyImage(annotate_image);
726 static char **FontToList(
char *font)
741 if (font == (
char *) NULL)
742 return((
char **) NULL);
747 for (p=font; *p !=
'\0'; p++)
748 if ((*p ==
':') || (*p ==
';') || (*p ==
','))
750 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts+1UL,
sizeof(*fontlist));
751 if (fontlist == (
char **) NULL)
752 ThrowXWindowFatalException(ResourceLimitError,
"MemoryAllocationFailed",
755 for (i=0; i < (int) fonts; i++)
757 for (q=p; *q !=
'\0'; q++)
758 if ((*q ==
':') || (*q ==
';') || (*q ==
','))
760 fontlist[i]=(
char *) AcquireQuantumMemory((
size_t) (q-p)+1UL,
761 sizeof(*fontlist[i]));
762 if (fontlist[i] == (
char *) NULL)
763 ThrowXWindowFatalException(ResourceLimitError,
"MemoryAllocationFailed",
765 (void) CopyMagickString(fontlist[i],p,(
size_t) (q-p+1));
768 fontlist[i]=(
char *) NULL;
772 MagickExport XFontStruct *XBestFont(Display *display,
773 const XResourceInfo *resource_info,
const MagickBooleanType text_font)
778 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
779 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
780 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
781 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
782 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
783 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
790 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
791 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
792 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
806 font_info=(XFontStruct *) NULL;
807 font_name=resource_info->font;
808 if (text_font != MagickFalse)
809 font_name=resource_info->text_font;
810 if ((font_name != (
char *) NULL) && (*font_name !=
'\0'))
821 fontlist=FontToList(font_name);
822 if (fontlist != (
char **) NULL)
824 for (i=0; fontlist[i] != (
char *) NULL; i++)
826 if (font_info == (XFontStruct *) NULL)
827 font_info=XLoadQueryFont(display,fontlist[i]);
828 fontlist[i]=DestroyString(fontlist[i]);
830 fontlist=(
char **) RelinquishMagickMemory(fontlist);
832 if (font_info == (XFontStruct *) NULL)
833 ThrowXWindowException(XServerError,
"UnableToLoadFont",font_name);
839 if (text_font != MagickFalse)
841 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
843 while (*p != (
char *) NULL)
845 if (font_info != (XFontStruct *) NULL)
847 font_info=XLoadQueryFont(display,(
char *) *p);
880 MagickExport
void XBestIconSize(Display *display,XWindowInfo *window,
906 assert(display != (Display *) NULL);
907 assert(window != (XWindowInfo *) NULL);
908 assert(image != (
Image *) NULL);
909 if (IsEventLogging() != MagickFalse)
910 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
911 window->width=MaxIconSize;
912 window->height=MaxIconSize;
913 icon_size=(XIconSize *) NULL;
915 root_window=XRootWindow(display,window->screen);
916 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
917 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
919 if (icon_size == (XIconSize *) NULL)
924 icon_size=XAllocIconSize();
925 if (icon_size == (XIconSize *) NULL)
926 ThrowXWindowFatalException(ResourceLimitError,
927 "MemoryAllocationFailed",image->filename);
928 icon_size->min_width=1;
929 icon_size->max_width=MaxIconSize;
930 icon_size->min_height=1;
931 icon_size->max_height=MaxIconSize;
932 icon_size->width_inc=1;
933 icon_size->height_inc=1;
938 width=(
unsigned int) image->columns;
939 height=(
unsigned int) image->rows;
941 if (window->crop_geometry)
942 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
946 scale_factor=(MagickRealType) icon_size->max_width/width;
947 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
948 scale_factor=(MagickRealType) icon_size->max_height/height;
949 icon_width=(
unsigned int) icon_size->min_width;
950 while ((
int) icon_width < icon_size->max_width)
952 if (icon_width >= (
unsigned int) (scale_factor*width+0.5))
954 icon_width+=icon_size->width_inc;
956 icon_height=(
unsigned int) icon_size->min_height;
957 while ((
int) icon_height < icon_size->max_height)
959 if (icon_height >= (
unsigned int) (scale_factor*height+0.5))
961 icon_height+=icon_size->height_inc;
963 (void) XFree((
void *) icon_size);
964 window->width=icon_width;
965 window->height=icon_height;
1006 MagickExport
void XBestPixel(Display *display,
const Colormap colormap,
1007 XColor *colors,
unsigned int number_colors,XColor *color)
1031 assert(display != (Display *) NULL);
1032 assert(color != (XColor *) NULL);
1033 if (IsEventLogging() != MagickFalse)
1034 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1035 status=XAllocColor(display,colormap,color);
1036 if (status != False)
1038 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1039 if (query_server != MagickFalse)
1044 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
1045 if (colors == (XColor *) NULL)
1046 ThrowXWindowFatalException(ResourceLimitError,
1047 "MemoryAllocationFailed",
"...");
1048 for (i=0; i < (int) number_colors; i++)
1049 colors[i].pixel=(
size_t) i;
1050 if (number_colors > 256)
1052 (void) XQueryColors(display,colormap,colors,(
int) number_colors);
1054 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1057 for (i=0; i < (int) number_colors; i++)
1059 pixel.red=colors[i].red-(MagickRealType) color->red;
1060 distance=pixel.red*pixel.red;
1061 if (distance > min_distance)
1063 pixel.green=colors[i].green-(MagickRealType) color->green;
1064 distance+=pixel.green*pixel.green;
1065 if (distance > min_distance)
1067 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1068 distance+=pixel.blue*pixel.blue;
1069 if (distance > min_distance)
1071 min_distance=distance;
1072 color->pixel=colors[i].pixel;
1075 (void) XAllocColor(display,colormap,&colors[j]);
1076 if (query_server != MagickFalse)
1077 colors=(XColor *) RelinquishMagickMemory(colors);
1125 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1126 XStandardColormap *map_info,XResourceInfo *resource_info)
1128 #define MaxStandardColormaps 7
1129 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1130 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1131 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1132 (unsigned long) visual_info->colormap_size),1UL << visual_info->depth)
1160 assert(display != (Display *) NULL);
1161 assert(map_info != (XStandardColormap *) NULL);
1162 assert(resource_info != (XResourceInfo *) NULL);
1163 if (IsEventLogging() != MagickFalse)
1164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1165 map_type=resource_info->map_type;
1166 visual_type=resource_info->visual_type;
1167 visual_mask=VisualScreenMask;
1168 visual_template.screen=XDefaultScreen(display);
1169 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1171 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1172 if (resource_info->colors <= (one << (
size_t) visual_template.depth))
1173 visual_mask|=VisualDepthMask;
1174 if (visual_type != (
char *) NULL)
1179 if (LocaleCompare(
"staticgray",visual_type) == 0)
1181 visual_mask|=VisualClassMask;
1182 visual_template.klass=StaticGray;
1185 if (LocaleCompare(
"grayscale",visual_type) == 0)
1187 visual_mask|=VisualClassMask;
1188 visual_template.klass=GrayScale;
1191 if (LocaleCompare(
"staticcolor",visual_type) == 0)
1193 visual_mask|=VisualClassMask;
1194 visual_template.klass=StaticColor;
1197 if (LocaleCompare(
"pseudocolor",visual_type) == 0)
1199 visual_mask|=VisualClassMask;
1200 visual_template.klass=PseudoColor;
1203 if (LocaleCompare(
"truecolor",visual_type) == 0)
1205 visual_mask|=VisualClassMask;
1206 visual_template.klass=TrueColor;
1209 if (LocaleCompare(
"directcolor",visual_type) == 0)
1211 visual_mask|=VisualClassMask;
1212 visual_template.klass=DirectColor;
1215 if (LocaleCompare(
"default",visual_type) == 0)
1217 visual_mask|=VisualIDMask;
1218 visual_template.visualid=XVisualIDFromVisual(
1219 XDefaultVisual(display,XDefaultScreen(display)));
1222 if (isdigit((
int) ((
unsigned char) *visual_type)) != 0)
1224 visual_mask|=VisualIDMask;
1225 visual_template.visualid=
1226 strtol(visual_type,(
char **) NULL,0);
1229 ThrowXWindowException(XServerError,
1230 "UnrecognizedVisualSpecifier",visual_type);
1236 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1238 visual_mask=VisualScreenMask | VisualIDMask;
1239 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1244 ThrowXWindowException(XServerWarning,
"UnableToGetVisual",visual_type);
1245 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1246 XDefaultScreen(display)));
1247 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1249 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1250 return((XVisualInfo *) NULL);
1251 ThrowXWindowException(XServerWarning,
"UsingDefaultVisual",
1252 XVisualClassName(visual_list->klass));
1254 resource_info->color_recovery=MagickFalse;
1255 if ((map_info != (XStandardColormap *) NULL) && (map_type != (
char *) NULL))
1261 map_name[MaxTextExtent];
1279 map_list=(XStandardColormap *) NULL;
1280 root_window=XRootWindow(display,XDefaultScreen(display));
1283 if (LocaleCompare(map_type,
"list") != 0)
1288 (void) FormatLocaleString((
char *) map_name,MaxTextExtent,
1289 "RGB_%s_MAP",map_type);
1290 LocaleUpper(map_name);
1291 map_property=XInternAtom(display,(
char *) map_name,MagickTrue);
1292 if (map_property != (Atom) NULL)
1293 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1299 *colormap[MaxStandardColormaps]=
1301 "_HP_RGB_SMOOTH_MAP_LIST",
1313 for (i=0; i < MaxStandardColormaps; i++)
1315 map_property=XInternAtom(display,(
char *) colormap[i],MagickTrue);
1316 if (map_property == (Atom) NULL)
1318 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1320 if (status != False)
1323 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1325 if (status == False)
1326 ThrowXWindowFatalException(XServerError,
"UnableToGetStandardColormap",
1331 *map_info=map_list[0];
1332 #if !defined(PRE_R4_ICCCM)
1333 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1334 for (i=0; i < number_maps; i++)
1335 for (j=0; j < number_visuals; j++)
1336 if (map_list[i].visualid ==
1337 XVisualIDFromVisual(visual_list[j].visual))
1339 *map_info=map_list[i];
1340 visual_template.visualid=XVisualIDFromVisual(
1341 visual_list[j].visual);
1344 if (map_info->visualid != visual_template.visualid)
1345 ThrowXWindowFatalException(XServerError,
1346 "UnableToMatchVisualToStandardColormap",map_type);
1348 if (map_info->colormap == (Colormap) NULL)
1349 ThrowXWindowFatalException(XServerError,
1350 "StandardColormapIsNotInitialized",map_type);
1351 (void) XFree((
void *) map_list);
1355 static const unsigned int
1372 visual_info=visual_list;
1374 for (i=1; i < number_visuals; i++)
1377 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1380 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1381 if (rank[p->klass] > rank[visual_info->klass])
1384 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1386 (void) XFree((
void *) visual_list);
1390 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1392 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1393 return((XVisualInfo *) NULL);
1394 return(visual_info);
1424 MagickExport
int XCheckDefineCursor(Display *display,Window window,
1427 assert(display != (Display *) NULL);
1428 if (IsEventLogging() != MagickFalse)
1429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1430 if (window == XRootWindow(display,XDefaultScreen(display)))
1432 return(XDefineCursor(display,window,cursor));
1461 MagickExport
void XCheckRefreshWindows(Display *display,XWindows *windows)
1469 assert(display != (Display *) NULL);
1470 assert(windows != (XWindows *) NULL);
1471 if (IsEventLogging() != MagickFalse)
1472 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1473 XDelay(display,SuspendTime);
1474 id=windows->command.id;
1475 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1476 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1477 id=windows->image.id;
1478 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1479 XRefreshWindow(display,&windows->image,&event);
1480 XDelay(display,SuspendTime << 1);
1481 id=windows->command.id;
1482 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1483 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1484 id=windows->image.id;
1485 while (XCheckTypedWindowEvent(display,
id,Expose,&event) != MagickFalse)
1486 XRefreshWindow(display,&windows->image,&event);
1521 MagickExport
void XClientMessage(Display *display,
const Window window,
1522 const Atom protocol,
const Atom reason,
const Time timestamp)
1527 assert(display != (Display *) NULL);
1528 (void) memset(&client_event,0,
sizeof(client_event));
1529 client_event.type=ClientMessage;
1530 client_event.window=window;
1531 client_event.message_type=protocol;
1532 client_event.format=32;
1533 client_event.data.l[0]=(long) reason;
1534 client_event.data.l[1]=(long) timestamp;
1535 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1569 static Window XClientWindow(Display *display,Window target_window)
1591 assert(display != (Display *) NULL);
1592 if (IsEventLogging() != MagickFalse)
1593 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1594 state=XInternAtom(display,
"WM_STATE",MagickTrue);
1595 if (state == (Atom) NULL)
1596 return(target_window);
1598 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1599 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1600 if ((status == Success) && (type != (Atom) NULL))
1601 return(target_window);
1602 client_window=XWindowByProperty(display,target_window,state);
1603 if (client_window == (Window) NULL)
1604 return(target_window);
1605 return(client_window);
1626 MagickExport
void XComponentTerminus(
void)
1628 DestroyXResources();
1661 MagickExport
void XConfigureImageColormap(Display *display,
1662 XResourceInfo *resource_info,XWindows *windows,
Image *image)
1670 XSetCursorState(display,windows,MagickTrue);
1671 XCheckRefreshWindows(display,windows);
1672 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1673 windows->map_info,windows->pixel_info);
1674 colormap=windows->map_info->colormap;
1675 (void) XSetWindowColormap(display,windows->image.id,colormap);
1676 (void) XSetWindowColormap(display,windows->command.id,colormap);
1677 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1678 if (windows->magnify.mapped != MagickFalse)
1679 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1680 if (windows->pan.mapped != MagickFalse)
1681 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1682 XSetCursorState(display,windows,MagickFalse);
1683 XClientMessage(display,windows->image.id,windows->im_protocols,
1684 windows->im_update_colormap,CurrentTime);
1713 MagickExport
void XConstrainWindowPosition(Display *display,
1714 XWindowInfo *window_info)
1719 assert(display != (Display *) NULL);
1720 assert(window_info != (XWindowInfo *) NULL);
1721 if (IsEventLogging() != MagickFalse)
1722 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1723 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1724 if (window_info->x < 0)
1727 if (window_info->x > (
int) limit)
1728 window_info->x=(int) limit;
1729 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1730 if (window_info->y < 0)
1733 if (window_info->y > limit)
1734 window_info->y=limit;
1764 MagickExport
void XDelay(Display *display,
const size_t milliseconds)
1766 assert(display != (Display *) NULL);
1767 (void) XFlush(display);
1768 MagickDelay(milliseconds);
1794 MagickExport
void XDestroyResourceInfo(XResourceInfo *resource_info)
1796 if (resource_info->image_geometry != (
char *) NULL)
1797 resource_info->image_geometry=(
char *)
1798 RelinquishMagickMemory(resource_info->image_geometry);
1799 if (resource_info->quantize_info != (
QuantizeInfo *) NULL)
1800 resource_info->quantize_info=DestroyQuantizeInfo(
1801 resource_info->quantize_info);
1802 if (resource_info->client_name != (
char *) NULL)
1803 resource_info->client_name=(
char *)
1804 RelinquishMagickMemory(resource_info->client_name);
1805 if (resource_info->name != (
char *) NULL)
1806 resource_info->name=DestroyString(resource_info->name);
1807 (void) memset(resource_info,0,
sizeof(*resource_info));
1836 MagickExport
void XDestroyWindowColors(Display *display,Window window)
1858 assert(display != (Display *) NULL);
1859 if (IsEventLogging() != MagickFalse)
1860 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1861 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
1862 if (property == (Atom) NULL)
1863 ThrowXWindowFatalException(XServerError,
"UnableToCreateProperty",
1865 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1866 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1867 if (status != Success)
1869 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1871 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1872 (void) XDeleteProperty(display,window,property);
1875 (void) XFree((
void *) data);
1911 MagickExport
void XDisplayImageInfo(Display *display,
1912 const XResourceInfo *resource_info,XWindows *windows,
Image *undo_image,
1916 filename[MaxTextExtent],
1941 assert(display != (Display *) NULL);
1942 assert(resource_info != (XResourceInfo *) NULL);
1943 assert(windows != (XWindows *) NULL);
1944 assert(image != (
Image *) NULL);
1945 if (IsEventLogging() != MagickFalse)
1946 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1948 unique_file=AcquireUniqueFileResource(filename);
1949 if (unique_file != -1)
1950 file=fdopen(unique_file,
"w");
1951 if ((unique_file == -1) || (file == (FILE *) NULL))
1953 XNoticeWidget(display,windows,
"Unable to display image info",filename);
1956 if (resource_info->gamma_correct != MagickFalse)
1957 if (resource_info->display_gamma != (
char *) NULL)
1958 (void) FormatLocaleFile(file,
"Display\n gamma: %s\n\n",
1959 resource_info->display_gamma);
1963 (void) FormatLocaleFile(file,
"X\n visual: %s\n",
1964 XVisualClassName((
int) windows->image.storage_class));
1965 (void) FormatLocaleFile(file,
" depth: %d\n",windows->image.ximage->depth);
1966 if (windows->visual_info->colormap_size != 0)
1967 (void) FormatLocaleFile(file,
" colormap size: %d\n",
1968 windows->visual_info->colormap_size);
1969 if (resource_info->colormap== SharedColormap)
1970 (void) FormatLocaleFile(file,
" colormap type: Shared\n");
1972 (
void) FormatLocaleFile(file,
" colormap type: Private\n");
1973 (void) FormatLocaleFile(file,
" geometry: %dx%d\n",
1974 windows->image.ximage->width,windows->image.ximage->height);
1975 if (windows->image.crop_geometry != (
char *) NULL)
1976 (
void) FormatLocaleFile(file,
" crop geometry: %s\n",
1977 windows->image.crop_geometry);
1978 if (windows->image.pixmap == (Pixmap) NULL)
1979 (void) FormatLocaleFile(file,
" type: X Image\n");
1981 (
void) FormatLocaleFile(file,
" type: Pixmap\n");
1982 if (windows->image.shape != MagickFalse)
1983 (void) FormatLocaleFile(file,
" non-rectangular shape: True\n");
1985 (
void) FormatLocaleFile(file,
" non-rectangular shape: False\n");
1986 if (windows->image.shared_memory != MagickFalse)
1987 (void) FormatLocaleFile(file,
" shared memory: True\n");
1989 (
void) FormatLocaleFile(file,
" shared memory: False\n");
1990 (void) FormatLocaleFile(file,
"\n");
1991 if (resource_info->font != (
char *) NULL)
1992 (
void) FormatLocaleFile(file,
"Font: %s\n\n",resource_info->font);
1993 if (resource_info->text_font != (
char *) NULL)
1994 (void) FormatLocaleFile(file,
"Text font: %s\n\n",resource_info->text_font);
1999 for (levels=0; undo_image != (
Image *) NULL; levels++)
2001 number_pixels=undo_image->list->columns*undo_image->list->rows;
2003 undo_image=GetPreviousImageInList(undo_image);
2005 (void) FormatLocaleFile(file,
"Undo Edit Cache\n levels: %u\n",levels);
2006 (void) FormatLocaleFile(file,
" bytes: %.20gmb\n",(
double)
2007 ((bytes+(1 << 19)) >> 20));
2008 (void) FormatLocaleFile(file,
" limit: %.20gmb\n\n",(
double)
2009 resource_info->undo_cache);
2013 (void) IdentifyImage(image,file,MagickTrue);
2014 (void) fclose(file);
2015 text=FileToString(filename,~0UL,&image->exception);
2016 (void) RelinquishUniqueFileResource(filename);
2017 if (text == (
char *) NULL)
2019 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
2020 "UnableToDisplayImageInfo");
2023 textlist=StringToList(text);
2024 if (textlist != (
char **) NULL)
2027 title[MaxTextExtent];
2032 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2033 (void) FormatLocaleString(title,MaxTextExtent,
"Image Info: %s",
2035 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2036 (
char const **) textlist);
2037 for (i=0; textlist[i] != (
char *) NULL; i++)
2038 textlist[i]=DestroyString(textlist[i]);
2039 textlist=(
char **) RelinquishMagickMemory(textlist);
2041 text=DestroyString(text);
2072 static void XDitherImage(
Image *image,XImage *ximage)
2074 static const short int
2077 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2078 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2080 dither_green[2][16]=
2082 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2083 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2087 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2088 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2126 for (i=0; i < 2; i++)
2127 for (j=0; j < 16; j++)
2129 red_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2131 green_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2132 sizeof(*green_map));
2133 blue_map[i][j]=(
unsigned char *) AcquireCriticalMemory(256UL*
2139 for (i=0; i < 2; i++)
2140 for (j=0; j < 16; j++)
2141 for (x=0; x < 256; x++)
2146 value+=dither_red[i][j];
2147 red_map[i][j][x]=(
unsigned char)
2148 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2152 value+=dither_green[i][j];
2153 green_map[i][j][x]=(
unsigned char)
2154 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2158 value+=((size_t) dither_blue[i][j] << 1);
2159 blue_map[i][j][x]=(
unsigned char)
2160 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2165 scanline_pad=(
unsigned int) (ximage->bytes_per_line-
2166 ((
size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2170 image_view=AcquireVirtualCacheView(image,&image->exception);
2171 for (y=0; y < (int) image->rows; y++)
2173 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2177 for (x=0; x < (int) image->columns; x++)
2179 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(
int)
2180 ScaleQuantumToChar(GetPixelRed(p))] << 8));
2181 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(
int)
2182 ScaleQuantumToChar(GetPixelGreen(p))] << 8));
2183 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(
int)
2184 ScaleQuantumToChar(GetPixelBlue(p))] << 8));
2185 pixel=(size_t) (((
size_t) color.red & 0xe0) |
2186 (((size_t) color.green & 0xe0) >> 3) |
2187 (((
size_t) color.blue & 0xc0) >> 6));
2199 image_view=DestroyCacheView(image_view);
2203 for (i=0; i < 2; i++)
2204 for (j=0; j < 16; j++)
2206 green_map[i][j]=(
unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2207 blue_map[i][j]=(
unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2208 red_map[i][j]=(
unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2241 MagickExport MagickBooleanType XDrawImage(Display *display,
2242 const XPixelInfo *pixel,XDrawInfo *draw_info,
Image *image)
2283 assert(display != (Display *) NULL);
2284 assert(pixel != (XPixelInfo *) NULL);
2285 assert(draw_info != (XDrawInfo *) NULL);
2286 assert(image != (
Image *) NULL);
2287 if (IsEventLogging() != MagickFalse)
2288 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2292 root_window=XRootWindow(display,XDefaultScreen(display));
2293 depth=(
unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2294 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2295 draw_info->height,depth);
2296 if (draw_pixmap == (Pixmap) NULL)
2297 return(MagickFalse);
2301 context_values.background=(size_t) (~0);
2302 context_values.foreground=0;
2303 context_values.line_width=(int) draw_info->line_width;
2304 draw_context=XCreateGC(display,root_window,(
size_t)
2305 (GCBackground | GCForeground | GCLineWidth),&context_values);
2306 if (draw_context == (GC) NULL)
2307 return(MagickFalse);
2311 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2316 (void) XSetBackground(display,draw_context,0);
2317 (void) XSetForeground(display,draw_context,(
size_t) (~0));
2318 if (draw_info->stipple != (Pixmap) NULL)
2320 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2321 (void) XSetStipple(display,draw_context,draw_info->stipple);
2323 switch (draw_info->element)
2328 (void) XDrawLines(display,draw_pixmap,draw_context,
2329 draw_info->coordinate_info,(
int) draw_info->number_coordinates,
2335 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2336 draw_info->line_info.y1,draw_info->line_info.x2,
2337 draw_info->line_info.y2);
2340 case RectangleElement:
2342 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2343 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2344 (
unsigned int) draw_info->rectangle_info.width,
2345 (
unsigned int) draw_info->rectangle_info.height);
2348 case FillRectangleElement:
2350 (void) XFillRectangle(display,draw_pixmap,draw_context,
2351 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2352 (
unsigned int) draw_info->rectangle_info.width,
2353 (
unsigned int) draw_info->rectangle_info.height);
2357 case EllipseElement:
2359 (void) XDrawArc(display,draw_pixmap,draw_context,
2360 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2361 (
unsigned int) draw_info->rectangle_info.width,
2362 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2365 case FillCircleElement:
2366 case FillEllipseElement:
2368 (void) XFillArc(display,draw_pixmap,draw_context,
2369 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2370 (
unsigned int) draw_info->rectangle_info.width,
2371 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2374 case PolygonElement:
2379 coordinate_info=draw_info->coordinate_info;
2380 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2381 (
int) draw_info->number_coordinates,CoordModeOrigin);
2382 (void) XDrawLine(display,draw_pixmap,draw_context,
2383 coordinate_info[draw_info->number_coordinates-1].x,
2384 coordinate_info[draw_info->number_coordinates-1].y,
2385 coordinate_info[0].x,coordinate_info[0].y);
2388 case FillPolygonElement:
2390 (void) XFillPolygon(display,draw_pixmap,draw_context,
2391 draw_info->coordinate_info,(
int) draw_info->number_coordinates,Complex,
2396 (void) XFreeGC(display,draw_context);
2400 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2401 draw_info->height,AllPlanes,ZPixmap);
2402 if (draw_ximage == (XImage *) NULL)
2403 return(MagickFalse);
2404 (void) XFreePixmap(display,draw_pixmap);
2408 draw_image=AcquireImage((
ImageInfo *) NULL);
2409 if (draw_image == (
Image *) NULL)
2410 return(MagickFalse);
2411 draw_image->columns=draw_info->width;
2412 draw_image->rows=draw_info->height;
2416 width=(
unsigned int) image->columns;
2417 height=(
unsigned int) image->rows;
2420 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2421 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
2422 &draw_image->background_color,&image->exception);
2423 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2424 return(MagickFalse);
2425 draw_image->matte=MagickTrue;
2426 exception=(&image->exception);
2427 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2428 for (y=0; y < (int) draw_image->rows; y++)
2436 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2440 for (x=0; x < (int) draw_image->columns; x++)
2442 if (XGetPixel(draw_ximage,x,y) == 0)
2447 *q=draw_image->background_color;
2448 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2449 TransparentOpacity : OpaqueOpacity);
2456 SetPixelRed(q,ScaleShortToQuantum(pixel->pen_color.red));
2457 SetPixelGreen(q,ScaleShortToQuantum(pixel->pen_color.green));
2458 SetPixelBlue(q,ScaleShortToQuantum(pixel->pen_color.blue));
2459 SetPixelOpacity(q,(Quantum) (draw_info->stencil ==
2460 OpaqueStencil ? OpaqueOpacity : TransparentOpacity));
2464 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2467 draw_view=DestroyCacheView(draw_view);
2468 XDestroyImage(draw_ximage);
2472 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2473 if ((width != (
unsigned int) draw_image->columns) ||
2474 (height != (
unsigned int) draw_image->rows))
2477 image_geometry[MaxTextExtent];
2482 (void) FormatLocaleString(image_geometry,MaxTextExtent,
"%ux%u",
2484 (void) TransformImage(&draw_image,(
char *) NULL,image_geometry);
2486 if (draw_info->degrees != 0.0)
2500 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2501 if (rotate_image == (
Image *) NULL)
2502 return(MagickFalse);
2503 draw_image=DestroyImage(draw_image);
2504 draw_image=rotate_image;
2508 normalized_degrees=draw_info->degrees;
2509 while (normalized_degrees < -45.0)
2510 normalized_degrees+=360.0;
2511 for (rotations=0; normalized_degrees > 45.0; rotations++)
2512 normalized_degrees-=90.0;
2513 switch (rotations % 4)
2523 x=x-(int) draw_image->columns/2;
2524 y=y+(
int) draw_image->columns/2;
2532 x=x-(int) draw_image->columns;
2540 x=x-(int) draw_image->columns/2;
2541 y=y-(
int) (draw_image->rows-(draw_image->columns/2));
2549 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2550 for (y=0; y < (int) draw_image->rows; y++)
2558 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2562 for (x=0; x < (int) draw_image->columns; x++)
2564 if (q->opacity != (Quantum) TransparentOpacity)
2565 SetPixelOpacity(q,OpaqueOpacity);
2568 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2571 draw_view=DestroyCacheView(draw_view);
2572 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2573 if (draw_info->stencil == TransparentStencil)
2574 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
2579 (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2583 draw_image=DestroyImage(draw_image);
2616 #if defined(__cplusplus) || defined(c_plusplus)
2620 MagickExport
int XError(Display *display,XErrorEvent *error)
2622 assert(display != (Display *) NULL);
2623 assert(error != (XErrorEvent *) NULL);
2624 if (IsEventLogging() != MagickFalse)
2625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2627 xerror_alert=MagickTrue;
2628 switch (error->request_code)
2632 if ((
int) error->error_code == BadDrawable)
2633 return(MagickFalse);
2636 case X_GetWindowAttributes:
2639 if ((
int) error->error_code == BadWindow)
2640 return(MagickFalse);
2645 if ((
int) error->error_code == BadValue)
2646 return(MagickFalse);
2653 #if defined(__cplusplus) || defined(c_plusplus)
2697 MagickExport
void XFreeResources(Display *display,XVisualInfo *visual_info,
2698 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2699 XResourceInfo *resource_info,XWindowInfo *window_info)
2701 assert(display != (Display *) NULL);
2702 assert(resource_info != (XResourceInfo *) NULL);
2703 if (IsEventLogging() != MagickFalse)
2704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2705 if (window_info != (XWindowInfo *) NULL)
2710 if (window_info->ximage != (XImage *) NULL)
2711 XDestroyImage(window_info->ximage);
2712 if (window_info->id != (Window) NULL)
2717 if (window_info->id != XRootWindow(display,visual_info->screen))
2718 (
void) XDestroyWindow(display,window_info->id);
2719 if (window_info->annotate_context != (GC) NULL)
2720 (void) XFreeGC(display,window_info->annotate_context);
2721 if (window_info->highlight_context != (GC) NULL)
2722 (
void) XFreeGC(display,window_info->highlight_context);
2723 if (window_info->widget_context != (GC) NULL)
2724 (void) XFreeGC(display,window_info->widget_context);
2725 if (window_info->cursor != (Cursor) NULL)
2726 (
void) XFreeCursor(display,window_info->cursor);
2727 window_info->cursor=(Cursor) NULL;
2728 if (window_info->busy_cursor != (Cursor) NULL)
2729 (
void) XFreeCursor(display,window_info->busy_cursor);
2730 window_info->busy_cursor=(Cursor) NULL;
2736 if (font_info != (XFontStruct *) NULL)
2738 (void) XFreeFont(display,font_info);
2739 font_info=(XFontStruct *) NULL;
2741 if (map_info != (XStandardColormap *) NULL)
2746 if (resource_info->map_type == (
char *) NULL)
2747 (
void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2748 (void) XFree((
void *) map_info);
2753 if (visual_info != (XVisualInfo *) NULL)
2754 (
void) XFree((
void *) visual_info);
2755 if (resource_info->close_server != MagickFalse)
2756 (void) XCloseDisplay(display);
2792 MagickExport
void XFreeStandardColormap(Display *display,
2793 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2798 assert(display != (Display *) NULL);
2799 assert(visual_info != (XVisualInfo *) NULL);
2800 assert(map_info != (XStandardColormap *) NULL);
2801 if (IsEventLogging() != MagickFalse)
2802 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2803 (void) XFlush(display);
2804 if (map_info->colormap != (Colormap) NULL)
2806 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2807 (
void) XFreeColormap(display,map_info->colormap);
2809 if (pixel != (XPixelInfo *) NULL)
2810 if ((visual_info->klass != TrueColor) &&
2811 (visual_info->klass != DirectColor))
2812 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2813 (
int) pixel->colors,0);
2815 map_info->colormap=(Colormap) NULL;
2816 if (pixel != (XPixelInfo *) NULL)
2818 if (pixel->pixels != (
unsigned long *) NULL)
2819 pixel->pixels=(
unsigned long *) RelinquishMagickMemory(pixel->pixels);
2820 pixel->pixels=(
unsigned long *) NULL;
2846 MagickExport
void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2851 assert(annotate_info != (XAnnotateInfo *) NULL);
2852 if (IsEventLogging() != MagickFalse)
2853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2856 annotate_info->width=0;
2857 annotate_info->height=0;
2858 annotate_info->stencil=ForegroundStencil;
2859 annotate_info->degrees=0.0;
2860 annotate_info->font_info=(XFontStruct *) NULL;
2861 annotate_info->text=(
char *) NULL;
2862 *annotate_info->geometry=
'\0';
2863 annotate_info->previous=(XAnnotateInfo *) NULL;
2864 annotate_info->next=(XAnnotateInfo *) NULL;
2865 (void) XSupportsLocale();
2866 (void) XSetLocaleModifiers(
"");
2897 MagickExport
void XGetMapInfo(
const XVisualInfo *visual_info,
2898 const Colormap colormap,XStandardColormap *map_info)
2903 assert(visual_info != (XVisualInfo *) NULL);
2904 assert(map_info != (XStandardColormap *) NULL);
2905 if (IsEventLogging() != MagickFalse)
2906 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2907 map_info->colormap=colormap;
2908 map_info->red_max=visual_info->red_mask;
2909 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2910 if (map_info->red_max != 0)
2911 while ((map_info->red_max & 0x01) == 0)
2913 map_info->red_max>>=1;
2914 map_info->red_mult<<=1;
2916 map_info->green_max=visual_info->green_mask;
2917 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2918 if (map_info->green_max != 0)
2919 while ((map_info->green_max & 0x01) == 0)
2921 map_info->green_max>>=1;
2922 map_info->green_mult<<=1;
2924 map_info->blue_max=visual_info->blue_mask;
2925 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2926 if (map_info->blue_max != 0)
2927 while ((map_info->blue_max & 0x01) == 0)
2929 map_info->blue_max>>=1;
2930 map_info->blue_mult<<=1;
2932 map_info->base_pixel=0;
2973 MagickExport
void XGetPixelPacket(Display *display,
2974 const XVisualInfo *visual_info,
const XStandardColormap *map_info,
2975 const XResourceInfo *resource_info,
Image *image,XPixelInfo *pixel)
2978 *PenColors[MaxNumberPens]=
3008 assert(display != (Display *) NULL);
3009 assert(visual_info != (XVisualInfo *) NULL);
3010 assert(map_info != (XStandardColormap *) NULL);
3011 assert(resource_info != (XResourceInfo *) NULL);
3012 assert(pixel != (XPixelInfo *) NULL);
3013 if (IsEventLogging() != MagickFalse)
3014 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3016 if (image != (
Image *) NULL)
3017 if (image->storage_class == PseudoClass)
3018 pixel->colors=(ssize_t) image->colors;
3019 packets=(
unsigned int)
3020 MagickMax((
int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3021 if (pixel->pixels != (
unsigned long *) NULL)
3022 pixel->pixels=(
unsigned long *) RelinquishMagickMemory(pixel->pixels);
3023 pixel->pixels=(
unsigned long *) AcquireQuantumMemory(packets,
3024 sizeof(*pixel->pixels));
3025 if (pixel->pixels == (
unsigned long *) NULL)
3026 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToGetPixelInfo",
3031 colormap=map_info->colormap;
3032 (void) XParseColor(display,colormap,(
char *) ForegroundColor,
3033 &pixel->foreground_color);
3034 status=XParseColor(display,colormap,resource_info->foreground_color,
3035 &pixel->foreground_color);
3036 if (status == False)
3037 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3038 resource_info->foreground_color);
3039 pixel->foreground_color.pixel=
3040 XStandardPixel(map_info,&pixel->foreground_color);
3041 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3045 (void) XParseColor(display,colormap,
"#d6d6d6d6d6d6",&pixel->background_color);
3046 status=XParseColor(display,colormap,resource_info->background_color,
3047 &pixel->background_color);
3048 if (status == False)
3049 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3050 resource_info->background_color);
3051 pixel->background_color.pixel=
3052 XStandardPixel(map_info,&pixel->background_color);
3053 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3057 (void) XParseColor(display,colormap,(
char *) BorderColor,
3058 &pixel->border_color);
3059 status=XParseColor(display,colormap,resource_info->border_color,
3060 &pixel->border_color);
3061 if (status == False)
3062 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3063 resource_info->border_color);
3064 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3065 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3069 pixel->matte_color=pixel->background_color;
3070 if (resource_info->matte_color != (
char *) NULL)
3075 status=XParseColor(display,colormap,resource_info->matte_color,
3076 &pixel->matte_color);
3077 if (status == False)
3078 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3079 resource_info->matte_color);
3080 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3081 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3086 pixel->highlight_color.red=(
unsigned short) (((MagickRealType)
3087 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3088 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3089 pixel->highlight_color.green=(
unsigned short) (((MagickRealType)
3090 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3091 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3092 pixel->highlight_color.blue=(
unsigned short) (((MagickRealType)
3093 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3094 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3095 pixel->highlight_color.pixel=
3096 XStandardPixel(map_info,&pixel->highlight_color);
3097 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3101 pixel->shadow_color.red=(
unsigned short) (((MagickRealType)
3102 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3103 pixel->shadow_color.green=(
unsigned short) (((MagickRealType)
3104 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3105 pixel->shadow_color.blue=(
unsigned short) (((MagickRealType)
3106 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3107 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3108 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3112 pixel->depth_color.red=(
unsigned short) (((MagickRealType)
3113 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3114 pixel->depth_color.green=(
unsigned short) (((MagickRealType)
3115 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3116 pixel->depth_color.blue=(
unsigned short) (((MagickRealType)
3117 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3118 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3119 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3123 pixel->trough_color.red=(
unsigned short) (((MagickRealType)
3124 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3125 pixel->trough_color.green=(
unsigned short) (((MagickRealType)
3126 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3127 pixel->trough_color.blue=(
unsigned short) (((MagickRealType)
3128 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3129 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3130 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3134 for (i=0; i < MaxNumberPens; i++)
3136 (void) XParseColor(display,colormap,(
char *) PenColors[i],
3137 &pixel->pen_colors[i]);
3138 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3139 &pixel->pen_colors[i]);
3140 if (status == False)
3141 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",
3142 resource_info->pen_colors[i]);
3143 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3144 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3146 pixel->box_color=pixel->background_color;
3147 pixel->pen_color=pixel->foreground_color;
3150 if (image != (
Image *) NULL)
3152 if ((resource_info->gamma_correct != MagickFalse) &&
3153 (image->gamma != 0.0))
3164 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3165 if ((flags & RhoValue) != 0)
3166 red_gamma=geometry_info.rho;
3167 green_gamma=red_gamma;
3168 if ((flags & SigmaValue) != 0)
3169 green_gamma=geometry_info.sigma;
3170 blue_gamma=red_gamma;
3171 if ((flags & XiValue) != 0)
3172 blue_gamma=geometry_info.xi;
3173 red_gamma*=image->gamma;
3174 green_gamma*=image->gamma;
3175 blue_gamma*=image->gamma;
3177 if (image->storage_class == PseudoClass)
3182 for (i=0; i < (ssize_t) image->colors; i++)
3183 pixel->pixels[i]=XGammaPixel(map_info,image->colormap+i);
3184 for (i=0; i < MaxNumberPens; i++)
3185 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3186 pixel->colors+=MaxNumberPens;
3225 MagickExport
char *XGetResourceClass(XrmDatabase database,
3226 const char *client_name,
const char *keyword,
char *resource_default)
3229 resource_class[MaxTextExtent],
3230 resource_name[MaxTextExtent];
3241 if (database == (XrmDatabase) NULL)
3242 return(resource_default);
3243 *resource_name=
'\0';
3244 *resource_class=
'\0';
3245 if (keyword != (
char *) NULL)
3254 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.%s",
3255 client_name,keyword);
3256 c=(int) (*client_name);
3257 if ((c >= XK_a) && (c <= XK_z))
3260 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3261 c-=(XK_agrave-XK_Agrave);
3263 if ((c >= XK_oslash) && (c <= XK_thorn))
3264 c-=(XK_oslash-XK_Ooblique);
3266 if ((k >= XK_a) && (k <= XK_z))
3269 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3270 k-=(XK_agrave-XK_Agrave);
3272 if ((k >= XK_oslash) && (k <= XK_thorn))
3273 k-=(XK_oslash-XK_Ooblique);
3274 (void) FormatLocaleString(resource_class,MaxTextExtent,
"%c%s.%c%s",c,
3275 client_name+1,k,keyword+1);
3277 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3279 if (status == False)
3280 return(resource_default);
3281 return(resource_value.addr);
3314 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3315 const char *client_name)
3318 filename[MaxTextExtent];
3330 if (display == (Display *) NULL)
3331 return((XrmDatabase) NULL);
3332 assert(client_name != (
char *) NULL);
3337 (void) XGetDefault(display,(
char *) client_name,
"dummy");
3338 resource_database=XrmGetDatabase(display);
3342 p=client_name+(strlen(client_name)-1);
3343 while ((p > client_name) && (*p !=
'/'))
3347 c=(int) (*client_name);
3348 if ((c >= XK_a) && (c <= XK_z))
3351 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3352 c-=(XK_agrave-XK_Agrave);
3354 if ((c >= XK_oslash) && (c <= XK_thorn))
3355 c-=(XK_oslash-XK_Ooblique);
3356 #if defined(X11_APPLICATION_PATH)
3357 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%c%s",
3358 X11_APPLICATION_PATH,c,client_name+1);
3359 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3361 if (XResourceManagerString(display) != (
char *) NULL)
3366 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3367 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3372 #if defined(X11_PREFERENCES_PATH)
3373 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%src",
3374 X11_PREFERENCES_PATH,client_name);
3375 ExpandFilename(filename);
3376 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3378 return(resource_database);
3412 MagickExport
void XGetResourceInfo(
const ImageInfo *image_info,
3413 XrmDatabase database,
const char *client_name,XResourceInfo *resource_info)
3422 assert(resource_info != (XResourceInfo *) NULL);
3423 if (IsEventLogging() != MagickFalse)
3424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3425 (void) memset(resource_info,0,
sizeof(*resource_info));
3426 resource_info->resource_database=database;
3427 resource_info->image_info=(
ImageInfo *) image_info;
3428 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3429 XMagickProgressMonitor,(
void *) NULL);
3430 resource_info->quantize_info=CloneQuantizeInfo((
QuantizeInfo *) NULL);
3431 resource_info->close_server=MagickTrue;
3432 resource_info->client_name=AcquireString(client_name);
3433 resource_value=XGetResourceClass(database,client_name,
"backdrop",
3435 resource_info->backdrop=IsMagickTrue(resource_value);
3436 resource_info->background_color=XGetResourceInstance(database,client_name,
3437 "background",(
char *)
"#d6d6d6d6d6d6");
3438 resource_info->border_color=XGetResourceInstance(database,client_name,
3439 "borderColor",BorderColor);
3440 resource_value=XGetResourceClass(database,client_name,
"borderWidth",
3442 resource_info->border_width=(
unsigned int) StringToUnsignedLong(
3444 resource_value=XGetResourceClass(database,client_name,
"colormap",
3446 resource_info->colormap=UndefinedColormap;
3447 if (LocaleCompare(
"private",resource_value) == 0)
3448 resource_info->colormap=PrivateColormap;
3449 if (LocaleCompare(
"shared",resource_value) == 0)
3450 resource_info->colormap=SharedColormap;
3451 if (resource_info->colormap == UndefinedColormap)
3452 ThrowXWindowException(OptionError,
"UnrecognizedColormapType",
3454 resource_value=XGetResourceClass(database,client_name,
3455 "colorRecovery",(
char *)
"False");
3456 resource_info->color_recovery=IsMagickTrue(resource_value);
3457 resource_value=XGetResourceClass(database,client_name,
"confirmExit",
3459 resource_info->confirm_exit=IsMagickTrue(resource_value);
3460 resource_value=XGetResourceClass(database,client_name,
"confirmEdit",
3462 resource_info->confirm_edit=IsMagickTrue(resource_value);
3463 resource_value=XGetResourceClass(database,client_name,
"delay",(
char *)
"1");
3464 resource_info->delay=(
unsigned int) StringToUnsignedLong(resource_value);
3465 resource_info->display_gamma=XGetResourceClass(database,client_name,
3466 "displayGamma",(
char *)
"2.2");
3467 resource_value=XGetResourceClass(database,client_name,
"displayWarnings",
3469 resource_info->display_warnings=IsMagickTrue(resource_value);
3470 resource_info->font=XGetResourceClass(database,client_name,
"font",
3472 resource_info->font=XGetResourceClass(database,client_name,
"fontList",
3473 resource_info->font);
3474 resource_info->font_name[0]=XGetResourceClass(database,client_name,
"font1",
3476 resource_info->font_name[1]=XGetResourceClass(database,client_name,
"font2",
3477 (
char *)
"variable");
3478 resource_info->font_name[2]=XGetResourceClass(database,client_name,
"font3",
3480 resource_info->font_name[3]=XGetResourceClass(database,client_name,
"font4",
3482 resource_info->font_name[4]=XGetResourceClass(database,client_name,
"font5",
3483 (
char *)
"7x13bold");
3484 resource_info->font_name[5]=XGetResourceClass(database,client_name,
"font6",
3485 (
char *)
"8x13bold");
3486 resource_info->font_name[6]=XGetResourceClass(database,client_name,
"font7",
3487 (
char *)
"9x15bold");
3488 resource_info->font_name[7]=XGetResourceClass(database,client_name,
"font8",
3490 resource_info->font_name[8]=XGetResourceClass(database,client_name,
"font9",
3492 resource_info->font_name[9]=XGetResourceClass(database,client_name,
"font0",
3494 resource_info->font_name[10]=XGetResourceClass(database,client_name,
"font0",
3496 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3497 "foreground",ForegroundColor);
3498 resource_value=XGetResourceClass(database,client_name,
"gammaCorrect",
3500 resource_info->gamma_correct=IsMagickTrue(resource_value);
3501 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3502 client_name,
"geometry",(
char *) NULL));
3503 resource_value=XGetResourceClass(database,client_name,
"gravity",
3505 resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3506 MagickFalse,resource_value);
3507 directory=getcwd(resource_info->home_directory,MaxTextExtent);
3509 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3510 "iconGeometry",(
char *) NULL);
3511 resource_value=XGetResourceClass(database,client_name,
"iconic",
3513 resource_info->iconic=IsMagickTrue(resource_value);
3514 resource_value=XGetResourceClass(database,client_name,
"immutable",
3515 LocaleCompare(client_name,
"PerlMagick") == 0 ? (
char *)
"True" :
3517 resource_info->immutable=IsMagickTrue(resource_value);
3518 resource_value=XGetResourceClass(database,client_name,
"magnify",
3520 resource_info->magnify=(
unsigned int) StringToUnsignedLong(resource_value);
3521 resource_info->map_type=XGetResourceClass(database,client_name,
"map",
3523 resource_info->matte_color=XGetResourceInstance(database,client_name,
3524 "mattecolor",(
char *) NULL);
3525 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3526 "name",(
char *) NULL));
3527 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,
"pen1",
3529 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,
"pen2",
3531 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,
"pen3",
3533 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,
"pen4",
3535 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,
"pen5",
3537 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,
"pen6",
3539 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,
"pen7",
3540 (
char *)
"magenta");
3541 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,
"pen8",
3543 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,
"pen9",
3545 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,
"pen0",
3547 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,
"pen0",
3549 resource_value=XGetResourceClass(database,client_name,
"pause",(
char *)
"0");
3550 resource_info->pause=(
unsigned int) StringToUnsignedLong(resource_value);
3551 resource_value=XGetResourceClass(database,client_name,
"quantum",(
char *)
"1");
3552 resource_info->quantum=StringToLong(resource_value);
3553 resource_info->text_font=XGetResourceClass(database,client_name,(
char *)
3554 "font",(
char *)
"fixed");
3555 resource_info->text_font=XGetResourceClass(database,client_name,
3556 "textFontList",resource_info->text_font);
3557 resource_info->title=XGetResourceClass(database,client_name,
"title",
3559 resource_value=XGetResourceClass(database,client_name,
"undoCache",
3561 resource_info->undo_cache=(
unsigned int) StringToUnsignedLong(resource_value);
3562 resource_value=XGetResourceClass(database,client_name,
"update",
3564 resource_info->update=IsMagickTrue(resource_value);
3565 resource_value=XGetResourceClass(database,client_name,
"usePixmap",
3567 resource_info->use_pixmap=IsMagickTrue(resource_value);
3568 resource_value=XGetResourceClass(database,client_name,
"sharedMemory",
3570 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3571 resource_info->visual_type=XGetResourceClass(database,client_name,
"visual",
3573 resource_info->window_group=XGetResourceClass(database,client_name,
3574 "windowGroup",(
char *) NULL);
3575 resource_info->window_id=XGetResourceClass(database,client_name,
"window",
3577 resource_info->write_filename=XGetResourceClass(database,client_name,
3578 "writeFilename",(
char *) NULL);
3579 resource_info->debug=(GetLogEventMask() & X11Event) != 0 ? MagickTrue :
3617 MagickExport
char *XGetResourceInstance(XrmDatabase database,
3618 const char *client_name,
const char *keyword,
const char *resource_default)
3622 resource_name[MaxTextExtent];
3630 if (database == (XrmDatabase) NULL)
3631 return((
char *) resource_default);
3632 *resource_name=
'\0';
3633 if (keyword != (
char *) NULL)
3634 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.%s",client_name,
3636 status=XrmGetResource(database,resource_name,
"ImageMagick",&resource_type,
3638 if (status == False)
3639 return((
char *) resource_default);
3640 return(resource_value.addr);
3670 MagickExport
char *XGetScreenDensity(Display *display)
3673 density[MaxTextExtent];
3682 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3683 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3684 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3685 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3686 (void) FormatLocaleString(density,MaxTextExtent,
"%gx%g",x_density,
3688 return(GetPageGeometry(density));
3726 static Window XGetSubwindow(Display *display,Window window,
int x,
int y)
3739 assert(display != (Display *) NULL);
3740 source_window=XRootWindow(display,XDefaultScreen(display));
3741 if (window == (Window) NULL)
3742 return(source_window);
3743 target_window=window;
3746 status=XTranslateCoordinates(display,source_window,window,x,y,
3747 &x_offset,&y_offset,&target_window);
3750 if (target_window == (Window) NULL)
3752 source_window=window;
3753 window=target_window;
3757 if (target_window == (Window) NULL)
3758 target_window=window;
3759 return(target_window);
3792 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3793 XWindows *windows,
char *name)
3826 assert(display != (Display *) NULL);
3827 assert(name != (
char *) NULL);
3828 if (IsEventLogging() != MagickFalse)
3829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
3831 target_window=XSelectWindow(display,&crop_info);
3832 if (target_window == (Window) NULL)
3833 return(MagickFalse);
3834 root_window=XRootWindow(display,XDefaultScreen(display));
3835 client_window=target_window;
3836 if (target_window != root_window)
3844 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3845 if (status != False)
3847 client_window=XClientWindow(display,target_window);
3848 target_window=client_window;
3854 status=XGetWindowAttributes(display,target_window,&window_attributes);
3855 if ((status == False) || (window_attributes.map_state != IsViewable))
3856 return(MagickFalse);
3860 (void) XTranslateCoordinates(display,root_window,target_window,
3861 (
int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3862 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3863 if (ximage == (XImage *) NULL)
3864 return(MagickFalse);
3865 color.pixel=XGetPixel(ximage,0,0);
3866 XDestroyImage(ximage);
3870 (void) XQueryColor(display,window_attributes.colormap,&color);
3871 pixel.red=ScaleShortToQuantum(color.red);
3872 pixel.green=ScaleShortToQuantum(color.green);
3873 pixel.blue=ScaleShortToQuantum(color.blue);
3874 pixel.opacity=OpaqueOpacity;
3875 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3876 &windows->image.image->exception);
3919 static Image *XGetWindowImage(Display *display,
const Window window,
3920 const unsigned int borders,
const unsigned int level)
3934 typedef struct _WindowInfo
3995 assert(display != (Display *) NULL);
3996 if (IsEventLogging() != MagickFalse)
3997 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3998 status=XGetWindowAttributes(display,window,&window_attributes);
3999 if ((status == False) || (window_attributes.map_state != IsViewable))
4000 return((
Image *) NULL);
4004 root_window=XRootWindow(display,XDefaultScreen(display));
4005 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4007 crop_info.x=(ssize_t) x_offset;
4008 crop_info.y=(ssize_t) y_offset;
4009 crop_info.width=(size_t) window_attributes.width;
4010 crop_info.height=(
size_t) window_attributes.height;
4011 if (borders != MagickFalse)
4016 crop_info.x-=(ssize_t) window_attributes.border_width;
4017 crop_info.y-=(ssize_t) window_attributes.border_width;
4018 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4019 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4024 if (crop_info.x < 0)
4026 crop_info.width+=crop_info.x;
4029 if (crop_info.y < 0)
4031 crop_info.height+=crop_info.y;
4034 display_width=XDisplayWidth(display,XDefaultScreen(display));
4035 if ((
int) (crop_info.x+crop_info.width) > display_width)
4036 crop_info.width=(size_t) (display_width-crop_info.x);
4037 display_height=XDisplayHeight(display,XDefaultScreen(display));
4038 if ((
int) (crop_info.y+crop_info.height) > display_height)
4039 crop_info.height=(size_t) (display_height-crop_info.y);
4043 if (number_windows >= max_windows)
4049 if (window_info == (WindowInfo *) NULL)
4050 window_info=(WindowInfo *) AcquireQuantumMemory((
size_t) max_windows,
4051 sizeof(*window_info));
4053 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(
size_t)
4054 max_windows,
sizeof(*window_info));
4056 if (window_info == (WindowInfo *) NULL)
4057 ThrowXWindowFatalException(ResourceLimitError,
4058 "MemoryAllocationFailed",
"...");
4059 id=number_windows++;
4060 window_info[id].window=window;
4061 window_info[id].visual=window_attributes.visual;
4062 window_info[id].colormap=window_attributes.colormap;
4063 window_info[id].bounds.x1=(short) crop_info.x;
4064 window_info[
id].bounds.y1=(
short) crop_info.y;
4065 window_info[id].bounds.x2=(short) (crop_info.x+(
int) crop_info.width-1);
4066 window_info[id].bounds.y2=(short) (crop_info.y+(
int) crop_info.height-1);
4067 crop_info.x-=x_offset;
4068 crop_info.y-=y_offset;
4069 window_info[id].crop_info=crop_info;
4081 status=XQueryTree(display,window,&root_window,&window_info[
id].parent,
4082 &children,&number_children);
4083 for (i=0; i < id; i++)
4084 if ((window_info[i].window == window_info[
id].parent) &&
4085 (window_info[i].visual == window_info[
id].visual) &&
4086 (window_info[i].colormap == window_info[
id].colormap))
4088 if ((window_info[
id].bounds.x1 < window_info[i].bounds.x1) ||
4089 (window_info[
id].bounds.x2 > window_info[i].bounds.x2) ||
4090 (window_info[
id].bounds.y1 < window_info[i].bounds.y1) ||
4091 (window_info[
id].bounds.y2 > window_info[i].bounds.y2))
4100 if ((status == True) && (number_children != 0))
4102 for (i=0; i < (int) number_children; i++)
4103 (
void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4104 (void) XFree((
void *) children);
4150 image=NewImageList();
4151 for (
id=0;
id < number_windows;
id++)
4156 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4157 (window_info[
id].bounds.x1 <= window_info[0].bounds.x2) &&
4158 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4159 (window_info[
id].bounds.y1 <= window_info[0].bounds.y2)) ?
4160 MagickTrue : MagickFalse;
4164 for (j=0; j < id; j++)
4165 if ((window_info[
id].visual == window_info[j].visual) &&
4166 (window_info[id].colormap == window_info[j].colormap))
4168 if ((window_info[
id].bounds.x1 >= window_info[j].bounds.x1) &&
4169 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4170 (window_info[
id].bounds.y1 >= window_info[j].bounds.y1) &&
4171 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4174 if (
import == MagickFalse)
4179 ximage=XGetImage(display,window_info[
id].window,(
int)
4180 window_info[
id].crop_info.x,(
int) window_info[
id].crop_info.y,
4181 (
unsigned int) window_info[
id].crop_info.width,(
unsigned int)
4182 window_info[
id].crop_info.height,AllPlanes,ZPixmap);
4183 if (ximage == (XImage *) NULL)
4189 colors=(XColor *) NULL;
4190 if (window_info[
id].colormap != (Colormap) NULL)
4198 number_colors=(
unsigned int) window_info[
id].visual->map_entries;
4199 for (p=colormap_info; p != (
ColormapInfo *) NULL; p=p->next)
4200 if (p->colormap == window_info[
id].colormap)
4207 colors=(XColor *) AcquireQuantumMemory(number_colors,
4209 if (colors == (XColor *) NULL)
4211 XDestroyImage(ximage);
4212 return((
Image *) NULL);
4214 if ((window_info[
id].visual->klass != DirectColor) &&
4215 (window_info[
id].visual->klass != TrueColor))
4216 for (i=0; i < (int) number_colors; i++)
4218 colors[i].pixel=(size_t) i;
4237 red_bit=window_info[id].visual->red_mask &
4238 (~(window_info[id].visual->red_mask)+1);
4239 green_bit=window_info[id].visual->green_mask &
4240 (~(window_info[id].visual->green_mask)+1);
4241 blue_bit=window_info[id].visual->blue_mask &
4242 (~(window_info[id].visual->blue_mask)+1);
4243 for (i=0; i < (int) number_colors; i++)
4245 colors[i].pixel=(
unsigned long) (red | green | blue);
4248 if (red > window_info[
id].visual->red_mask)
4251 if (green > window_info[
id].visual->green_mask)
4254 if (blue > window_info[
id].visual->blue_mask)
4258 (void) XQueryColors(display,window_info[
id].colormap,colors,
4259 (
int) number_colors);
4265 return((
Image *) NULL);
4266 p->colormap=window_info[id].colormap;
4268 p->next=colormap_info;
4276 composite_image=AcquireImage((
ImageInfo *) NULL);
4277 if (composite_image == (
Image *) NULL)
4279 XDestroyImage(ximage);
4280 return((
Image *) NULL);
4285 if ((window_info[
id].visual->klass != TrueColor) &&
4286 (window_info[
id].visual->klass != DirectColor))
4287 composite_image->storage_class=PseudoClass;
4288 composite_image->columns=(size_t) ximage->width;
4289 composite_image->rows=(
size_t) ximage->height;
4290 exception=(&composite_image->exception);
4291 composite_view=AcquireAuthenticCacheView(composite_image,exception);
4292 switch (composite_image->storage_class)
4312 red_mask=window_info[id].visual->red_mask;
4314 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4319 green_mask=window_info[id].visual->green_mask;
4321 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4326 blue_mask=window_info[id].visual->blue_mask;
4328 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4336 if ((number_colors != 0) &&
4337 (window_info[
id].visual->klass == DirectColor))
4338 for (y=0; y < (int) composite_image->rows; y++)
4340 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4341 composite_image->columns,1,exception);
4344 for (x=0; x < (int) composite_image->columns; x++)
4346 pixel=XGetPixel(ximage,x,y);
4347 index=(pixel >> red_shift) & red_mask;
4348 SetPixelRed(q,ScaleShortToQuantum(
4349 colors[index].red));
4350 index=(pixel >> green_shift) & green_mask;
4351 SetPixelGreen(q,ScaleShortToQuantum(
4352 colors[index].green));
4353 index=(pixel >> blue_shift) & blue_mask;
4354 SetPixelBlue(q,ScaleShortToQuantum(
4355 colors[index].blue));
4358 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4362 for (y=0; y < (int) composite_image->rows; y++)
4364 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4365 composite_image->columns,1,exception);
4368 for (x=0; x < (int) composite_image->columns; x++)
4370 pixel=XGetPixel(ximage,x,y);
4371 color=(pixel >> red_shift) & red_mask;
4373 color=(65535UL*color)/red_mask;
4374 SetPixelRed(q,ScaleShortToQuantum((
unsigned short)
4376 color=(pixel >> green_shift) & green_mask;
4377 if (green_mask != 0)
4378 color=(65535UL*color)/green_mask;
4379 SetPixelGreen(q,ScaleShortToQuantum((
unsigned short)
4381 color=(pixel >> blue_shift) & blue_mask;
4383 color=(65535UL*color)/blue_mask;
4384 SetPixelBlue(q,ScaleShortToQuantum((
unsigned short)
4388 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4398 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4400 XDestroyImage(ximage);
4401 composite_image=DestroyImage(composite_image);
4402 return((
Image *) NULL);
4404 if (colors == (XColor *) NULL)
4406 for (i=0; i < (int) composite_image->colors; i++)
4408 composite_image->colormap[colors[i].pixel].red=
4409 ScaleShortToQuantum(colors[i].red);
4410 composite_image->colormap[colors[i].pixel].green=
4411 ScaleShortToQuantum(colors[i].green);
4412 composite_image->colormap[colors[i].pixel].blue=
4413 ScaleShortToQuantum(colors[i].blue);
4418 for (y=0; y < (int) composite_image->rows; y++)
4420 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4421 composite_image->columns,1,exception);
4424 indexes=GetCacheViewAuthenticIndexQueue(composite_view);
4425 for (x=0; x < (int) composite_image->columns; x++)
4427 index=(IndexPacket) XGetPixel(ximage,x,y);
4428 SetPixelIndex(indexes+x,index);
4429 SetPixelRGBO(q,composite_image->colormap+(ssize_t)
4433 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4439 composite_view=DestroyCacheView(composite_view);
4440 XDestroyImage(ximage);
4441 if (image == (
Image *) NULL)
4443 image=composite_image;
4449 (void) XTranslateCoordinates(display,window_info[
id].window,window,0,0,
4450 &x_offset,&y_offset,&child);
4451 x_offset-=(int) crop_info.x;
4454 y_offset-=(int) crop_info.y;
4457 (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4458 x_offset,(ssize_t) y_offset);
4459 composite_image=DestroyImage(composite_image);
4466 next=colormap_info->next;
4467 colormap_info->colors=(XColor *)
4468 RelinquishMagickMemory(colormap_info->colors);
4469 colormap_info=(
ColormapInfo *) RelinquishMagickMemory(colormap_info);
4475 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4481 return((
Image *) NULL);
4522 MagickExport
void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4523 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4524 XResourceInfo *resource_info,XWindowInfo *window)
4529 assert(display != (Display *) NULL);
4530 assert(visual_info != (XVisualInfo *) NULL);
4531 assert(map_info != (XStandardColormap *) NULL);
4532 assert(pixel != (XPixelInfo *) NULL);
4533 assert(resource_info != (XResourceInfo *) NULL);
4534 assert(window != (XWindowInfo *) NULL);
4535 if (IsEventLogging() != MagickFalse)
4536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4537 if (window->id != (Window) NULL)
4539 if (window->cursor != (Cursor) NULL)
4540 (
void) XFreeCursor(display,window->cursor);
4541 if (window->busy_cursor != (Cursor) NULL)
4542 (void) XFreeCursor(display,window->busy_cursor);
4543 if (window->highlight_stipple != (Pixmap) NULL)
4544 (
void) XFreePixmap(display,window->highlight_stipple);
4545 if (window->shadow_stipple != (Pixmap) NULL)
4546 (void) XFreePixmap(display,window->shadow_stipple);
4547 if (window->name == (
char *) NULL)
4548 window->name=AcquireString(
"");
4549 if (window->icon_name == (
char *) NULL)
4550 window->icon_name=AcquireString(
"");
4557 window->id=(Window) NULL;
4558 if (window->name == (
char *) NULL)
4559 window->name=AcquireString(
"");
4560 if (window->icon_name == (
char *) NULL)
4561 window->icon_name=AcquireString(
"");
4562 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4563 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4564 window->ximage=(XImage *) NULL;
4565 window->matte_image=(XImage *) NULL;
4566 window->pixmap=(Pixmap) NULL;
4567 window->matte_pixmap=(Pixmap) NULL;
4568 window->mapped=MagickFalse;
4569 window->stasis=MagickFalse;
4570 window->shared_memory=MagickTrue;
4571 window->segment_info=(
void *) NULL;
4572 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4577 if (window->segment_info == (
void *) NULL)
4578 window->segment_info=AcquireCriticalMemory(2*
sizeof(*segment_info));
4579 segment_info=(XShmSegmentInfo *) window->segment_info;
4580 segment_info[0].shmid=(-1);
4581 segment_info[0].shmaddr=(
char *) NULL;
4582 segment_info[1].shmid=(-1);
4583 segment_info[1].shmaddr=(
char *) NULL;
4590 window->screen=visual_info->screen;
4591 window->root=XRootWindow(display,visual_info->screen);
4592 window->visual=visual_info->visual;
4593 window->storage_class=(
unsigned int) visual_info->klass;
4594 window->depth=(
unsigned int) visual_info->depth;
4595 window->visual_info=visual_info;
4596 window->map_info=map_info;
4597 window->pixel_info=pixel;
4598 window->font_info=font_info;
4599 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4600 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4601 window->geometry=(
char *) NULL;
4602 window->icon_geometry=(
char *) NULL;
4603 if (resource_info->icon_geometry != (
char *) NULL)
4604 (
void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4605 window->crop_geometry=(
char *) NULL;
4606 window->flags=(size_t) PSize;
4609 window->min_width=1;
4610 window->min_height=1;
4611 window->width_inc=1;
4612 window->height_inc=1;
4613 window->border_width=resource_info->border_width;
4614 window->annotate_context=pixel->annotate_context;
4615 window->highlight_context=pixel->highlight_context;
4616 window->widget_context=pixel->widget_context;
4617 window->shadow_stipple=(Pixmap) NULL;
4618 window->highlight_stipple=(Pixmap) NULL;
4619 window->use_pixmap=MagickTrue;
4620 window->immutable=MagickFalse;
4621 window->shape=MagickFalse;
4623 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4624 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4625 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4626 window->attributes.background_pixel=pixel->background_color.pixel;
4627 window->attributes.background_pixmap=(Pixmap) NULL;
4628 window->attributes.bit_gravity=ForgetGravity;
4629 window->attributes.backing_store=WhenMapped;
4630 window->attributes.save_under=MagickTrue;
4631 window->attributes.border_pixel=pixel->border_color.pixel;
4632 window->attributes.colormap=map_info->colormap;
4633 window->attributes.cursor=window->cursor;
4634 window->attributes.do_not_propagate_mask=NoEventMask;
4635 window->attributes.event_mask=NoEventMask;
4636 window->attributes.override_redirect=MagickFalse;
4637 window->attributes.win_gravity=NorthWestGravity;
4638 window->orphan=MagickFalse;
4673 MagickExport
void XHighlightEllipse(Display *display,Window window,
4676 assert(display != (Display *) NULL);
4677 assert(window != (Window) NULL);
4678 assert(annotate_context != (GC) NULL);
4680 if (IsEventLogging() != MagickFalse)
4681 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4682 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4684 (void) XDrawArc(display,window,annotate_context,(
int) highlight_info->x,
4685 (int) highlight_info->y,(
unsigned int) highlight_info->width-1,
4686 (
unsigned int) highlight_info->height-1,0,360*64);
4687 (void) XDrawArc(display,window,annotate_context,(
int) highlight_info->x+1,
4688 (int) highlight_info->y+1,(
unsigned int) highlight_info->width-3,
4689 (
unsigned int) highlight_info->height-3,0,360*64);
4724 MagickExport
void XHighlightLine(Display *display,Window window,
4725 GC annotate_context,
const XSegment *highlight_info)
4727 assert(display != (Display *) NULL);
4728 assert(window != (Window) NULL);
4729 assert(annotate_context != (GC) NULL);
4730 assert(highlight_info != (XSegment *) NULL);
4731 if (IsEventLogging() != MagickFalse)
4732 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4733 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4734 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4769 MagickExport
void XHighlightRectangle(Display *display,Window window,
4772 assert(display != (Display *) NULL);
4773 assert(window != (Window) NULL);
4774 assert(annotate_context != (GC) NULL);
4776 if (IsEventLogging() != MagickFalse)
4777 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4778 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4780 (void) XDrawRectangle(display,window,annotate_context,(
int) highlight_info->x,
4781 (int) highlight_info->y,(
unsigned int) highlight_info->width-1,
4782 (
unsigned int) highlight_info->height-1);
4783 (void) XDrawRectangle(display,window,annotate_context,(
int) highlight_info->x+
4784 1,(int) highlight_info->y+1,(
unsigned int) highlight_info->width-3,
4785 (
unsigned int) highlight_info->height-3);
4848 assert(image_info != (
const ImageInfo *) NULL);
4849 assert(image_info->signature == MagickCoreSignature);
4851 if (IsEventLogging() != MagickFalse)
4852 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
4853 image_info->filename);
4854 display=XOpenDisplay(image_info->server_name);
4855 if (display == (Display *) NULL)
4856 ThrowXWindowFatalException(XServerError,
"UnableToOpenXServer",
4857 XDisplayName(image_info->server_name));
4861 (void) XSetErrorHandler(XError);
4869 root=XRootWindow(display,XDefaultScreen(display));
4870 target=(Window) NULL;
4871 if (*image_info->filename !=
'\0')
4873 if (LocaleCompare(image_info->filename,
"root") == 0)
4880 if (isdigit((
int) ((
unsigned char) *image_info->filename)) != 0)
4881 target=XWindowByID(display,root,(Window)
4882 strtol(image_info->filename,(
char **) NULL,0));
4883 if (target == (Window) NULL)
4884 target=XWindowByName(display,root,image_info->filename);
4885 if (target == (Window) NULL)
4886 ThrowXWindowException(XServerError,
"NoWindowWithSpecifiedIDExists",
4887 image_info->filename);
4893 prior_target=target;
4894 if (target == (Window) NULL)
4895 target=XSelectWindow(display,&crop_info);
4896 if (target == (Window) NULL)
4897 ThrowXWindowException(XServerError,
"UnableToReadXWindowImage",
4898 image_info->filename);
4905 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4906 if (status != False)
4916 status=XQueryTree(display,target,&root,&parent,&children,&d);
4917 if ((status != False) && (children != (Window *) NULL))
4918 (void) XFree((
char *) children);
4919 if ((status == False) || (parent == (Window) NULL) ||
4927 client=XClientWindow(display,target);
4928 if (ximage_info->frame == MagickFalse)
4930 if ((ximage_info->frame == MagickFalse) &&
4931 (prior_target != MagickFalse))
4932 target=prior_target;
4935 if (ximage_info->screen != MagickFalse)
4949 status=XGetWindowAttributes(display,target,&window_attributes);
4950 if (status == False)
4952 (void) XCloseDisplay(display);
4953 ThrowXWindowFatalException(XServerError,
4954 "UnableToReadXWindowAttributes",image_info->filename);
4956 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4957 crop_info.x=(ssize_t) x;
4958 crop_info.y=(ssize_t) y;
4959 crop_info.width=(size_t) window_attributes.width;
4960 crop_info.height=(
size_t) window_attributes.height;
4961 if (ximage_info->borders != 0)
4966 crop_info.x-=window_attributes.border_width;
4967 crop_info.y-=window_attributes.border_width;
4968 crop_info.width+=window_attributes.border_width << 1;
4969 crop_info.height+=window_attributes.border_width << 1;
4977 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4978 if ((status == True) && (number_windows > 0))
4980 ximage_info->descend=MagickTrue;
4981 (void) XFree ((
char *) children);
4983 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
4984 if (number_colormaps > 0)
4986 if (number_colormaps > 1)
4987 ximage_info->descend=MagickTrue;
4988 (void) XFree((
char *) colormaps);
4993 if (ximage_info->silent == MagickFalse)
4994 (void) XBell(display,0);
4998 (void) XGrabServer(display);
4999 image=XGetWindowImage(display,target,ximage_info->borders,
5000 ximage_info->descend ? 1U : 0U);
5001 (void) XUngrabServer(display);
5002 if (image == (
Image *) NULL)
5003 ThrowXWindowException(XServerError,
"UnableToReadXWindowImage",
5004 image_info->filename)
5007 (void) CopyMagickString(image->filename,image_info->filename,
5009 if ((crop_info.width != 0) && (crop_info.height != 0))
5017 crop_image=CropImage(image,&crop_info,&image->exception);
5018 if (crop_image != (
Image *) NULL)
5020 image=DestroyImage(image);
5024 status=XGetWMName(display,target,&window_name);
5027 if (*image_info->filename ==
'\0')
5028 (void) CopyMagickString(image->filename,(
char *) window_name.value,
5029 (size_t) window_name.nitems+1);
5030 (void) XFree((
void *) window_name.value);
5033 if (ximage_info->silent == MagickFalse)
5038 (void) XBell(display,0);
5039 (void) XBell(display,0);
5041 (void) XCloseDisplay(display);
5073 MagickExport XWindows *XInitializeWindows(Display *display,
5074 XResourceInfo *resource_info)
5085 windows=(XWindows *) AcquireMagickMemory(
sizeof(*windows));
5086 if (windows == (XWindows *) NULL)
5087 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5089 (void) memset(windows,0,
sizeof(*windows));
5090 windows->pixel_info=(XPixelInfo *) AcquireQuantumMemory(1,
5091 sizeof(*windows->pixel_info));
5092 windows->icon_pixel=(XPixelInfo *) AcquireQuantumMemory(1,
5093 sizeof(*windows->icon_pixel));
5094 windows->icon_resources=(XResourceInfo *) AcquireQuantumMemory(1,
5095 sizeof(*windows->icon_resources));
5096 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5097 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5098 (windows->icon_resources == (XResourceInfo *) NULL))
5099 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
5101 (void) memset((
void *) windows->pixel_info,0,
sizeof(XPixelInfo));
5102 (void) memset((
void *) windows->icon_pixel,0,
sizeof(XPixelInfo));
5106 windows->display=display;
5107 windows->wm_protocols=XInternAtom(display,
"WM_PROTOCOLS",MagickFalse);
5108 windows->wm_delete_window=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
5109 windows->wm_take_focus=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
5110 windows->im_protocols=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
5111 windows->im_remote_command=
5112 XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
5113 windows->im_update_widget=XInternAtom(display,
"IM_UPDATE_WIDGET",MagickFalse);
5114 windows->im_update_colormap=
5115 XInternAtom(display,
"IM_UPDATE_COLORMAP",MagickFalse);
5116 windows->im_former_image=XInternAtom(display,
"IM_FORMER_IMAGE",MagickFalse);
5117 windows->im_next_image=XInternAtom(display,
"IM_NEXT_IMAGE",MagickFalse);
5118 windows->im_retain_colors=XInternAtom(display,
"IM_RETAIN_COLORS",MagickFalse);
5119 windows->im_exit=XInternAtom(display,
"IM_EXIT",MagickFalse);
5120 windows->dnd_protocols=XInternAtom(display,
"DndProtocol",MagickFalse);
5121 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5122 (void) XSynchronize(display,MagickFalse);
5124 if ((GetLogEventMask() & X11Event) != 0)
5126 (void) XSynchronize(display,MagickTrue);
5127 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Version: %s",
5128 GetMagickVersion((
size_t *) NULL));
5129 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Protocols:");
5130 (void) LogMagickEvent(X11Event,GetMagickModule(),
5131 " Window Manager: 0x%lx",windows->wm_protocols);
5132 (void) LogMagickEvent(X11Event,GetMagickModule(),
5133 " delete window: 0x%lx",windows->wm_delete_window);
5134 (void) LogMagickEvent(X11Event,GetMagickModule(),
" take focus: 0x%lx",
5135 windows->wm_take_focus);
5136 (void) LogMagickEvent(X11Event,GetMagickModule(),
" ImageMagick: 0x%lx",
5137 windows->im_protocols);
5138 (void) LogMagickEvent(X11Event,GetMagickModule(),
5139 " remote command: 0x%lx",windows->im_remote_command);
5140 (void) LogMagickEvent(X11Event,GetMagickModule(),
5141 " update widget: 0x%lx",windows->im_update_widget);
5142 (void) LogMagickEvent(X11Event,GetMagickModule(),
5143 " update colormap: 0x%lx",windows->im_update_colormap);
5144 (void) LogMagickEvent(X11Event,GetMagickModule(),
5145 " former image: 0x%lx",windows->im_former_image);
5146 (void) LogMagickEvent(X11Event,GetMagickModule(),
" next image: 0x%lx",
5147 windows->im_next_image);
5148 (void) LogMagickEvent(X11Event,GetMagickModule(),
5149 " retain colors: 0x%lx",windows->im_retain_colors);
5150 (void) LogMagickEvent(X11Event,GetMagickModule(),
" exit: 0x%lx",
5152 (void) LogMagickEvent(X11Event,GetMagickModule(),
" Drag and Drop: 0x%lx",
5153 windows->dnd_protocols);
5158 windows->map_info=XAllocStandardColormap();
5159 windows->icon_map=XAllocStandardColormap();
5160 if ((windows->map_info == (XStandardColormap *) NULL) ||
5161 (windows->icon_map == (XStandardColormap *) NULL))
5162 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5164 windows->map_info->colormap=(Colormap) NULL;
5165 windows->icon_map->colormap=(Colormap) NULL;
5166 windows->pixel_info->pixels=(
unsigned long *) NULL;
5167 windows->pixel_info->annotate_context=(GC) NULL;
5168 windows->pixel_info->highlight_context=(GC) NULL;
5169 windows->pixel_info->widget_context=(GC) NULL;
5170 windows->font_info=(XFontStruct *) NULL;
5171 windows->icon_pixel->annotate_context=(GC) NULL;
5172 windows->icon_pixel->pixels=(
unsigned long *) NULL;
5176 *windows->icon_resources=(*resource_info);
5177 windows->icon_resources->visual_type=(
char *)
"default";
5178 windows->icon_resources->colormap=SharedColormap;
5179 windows->visual_info=
5180 XBestVisualInfo(display,windows->map_info,resource_info);
5181 windows->icon_visual=
5182 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5183 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5184 (windows->icon_visual == (XVisualInfo *) NULL))
5185 ThrowXWindowFatalException(XServerFatalError,
"UnableToGetVisual",
5186 resource_info->visual_type);
5187 if ((GetLogEventMask() & X11Event) != 0)
5189 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Visual:");
5190 (void) LogMagickEvent(X11Event,GetMagickModule(),
" visual id: 0x%lx",
5191 windows->visual_info->visualid);
5192 (void) LogMagickEvent(X11Event,GetMagickModule(),
" class: %s",
5193 XVisualClassName(windows->visual_info->klass));
5194 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d planes",
5195 windows->visual_info->depth);
5196 (void) LogMagickEvent(X11Event,GetMagickModule(),
5197 " size of colormap: %d entries",windows->visual_info->colormap_size);
5198 (void) LogMagickEvent(X11Event,GetMagickModule(),
5199 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5200 windows->visual_info->red_mask,windows->visual_info->green_mask,
5201 windows->visual_info->blue_mask);
5202 (void) LogMagickEvent(X11Event,GetMagickModule(),
5203 " significant bits in color: %d bits",
5204 windows->visual_info->bits_per_rgb);
5209 windows->class_hints=XAllocClassHint();
5210 windows->manager_hints=XAllocWMHints();
5211 if ((windows->class_hints == (XClassHint *) NULL) ||
5212 (windows->manager_hints == (XWMHints *) NULL))
5213 ThrowXWindowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
5218 root_window=XRootWindow(display,windows->visual_info->screen);
5219 windows->group_leader.id=(Window) NULL;
5220 if (resource_info->window_group != (
char *) NULL)
5222 if (isdigit((
int) ((
unsigned char) *resource_info->window_group)) != 0)
5223 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5224 strtol((
char *) resource_info->window_group,(
char **) NULL,0));
5225 if (windows->group_leader.id == (Window) NULL)
5226 windows->group_leader.id=
5227 XWindowByName(display,root_window,resource_info->window_group);
5266 MagickExport Cursor XMakeCursor(Display *display,Window window,
5267 Colormap colormap,
char *background_color,
char *foreground_color)
5269 #define scope_height 17
5270 #define scope_x_hot 8
5271 #define scope_y_hot 8
5272 #define scope_width 17
5274 static const unsigned char
5277 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5278 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5279 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5280 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5281 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5285 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5286 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5287 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5288 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5289 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5303 assert(display != (Display *) NULL);
5304 assert(window != (Window) NULL);
5305 assert(colormap != (Colormap) NULL);
5306 assert(background_color != (
char *) NULL);
5307 assert(foreground_color != (
char *) NULL);
5308 if (IsEventLogging() != MagickFalse)
5309 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",background_color);
5310 source=XCreateBitmapFromData(display,window,(
char *) scope_bits,scope_width,
5312 mask=XCreateBitmapFromData(display,window,(
char *) scope_mask_bits,
5313 scope_width,scope_height);
5314 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5315 ThrowXWindowFatalException(XServerError,
"UnableToCreatePixmap",
"...");
5316 (void) XParseColor(display,colormap,background_color,&background);
5317 (void) XParseColor(display,colormap,foreground_color,&foreground);
5318 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5319 scope_x_hot,scope_y_hot);
5320 (void) XFreePixmap(display,source);
5321 (void) XFreePixmap(display,mask);
5363 MagickExport MagickBooleanType XMakeImage(Display *display,
5364 const XResourceInfo *resource_info,XWindowInfo *window,
Image *image,
5365 unsigned int width,
unsigned int height)
5367 #define CheckOverflowException(length,width,height) \
5368 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5378 assert(display != (Display *) NULL);
5379 assert(resource_info != (XResourceInfo *) NULL);
5380 assert(window != (XWindowInfo *) NULL);
5382 assert(height != 0);
5383 if (IsEventLogging() != MagickFalse)
5384 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
5385 if ((window->width == 0) || (window->height == 0))
5386 return(MagickFalse);
5390 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5391 (void) XFlush(display);
5392 depth=(int) window->depth;
5393 if (window->destroy)
5394 window->image=DestroyImage(window->image);
5395 window->image=image;
5396 window->destroy=MagickFalse;
5397 if (window->image != (
Image *) NULL)
5399 if (window->crop_geometry != (
char *) NULL)
5410 window->image->page.x=0;
5411 window->image->page.y=0;
5412 (void) ParsePageGeometry(window->image,window->crop_geometry,
5413 &crop_info,&image->exception);
5414 crop_image=CropImage(window->image,&crop_info,&image->exception);
5415 if (crop_image != (
Image *) NULL)
5417 if (window->image != image)
5418 window->image=DestroyImage(window->image);
5419 window->image=crop_image;
5420 window->destroy=MagickTrue;
5423 if ((width != (
unsigned int) window->image->columns) ||
5424 (height != (
unsigned int) window->image->rows))
5432 resize_image=NewImageList();
5433 if ((window->pixel_info->colors == 0) &&
5434 (window->image->rows > (
unsigned long) XDisplayHeight(display,window->screen)) &&
5435 (window->image->columns > (
unsigned long) XDisplayWidth(display,window->screen)))
5436 resize_image=ResizeImage(window->image,width,height,
5437 image->filter,image->blur,&image->exception);
5440 if (window->image->storage_class == PseudoClass)
5441 resize_image=SampleImage(window->image,width,height,
5444 resize_image=ThumbnailImage(window->image,width,height,
5447 if (resize_image != (
Image *) NULL)
5449 if (window->image != image)
5450 window->image=DestroyImage(window->image);
5451 window->image=resize_image;
5452 window->destroy=MagickTrue;
5455 width=(
unsigned int) window->image->columns;
5456 assert((
size_t) width == window->image->columns);
5457 height=(
unsigned int) window->image->rows;
5458 assert((
size_t) height == window->image->rows);
5463 ximage=(XImage *) NULL;
5464 format=(depth == 1) ? XYBitmap : ZPixmap;
5465 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5466 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 if ((GetLogEventMask() & X11Event) != 0)
5566 (void) LogMagickEvent(X11Event,GetMagickModule(),
"XImage:");
5567 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %dx%d",
5568 ximage->width,ximage->height);
5569 (void) LogMagickEvent(X11Event,GetMagickModule(),
" format: %d",
5571 (void) LogMagickEvent(X11Event,GetMagickModule(),
" byte order: %d",
5572 ximage->byte_order);
5573 (void) LogMagickEvent(X11Event,GetMagickModule(),
5574 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5575 ximage->bitmap_bit_order,ximage->bitmap_pad);
5576 (void) LogMagickEvent(X11Event,GetMagickModule(),
" depth: %d",
5578 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bytes per line: %d",
5579 ximage->bytes_per_line);
5580 (void) LogMagickEvent(X11Event,GetMagickModule(),
" bits per pixel: %d",
5581 ximage->bits_per_pixel);
5582 (void) LogMagickEvent(X11Event,GetMagickModule(),
5583 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5584 ximage->green_mask,ximage->blue_mask);
5586 if (window->shared_memory == MagickFalse)
5588 if (ximage->format == XYBitmap)
5590 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5591 ximage->bytes_per_line,(size_t) ximage->depth*ximage->height);
5592 if (ximage->data != (
char *) NULL)
5593 (
void) memset(ximage->data,0,(
size_t)
5594 ximage->bytes_per_line*ximage->depth*ximage->height);
5598 ximage->data=(
char *) AcquireQuantumMemory((
size_t)
5599 ximage->bytes_per_line,(size_t) ximage->height);
5600 if (ximage->data != (
char *) NULL)
5601 (
void) memset(ximage->data,0,(
size_t)
5602 ximage->bytes_per_line*ximage->height);
5605 if (ximage->data == (
char *) NULL)
5610 XDestroyImage(ximage);
5611 ximage=(XImage *) NULL;
5612 (void) XCheckDefineCursor(display,window->id,window->cursor);
5613 return(MagickFalse);
5615 if (window->ximage != (XImage *) NULL)
5620 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5621 if (window->segment_info != (XShmSegmentInfo *) NULL)
5626 segment_info=(XShmSegmentInfo *) window->segment_info;
5627 if (segment_info[0].shmid >= 0)
5629 (void) XSync(display,MagickFalse);
5630 (void) XShmDetach(display,&segment_info[0]);
5631 (void) XSync(display,MagickFalse);
5632 if (segment_info[0].shmaddr != (
char *) NULL)
5633 (
void) shmdt(segment_info[0].shmaddr);
5634 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5635 segment_info[0].shmid=(-1);
5636 segment_info[0].shmaddr=(
char *) NULL;
5637 window->ximage->data=(
char *) NULL;
5641 if (window->ximage->data != (
char *) NULL)
5642 free(window->ximage->data);
5643 window->ximage->data=(
char *) NULL;
5644 XDestroyImage(window->ximage);
5645 window->ximage=(XImage *) NULL;
5647 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5648 if (window->segment_info != (XShmSegmentInfo *) NULL)
5653 segment_info=(XShmSegmentInfo *) window->segment_info;
5654 segment_info[0]=segment_info[1];
5657 window->ximage=ximage;
5658 matte_image=(XImage *) NULL;
5659 if ((window->shape != MagickFalse) && (window->image != (
Image *) NULL))
5660 if ((window->image->matte != MagickFalse) &&
5661 ((int) width <= XDisplayWidth(display,window->screen)) &&
5662 ((
int) height <= XDisplayHeight(display,window->screen)))
5667 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5668 (
char *) NULL,width,height,XBitmapPad(display),0);
5669 if ((GetLogEventMask() & X11Event) != 0)
5671 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Matte Image:");
5672 (void) LogMagickEvent(X11Event,GetMagickModule(),
5673 " width, height: %dx%d",matte_image->width,matte_image->height);
5675 if (matte_image != (XImage *) NULL)
5680 matte_image->data=(
char *) malloc((
size_t)
5681 matte_image->bytes_per_line*matte_image->depth*
5682 matte_image->height);
5683 if (matte_image->data == (
char *) NULL)
5685 XDestroyImage(matte_image);
5686 matte_image=(XImage *) NULL;
5690 if (window->matte_image != (XImage *) NULL)
5695 if (window->matte_image->data != (
char *) NULL)
5696 free(window->matte_image->data);
5697 window->matte_image->data=(
char *) NULL;
5698 XDestroyImage(window->matte_image);
5699 window->matte_image=(XImage *) NULL;
5701 window->matte_image=matte_image;
5702 if (window->matte_pixmap != (Pixmap) NULL)
5704 (void) XFreePixmap(display,window->matte_pixmap);
5705 window->matte_pixmap=(Pixmap) NULL;
5706 #if defined(MAGICKCORE_HAVE_SHAPE)
5707 if (window->shape != MagickFalse)
5708 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5711 window->stasis=MagickFalse;
5715 if (window->image != (
Image *) NULL)
5717 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5718 (ximage->bitmap_bit_order == LSBFirst)))
5719 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5722 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5725 if (window->matte_image != (XImage *) NULL)
5730 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5731 if (window->matte_pixmap != (Pixmap) NULL)
5742 context_values.background=1;
5743 context_values.foreground=0;
5744 graphics_context=XCreateGC(display,window->matte_pixmap,
5745 (
size_t) (GCBackground | GCForeground),&context_values);
5746 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5747 window->matte_image,0,0,0,0,width,height);
5748 (void) XFreeGC(display,graphics_context);
5749 #if defined(MAGICKCORE_HAVE_SHAPE)
5750 if (window->shape != MagickFalse)
5751 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5752 window->matte_pixmap,ShapeSet);
5756 (void) XMakePixmap(display,resource_info,window);
5760 (void) XCheckDefineCursor(display,window->id,window->cursor);
5800 static void XMakeImageLSBFirst(
const XResourceInfo *resource_info,
5801 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image)
5838 assert(resource_info != (XResourceInfo *) NULL);
5839 assert(window != (XWindowInfo *) NULL);
5840 assert(image != (
Image *) NULL);
5841 if (IsEventLogging() != MagickFalse)
5842 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5844 if ((window->immutable == MagickFalse) &&
5845 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5848 size[MaxTextExtent];
5856 image_info=AcquireImageInfo();
5857 (void) CopyMagickString(image_info->filename,
5858 resource_info->image_info->texture != (
char *) NULL ?
5859 resource_info->image_info->texture :
"pattern:checkerboard",
5861 (void) FormatLocaleString(size,MaxTextExtent,
"%.20gx%.20g",(
double)
5862 image->columns,(double) image->rows);
5863 image_info->size=ConstantString(size);
5864 pattern=ReadImage(image_info,&image->exception);
5865 image_info=DestroyImageInfo(image_info);
5866 if (pattern != (
Image *) NULL)
5868 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5869 if (canvas == (
Image *) NULL)
5871 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5872 pattern=DestroyImage(pattern);
5875 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
5876 ximage->bits_per_pixel) >> 3));
5877 map_info=window->map_info;
5878 pixels=window->pixel_info->pixels;
5879 q=(
unsigned char *) ximage->data;
5881 canvas_view=AcquireVirtualCacheView(canvas,&canvas->exception);
5882 if (ximage->format == XYBitmap)
5894 background=(
unsigned char)
5895 (XPixelIntensity(&window->pixel_info->foreground_color) <
5896 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5897 foreground=(
unsigned char)
5898 (XPixelIntensity(&window->pixel_info->background_color) <
5899 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5900 polarity=(
unsigned short) ((GetPixelIntensity(image,
5901 &canvas->colormap[0])) < ((
double) QuantumRange/2.0) ? 1 : 0);
5902 if (canvas->colors == 2)
5903 polarity=GetPixelIntensity(canvas,&canvas->colormap[0]) <
5904 GetPixelIntensity(canvas,&canvas->colormap[1]);
5905 for (y=0; y < (int) canvas->rows; y++)
5907 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5908 &canvas->exception);
5911 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5914 for (x=0; x < (int) canvas->columns; x++)
5917 if (GetPixelIndex(indexes+x) == (IndexPacket) polarity)
5935 if (window->pixel_info->colors != 0)
5936 switch (ximage->bits_per_pixel)
5946 for (y=0; y < (int) canvas->rows; y++)
5948 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
5949 canvas->columns,1,&canvas->exception);
5952 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5954 for (x=0; x < (int) canvas->columns; x++)
5956 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0x0f;
5961 *q=(
unsigned char) pixel;
5967 *q|=(
unsigned char) (pixel << 2);
5973 *q|=(
unsigned char) (pixel << 4);
5979 *q|=(
unsigned char) (pixel << 6);
5998 for (y=0; y < (int) canvas->rows; y++)
6000 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6001 canvas->columns,1,&canvas->exception);
6004 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6006 for (x=0; x < (int) canvas->columns; x++)
6008 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0xf;
6013 *q=(
unsigned char) pixel;
6019 *q|=(
unsigned char) (pixel << 4);
6036 if ((resource_info->color_recovery != MagickFalse) &&
6037 (resource_info->quantize_info->dither != MagickFalse))
6039 XDitherImage(canvas,ximage);
6042 for (y=0; y < (int) canvas->rows; y++)
6044 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6045 canvas->columns,1,&canvas->exception);
6048 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6049 for (x=0; x < (int) canvas->columns; x++)
6051 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6052 *q++=(
unsigned char) pixel;
6069 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6070 for (y=0; y < (int) canvas->rows; y++)
6072 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6073 canvas->columns,1,&canvas->exception);
6076 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6077 for (x=0; x < (int) canvas->columns; x++)
6079 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6080 for (k=0; k < (int) bytes_per_pixel; k++)
6082 *q++=(
unsigned char) (pixel & 0xff);
6092 switch (ximage->bits_per_pixel)
6102 for (y=0; y < (int) canvas->rows; y++)
6105 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6106 canvas->columns,1,&canvas->exception);
6109 for (x=0; x < (int) canvas->columns; x++)
6111 pixel=XGammaPixel(map_info,p);
6117 *q=(
unsigned char) pixel;
6123 *q|=(
unsigned char) (pixel << 2);
6129 *q|=(
unsigned char) (pixel << 4);
6135 *q|=(
unsigned char) (pixel << 6);
6155 for (y=0; y < (int) canvas->rows; y++)
6157 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6158 canvas->columns,1,&canvas->exception);
6162 for (x=0; x < (int) canvas->columns; x++)
6164 pixel=XGammaPixel(map_info,p);
6170 *q=(
unsigned char) pixel;
6176 *q|=(
unsigned char) (pixel << 4);
6194 if ((resource_info->color_recovery != MagickFalse) &&
6195 (resource_info->quantize_info->dither != MagickFalse))
6197 XDitherImage(canvas,ximage);
6200 for (y=0; y < (int) canvas->rows; y++)
6202 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6203 canvas->columns,1,&canvas->exception);
6206 for (x=0; x < (int) canvas->columns; x++)
6208 pixel=XGammaPixel(map_info,p);
6209 *q++=(
unsigned char) pixel;
6218 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6219 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6220 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6221 (map_info->blue_mult == 1))
6226 for (y=0; y < (int) canvas->rows; y++)
6228 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6229 canvas->columns,1,&canvas->exception);
6232 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6233 (blue_gamma != 1.0))
6238 for (x=(
int) canvas->columns-1; x >= 0; x--)
6240 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6241 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6242 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6248 for (x=(
int) canvas->columns-1; x >= 0; x--)
6250 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6251 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6252 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6259 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6260 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6261 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6262 (map_info->blue_mult == 65536L))
6267 for (y=0; y < (int) canvas->rows; y++)
6269 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6270 canvas->columns,1,&canvas->exception);
6273 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6274 (blue_gamma != 1.0))
6279 for (x=(
int) canvas->columns-1; x >= 0; x--)
6281 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6282 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6283 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6289 for (x=(
int) canvas->columns-1; x >= 0; x--)
6291 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6292 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6293 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6310 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6311 for (y=0; y < (int) canvas->rows; y++)
6313 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6314 canvas->columns,1,&canvas->exception);
6317 for (x=0; x < (int) canvas->columns; x++)
6319 pixel=XGammaPixel(map_info,p);
6320 for (k=0; k < (int) bytes_per_pixel; k++)
6322 *q++=(
unsigned char) (pixel & 0xff);
6333 if (matte_image != (XImage *) NULL)
6338 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6339 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6340 q=(
unsigned char *) matte_image->data;
6341 for (y=0; y < (int) canvas->rows; y++)
6343 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6344 &canvas->exception);
6349 for (x=(
int) canvas->columns-1; x >= 0; x--)
6352 if (GetPixelOpacity(p) > (QuantumRange/2))
6368 canvas_view=DestroyCacheView(canvas_view);
6369 if (canvas != image)
6370 canvas=DestroyImage(canvas);
6409 static void XMakeImageMSBFirst(
const XResourceInfo *resource_info,
6410 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image)
6447 assert(resource_info != (XResourceInfo *) NULL);
6448 assert(window != (XWindowInfo *) NULL);
6449 assert(image != (
Image *) NULL);
6450 if (IsEventLogging() != MagickFalse)
6451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
6453 if ((window->immutable != MagickFalse) &&
6454 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6457 size[MaxTextExtent];
6465 image_info=AcquireImageInfo();
6466 (void) CopyMagickString(image_info->filename,
6467 resource_info->image_info->texture != (
char *) NULL ?
6468 resource_info->image_info->texture :
"pattern:checkerboard",
6470 (void) FormatLocaleString(size,MaxTextExtent,
"%.20gx%.20g",(
double)
6471 image->columns,(double) image->rows);
6472 image_info->size=ConstantString(size);
6473 pattern=ReadImage(image_info,&image->exception);
6474 image_info=DestroyImageInfo(image_info);
6475 if (pattern != (
Image *) NULL)
6477 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6478 if (canvas == (
Image *) NULL)
6480 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6481 pattern=DestroyImage(pattern);
6484 scanline_pad=(
unsigned int) (ximage->bytes_per_line-
6485 ((ximage->width*ximage->bits_per_pixel) >> 3));
6486 map_info=window->map_info;
6487 pixels=window->pixel_info->pixels;
6488 q=(
unsigned char *) ximage->data;
6490 canvas_view=AcquireVirtualCacheView(canvas,&canvas->exception);
6491 if (ximage->format == XYBitmap)
6503 background=(
unsigned char)
6504 (XPixelIntensity(&window->pixel_info->foreground_color) <
6505 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6506 foreground=(
unsigned char)
6507 (XPixelIntensity(&window->pixel_info->background_color) <
6508 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6509 polarity=(
unsigned short) ((GetPixelIntensity(image,
6510 &canvas->colormap[0])) < ((
double) QuantumRange/2.0) ? 1 : 0);
6511 if (canvas->colors == 2)
6512 polarity=GetPixelIntensity(canvas,&canvas->colormap[0]) <
6513 GetPixelIntensity(canvas,&canvas->colormap[1]);
6514 for (y=0; y < (int) canvas->rows; y++)
6516 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6517 &canvas->exception);
6520 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6523 for (x=(
int) canvas->columns-1; x >= 0; x--)
6526 if (GetPixelIndex(indexes+x) == (IndexPacket) polarity)
6544 if (window->pixel_info->colors != 0)
6545 switch (ximage->bits_per_pixel)
6555 for (y=0; y < (int) canvas->rows; y++)
6557 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6558 canvas->columns,1,&canvas->exception);
6561 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6563 for (x=0; x < (int) canvas->columns; x++)
6565 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0xf;
6570 *q=(
unsigned char) (pixel << 6);
6576 *q|=(
unsigned char) (pixel << 4);
6582 *q|=(
unsigned char) (pixel << 2);
6588 *q|=(
unsigned char) pixel;
6607 for (y=0; y < (int) canvas->rows; y++)
6609 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6610 canvas->columns,1,&canvas->exception);
6613 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6615 for (x=0; x < (int) canvas->columns; x++)
6617 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)] & 0xf;
6622 *q=(
unsigned char) (pixel << 4);
6628 *q|=(
unsigned char) pixel;
6645 if (resource_info->color_recovery &&
6646 resource_info->quantize_info->dither)
6648 XDitherImage(canvas,ximage);
6651 for (y=0; y < (int) canvas->rows; y++)
6653 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6654 canvas->columns,1,&canvas->exception);
6657 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6658 for (x=0; x < (int) canvas->columns; x++)
6660 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6661 *q++=(
unsigned char) pixel;
6676 channel[
sizeof(size_t)];
6681 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6682 for (y=0; y < (int) canvas->rows; y++)
6684 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6685 canvas->columns,1,&canvas->exception);
6688 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6689 for (x=0; x < (int) canvas->columns; x++)
6691 pixel=pixels[(ssize_t) GetPixelIndex(indexes+x)];
6692 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
6694 channel[k]=(
unsigned char) pixel;
6697 for (k=0; k < (int) bytes_per_pixel; k++)
6706 switch (ximage->bits_per_pixel)
6716 for (y=0; y < (int) canvas->rows; y++)
6718 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6719 canvas->columns,1,&canvas->exception);
6723 for (x=(
int) canvas->columns-1; x >= 0; x--)
6725 pixel=XGammaPixel(map_info,p);
6731 *q=(
unsigned char) (pixel << 6);
6737 *q|=(
unsigned char) (pixel << 4);
6743 *q|=(
unsigned char) (pixel << 2);
6749 *q|=(
unsigned char) pixel;
6769 for (y=0; y < (int) canvas->rows; y++)
6771 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6772 canvas->columns,1,&canvas->exception);
6776 for (x=(
int) canvas->columns-1; x >= 0; x--)
6778 pixel=XGammaPixel(map_info,p);
6784 *q=(
unsigned char) (pixel << 4);
6790 *q|=(
unsigned char) pixel;
6808 if (resource_info->color_recovery &&
6809 resource_info->quantize_info->dither)
6811 XDitherImage(canvas,ximage);
6814 for (y=0; y < (int) canvas->rows; y++)
6816 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6817 canvas->columns,1,&canvas->exception);
6820 for (x=(
int) canvas->columns-1; x >= 0; x--)
6822 pixel=XGammaPixel(map_info,p);
6823 *q++=(
unsigned char) pixel;
6832 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6833 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6834 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6835 (map_info->blue_mult == 1))
6840 for (y=0; y < (int) canvas->rows; y++)
6842 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6843 canvas->columns,1,&canvas->exception);
6846 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6847 (blue_gamma != 1.0))
6852 for (x=(
int) canvas->columns-1; x >= 0; x--)
6855 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6856 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6857 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6862 for (x=(
int) canvas->columns-1; x >= 0; x--)
6865 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6866 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6867 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6873 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6874 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6875 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6876 (map_info->blue_mult == 65536L))
6881 for (y=0; y < (int) canvas->rows; y++)
6883 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6884 canvas->columns,1,&canvas->exception);
6887 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6888 (blue_gamma != 1.0))
6893 for (x=(
int) canvas->columns-1; x >= 0; x--)
6896 *q++=ScaleQuantumToChar(XBlueGamma(GetPixelBlue(p)));
6897 *q++=ScaleQuantumToChar(XGreenGamma(GetPixelGreen(p)));
6898 *q++=ScaleQuantumToChar(XRedGamma(GetPixelRed(p)));
6903 for (x=(
int) canvas->columns-1; x >= 0; x--)
6906 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(p));
6907 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(p));
6908 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(p));
6924 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6925 for (y=0; y < (int) canvas->rows; y++)
6927 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6928 canvas->columns,1,&canvas->exception);
6931 for (x=(
int) canvas->columns-1; x >= 0; x--)
6933 pixel=XGammaPixel(map_info,p);
6934 for (k=(
int) bytes_per_pixel-1; k >= 0; k--)
6936 *q++=(
unsigned char) (pixel & 0xff);
6947 if (matte_image != (XImage *) NULL)
6952 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6953 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6954 q=(
unsigned char *) matte_image->data;
6955 for (y=0; y < (int) canvas->rows; y++)
6957 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6958 &canvas->exception);
6963 for (x=(
int) canvas->columns-1; x >= 0; x--)
6966 if (GetPixelOpacity(p) > (QuantumRange/2))
6982 canvas_view=DestroyCacheView(canvas_view);
6983 if (canvas != image)
6984 canvas=DestroyImage(canvas);
7012 MagickExport
void XMakeMagnifyImage(Display *display,XWindows *windows)
7015 tuple[MaxTextExtent];
7037 previous_magnify = 0;
7057 assert(display != (Display *) NULL);
7058 assert(windows != (XWindows *) NULL);
7059 if (IsEventLogging() != MagickFalse)
7060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7062 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7064 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7066 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7068 while (magnify > windows->magnify.width)
7070 while (magnify > windows->magnify.height)
7075 if (previous_magnify != 0)
7076 magnify=previous_magnify;
7078 if (magnify != previous_magnify)
7090 while ((1 << i) <= (int) magnify)
7092 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7093 "Magnify %.20gX",(
double) i);
7094 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7095 if (status != False)
7097 XSetWMName(display,windows->magnify.id,&window_name);
7098 XSetWMIconName(display,windows->magnify.id,&window_name);
7099 (void) XFree((
void *) window_name.value);
7102 previous_magnify=magnify;
7103 ximage=windows->image.ximage;
7104 width=(
unsigned int) windows->magnify.ximage->width;
7105 height=(
unsigned int) windows->magnify.ximage->height;
7106 if ((windows->magnify.x < 0) ||
7107 (windows->magnify.x >= windows->image.ximage->width))
7108 windows->magnify.x=windows->image.ximage->width >> 1;
7109 x=windows->magnify.x-((width/magnify) >> 1);
7113 if (x > (
int) (ximage->width-(width/magnify)))
7114 x=ximage->width-width/magnify;
7115 if ((windows->magnify.y < 0) ||
7116 (windows->magnify.y >= windows->image.ximage->height))
7117 windows->magnify.y=windows->image.ximage->height >> 1;
7118 y=windows->magnify.y-((height/magnify) >> 1);
7122 if (y > (
int) (ximage->height-(height/magnify)))
7123 y=ximage->height-height/magnify;
7124 q=(
unsigned char *) windows->magnify.ximage->data;
7125 scanline_pad=(
unsigned int) (windows->magnify.ximage->bytes_per_line-
7126 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7127 if (ximage->bits_per_pixel < 8)
7142 pixel_info=windows->magnify.pixel_info;
7143 switch (ximage->bitmap_bit_order)
7152 if (ximage->format == XYBitmap)
7154 background=(
unsigned char)
7155 (XPixelIntensity(&pixel_info->foreground_color) <
7156 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7157 foreground=(
unsigned char)
7158 (XPixelIntensity(&pixel_info->background_color) <
7159 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7160 if (windows->magnify.depth > 1)
7161 Swap(background,foreground);
7163 for (i=0; i < (ssize_t) height; i+=magnify)
7168 for (j=0; j < magnify; j++)
7170 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7171 ((x*ximage->bits_per_pixel) >> 3);
7172 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7175 for (k=0; k < width; k+=magnify)
7180 for (l=0; l < magnify; l++)
7185 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7188 if (*p & (0x01 << (p_bit+plane)))
7201 p_bit+=ximage->bits_per_pixel;
7208 *q=byte >> (8-q_bit);
7224 if (ximage->format == XYBitmap)
7226 background=(
unsigned char)
7227 (XPixelIntensity(&pixel_info->foreground_color) <
7228 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7229 foreground=(
unsigned char)
7230 (XPixelIntensity(&pixel_info->background_color) <
7231 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7232 if (windows->magnify.depth > 1)
7233 Swap(background,foreground);
7235 for (i=0; i < (ssize_t) height; i+=magnify)
7240 for (j=0; j < magnify; j++)
7242 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7243 ((x*ximage->bits_per_pixel) >> 3);
7244 p_bit=(
unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7247 for (k=0; k < width; k+=magnify)
7252 for (l=0; l < magnify; l++)
7257 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7260 if (*p & (0x80 >> (p_bit+plane)))
7273 p_bit+=ximage->bits_per_pixel;
7280 *q=byte << (8-q_bit);
7291 switch (ximage->bits_per_pixel)
7299 for (i=0; i < (ssize_t) height; i+=magnify)
7304 for (j=0; j < magnify; j++)
7306 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7307 ((x*ximage->bits_per_pixel) >> 3);
7308 for (k=0; k < width; k+=magnify)
7313 for (l=0; l < magnify; l++)
7332 bytes_per_pixel=(
unsigned int) ximage->bits_per_pixel >> 3;
7333 for (i=0; i < (ssize_t) height; i+=magnify)
7338 for (j=0; j < magnify; j++)
7340 p=(
unsigned char *) ximage->data+y*ximage->bytes_per_line+
7341 ((x*ximage->bits_per_pixel) >> 3);
7342 for (k=0; k < width; k+=magnify)
7347 for (l=0; l < magnify; l++)
7348 for (m=0; m < bytes_per_pixel; m++)
7362 x=windows->magnify.x-((width/magnify) >> 1);
7364 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7366 if (x > (
int) (ximage->width-(width/magnify)))
7367 x=(
int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7370 y=windows->magnify.y-((height/magnify) >> 1);
7372 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7374 if (y > (
int) (ximage->height-(height/magnify)))
7375 y=(
int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7378 if ((x != 0) || (y != 0))
7379 (void) XFillRectangle(display,windows->magnify.pixmap,
7380 windows->magnify.annotate_context,0,0,width,height);
7381 (void) XPutImage(display,windows->magnify.pixmap,
7382 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7384 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7385 (magnify <= (height >> 1))))
7393 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7394 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7395 highlight_info.width=magnify;
7396 highlight_info.height=magnify;
7397 (void) XDrawRectangle(display,windows->magnify.pixmap,
7398 windows->magnify.highlight_context,(
int) highlight_info.x,
7399 (int) highlight_info.y,(
unsigned int) highlight_info.width-1,
7400 (
unsigned int) highlight_info.height-1);
7402 (void) XDrawRectangle(display,windows->magnify.pixmap,
7403 windows->magnify.annotate_context,(
int) highlight_info.x+1,
7404 (int) highlight_info.y+1,(
unsigned int) highlight_info.width-3,
7405 (
unsigned int) highlight_info.height-3);
7410 (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
7411 windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
7412 &windows->image.image->exception);
7413 (void) FormatLocaleString(tuple,MaxTextExtent,
"%d,%d: ",
7414 windows->magnify.x,windows->magnify.y);
7415 (void) ConcatenateMagickString(tuple,
"(",MaxTextExtent);
7416 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7417 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7418 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7419 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7420 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7421 if (pixel.colorspace == CMYKColorspace)
7423 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7424 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7426 if (pixel.matte != MagickFalse)
7428 (void) ConcatenateMagickString(tuple,
",",MaxTextExtent);
7429 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7431 (void) ConcatenateMagickString(tuple,
")",MaxTextExtent);
7432 height=(
unsigned int) windows->magnify.font_info->ascent+
7433 windows->magnify.font_info->descent;
7434 x=windows->magnify.font_info->max_bounds.width >> 1;
7435 y=windows->magnify.font_info->ascent+(height >> 2);
7436 (void) XDrawImageString(display,windows->magnify.pixmap,
7437 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7438 GetColorTuple(&pixel,MagickTrue,tuple);
7440 (void) XDrawImageString(display,windows->magnify.pixmap,
7441 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7442 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7443 &windows->image.image->exception);
7445 (void) XDrawImageString(display,windows->magnify.pixmap,
7446 windows->magnify.annotate_context,x,y,tuple,(
int) strlen(tuple));
7450 magnify_window=windows->magnify;
7453 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7485 static MagickBooleanType XMakePixmap(Display *display,
7486 const XResourceInfo *resource_info,XWindowInfo *window)
7492 assert(display != (Display *) NULL);
7493 assert(resource_info != (XResourceInfo *) NULL);
7494 assert(window != (XWindowInfo *) NULL);
7495 if (IsEventLogging() != MagickFalse)
7496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7497 (void) resource_info;
7498 if (window->pixmap != (Pixmap) NULL)
7503 (void) XFreePixmap(display,window->pixmap);
7504 window->pixmap=(Pixmap) NULL;
7506 if (window->use_pixmap == MagickFalse)
7507 return(MagickFalse);
7508 if (window->ximage == (XImage *) NULL)
7509 return(MagickFalse);
7513 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7514 (void) XFlush(display);
7518 width=(
unsigned int) window->ximage->width;
7519 height=(
unsigned int) window->ximage->height;
7520 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7521 if (window->pixmap == (Pixmap) NULL)
7526 (void) XCheckDefineCursor(display,window->id,window->cursor);
7527 return(MagickFalse);
7532 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7533 if (window->shared_memory)
7534 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7535 window->ximage,0,0,0,0,width,height,MagickTrue);
7537 if (window->shared_memory == MagickFalse)
7538 (void) XPutImage(display,window->pixmap,window->annotate_context,
7539 window->ximage,0,0,0,0,width,height);
7540 if ((GetLogEventMask() & X11Event) != 0)
7542 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Pixmap:");
7543 (void) LogMagickEvent(X11Event,GetMagickModule(),
" width, height: %ux%u",
7549 (void) XCheckDefineCursor(display,window->id,window->cursor);
7590 #if defined(__cplusplus) || defined(c_plusplus)
7594 static inline MagickRealType DiversityPixelIntensity(
7595 const DiversityPacket *pixel)
7600 intensity=0.298839*(double) pixel->red+0.586811*(
double) pixel->green+
7601 0.114350*(double) pixel->blue;
7605 static int IntensityCompare(
const void *x,
const void *y)
7614 color_1=(DiversityPacket *) x;
7615 color_2=(DiversityPacket *) y;
7616 diversity=(int) (DiversityPixelIntensity(color_2)-
7617 DiversityPixelIntensity(color_1));
7621 static int PopularityCompare(
const void *x,
const void *y)
7627 color_1=(DiversityPacket *) x;
7628 color_2=(DiversityPacket *) y;
7629 return((
int) color_2->count-(int) color_1->count);
7632 #if defined(__cplusplus) || defined(c_plusplus)
7636 static inline Quantum ScaleXToQuantum(
const size_t x,
7639 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7642 MagickExport
void XMakeStandardColormap(Display *display,
7643 XVisualInfo *visual_info,XResourceInfo *resource_info,
Image *image,
7644 XStandardColormap *map_info,XPixelInfo *pixel)
7673 assert(display != (Display *) NULL);
7674 assert(visual_info != (XVisualInfo *) NULL);
7675 assert(map_info != (XStandardColormap *) NULL);
7676 assert(resource_info != (XResourceInfo *) NULL);
7677 assert(pixel != (XPixelInfo *) NULL);
7678 if (IsEventLogging() != MagickFalse)
7679 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
7680 exception=(&image->exception);
7681 if (resource_info->map_type != (
char *) NULL)
7686 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7688 number_colors=(
unsigned int) (map_info->base_pixel+
7689 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7690 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7691 if ((image->matte == MagickFalse) &&
7692 (resource_info->color_recovery == MagickFalse) &&
7693 resource_info->quantize_info->dither &&
7694 (number_colors < MaxColormapSize))
7705 affinity_image=AcquireImage((
ImageInfo *) NULL);
7706 if (affinity_image == (
Image *) NULL)
7707 ThrowXWindowFatalException(ResourceLimitFatalError,
7708 "UnableToDitherImage",image->filename);
7709 affinity_image->columns=number_colors;
7710 affinity_image->rows=1;
7714 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7718 for (i=0; i < (ssize_t) number_colors; i++)
7721 if (map_info->red_max != 0)
7722 SetPixelRed(q,ScaleXToQuantum((
size_t) (i/
7723 map_info->red_mult),map_info->red_max));
7725 if (map_info->green_max != 0)
7726 SetPixelGreen(q,ScaleXToQuantum((
size_t) ((i/
7727 map_info->green_mult) % (map_info->green_max+1)),
7728 map_info->green_max));
7730 if (map_info->blue_max != 0)
7731 SetPixelBlue(q,ScaleXToQuantum((
size_t) (i %
7732 map_info->green_mult),map_info->blue_max));
7733 SetPixelOpacity(q,TransparentOpacity);
7736 (void) SyncAuthenticPixels(affinity_image,exception);
7737 (void) RemapImage(resource_info->quantize_info,image,
7740 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7742 (void) SetImageStorageClass(image,DirectClass);
7743 affinity_image=DestroyImage(affinity_image);
7745 if ((GetLogEventMask() & X11Event) != 0)
7747 (void) LogMagickEvent(X11Event,GetMagickModule(),
7748 "Standard Colormap:");
7749 (void) LogMagickEvent(X11Event,GetMagickModule(),
7750 " colormap id: 0x%lx",map_info->colormap);
7751 (void) LogMagickEvent(X11Event,GetMagickModule(),
7752 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7753 map_info->green_max,map_info->blue_max);
7754 (void) LogMagickEvent(X11Event,GetMagickModule(),
7755 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7756 map_info->green_mult,map_info->blue_mult);
7760 if ((visual_info->klass != DirectColor) &&
7761 (visual_info->klass != TrueColor))
7762 if ((image->storage_class == DirectClass) ||
7763 ((int) image->colors > visual_info->colormap_size))
7771 quantize_info=(*resource_info->quantize_info);
7772 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7773 (
void) QuantizeImage(&quantize_info,image);
7778 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7779 colormap=XDefaultColormap(display,visual_info->screen);
7780 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7781 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7782 visual_info->visual,visual_info->klass == DirectColor ?
7783 AllocAll : AllocNone);
7784 if (colormap == (Colormap) NULL)
7785 ThrowXWindowFatalException(ResourceLimitFatalError,
"UnableToCreateColormap",
7790 XGetMapInfo(visual_info,colormap,map_info);
7791 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7795 switch (visual_info->klass)
7803 number_colors=image->colors;
7804 colors=(XColor *) AcquireQuantumMemory((
size_t)
7805 visual_info->colormap_size,
sizeof(*colors));
7806 if (colors == (XColor *) NULL)
7807 ThrowXWindowFatalException(ResourceLimitFatalError,
7808 "UnableToCreateColormap",image->filename);
7810 color.flags=(char) (DoRed | DoGreen | DoBlue);
7811 for (i=0; i < (ssize_t) image->colors; i++)
7813 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7814 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7815 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7816 if (visual_info->klass != StaticColor)
7818 gray_value=(
unsigned short) XPixelIntensity(&color);
7819 color.red=gray_value;
7820 color.green=gray_value;
7821 color.blue=gray_value;
7823 status=XAllocColor(display,colormap,&color);
7824 if (status == False)
7826 colormap=XCopyColormapAndFree(display,colormap);
7827 (void) XAllocColor(display,colormap,&color);
7829 pixel->pixels[i]=color.pixel;
7843 number_colors=image->colors;
7844 colors=(XColor *) AcquireQuantumMemory((
size_t)
7845 visual_info->colormap_size,
sizeof(*colors));
7846 if (colors == (XColor *) NULL)
7847 ThrowXWindowFatalException(ResourceLimitFatalError,
7848 "UnableToCreateColormap",image->filename);
7852 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7853 (void) XAllocColor(display,colormap,&pixel->background_color);
7854 (void) XAllocColor(display,colormap,&pixel->border_color);
7855 (void) XAllocColor(display,colormap,&pixel->matte_color);
7856 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7857 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7858 (void) XAllocColor(display,colormap,&pixel->depth_color);
7859 (void) XAllocColor(display,colormap,&pixel->trough_color);
7860 for (i=0; i < MaxNumberPens; i++)
7861 (
void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7865 colormap_type=resource_info->colormap;
7866 status=XAllocColorCells(display,colormap,MagickFalse,(
unsigned long *)
7867 NULL,0,pixel->pixels,(
unsigned int) image->colors);
7868 if (status != False)
7869 colormap_type=PrivateColormap;
7870 if (colormap_type == SharedColormap)
7893 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7894 sizeof(*diversity));
7895 if (diversity == (DiversityPacket *) NULL)
7896 ThrowXWindowFatalException(ResourceLimitFatalError,
7897 "UnableToCreateColormap",image->filename);
7898 for (i=0; i < (ssize_t) image->colors; i++)
7900 diversity[i].red=image->colormap[i].red;
7901 diversity[i].green=image->colormap[i].green;
7902 diversity[i].blue=image->colormap[i].blue;
7903 diversity[i].index=(
unsigned short) i;
7904 diversity[i].count=0;
7906 image_view=AcquireAuthenticCacheView(image,exception);
7907 for (y=0; y < (int) image->rows; y++)
7915 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7916 image->columns,1,exception);
7919 indexes=GetCacheViewAuthenticIndexQueue(image_view);
7920 for (x=(
int) image->columns-1; x >= 0; x--)
7921 diversity[(ssize_t) GetPixelIndex(indexes+x)].count++;
7923 image_view=DestroyCacheView(image_view);
7927 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
7929 for (i=0; i < (ssize_t) image->colors; )
7931 diversity[i].count<<=4;
7932 i+=MagickMax((
int) (image->colors >> 4),2);
7934 diversity[image->colors-1].count<<=4;
7935 qsort((
void *) diversity,image->colors,
sizeof(*diversity),
7941 color.flags=(char) (DoRed | DoGreen | DoBlue);
7942 for (i=0; i < (ssize_t) image->colors; i++)
7944 index=diversity[i].index;
7946 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7948 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7950 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7951 if (visual_info->klass != PseudoColor)
7953 gray_value=(
unsigned short) XPixelIntensity(&color);
7954 color.red=gray_value;
7955 color.green=gray_value;
7956 color.blue=gray_value;
7958 status=XAllocColor(display,colormap,&color);
7959 if (status == False)
7961 pixel->pixels[index]=color.pixel;
7967 server_colors=(XColor *) AcquireQuantumMemory((
size_t)
7968 visual_info->colormap_size,
sizeof(*server_colors));
7969 if (server_colors == (XColor *) NULL)
7970 ThrowXWindowFatalException(ResourceLimitFatalError,
7971 "UnableToCreateColormap",image->filename);
7972 for (x=visual_info->colormap_size-1; x >= 0; x--)
7973 server_colors[x].pixel=(size_t) x;
7974 (void) XQueryColors(display,colormap,server_colors,
7975 (
int) MagickMin((
unsigned int) visual_info->colormap_size,256));
7979 for (; i < (ssize_t) image->colors; i++)
7981 index=diversity[i].index;
7983 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7985 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7987 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7988 if (visual_info->klass != PseudoColor)
7990 gray_value=(
unsigned short) XPixelIntensity(&color);
7991 color.red=gray_value;
7992 color.green=gray_value;
7993 color.blue=gray_value;
7995 XBestPixel(display,colormap,server_colors,(
unsigned int)
7996 visual_info->colormap_size,&color);
7997 pixel->pixels[index]=color.pixel;
8000 if ((
int) image->colors < visual_info->colormap_size)
8005 retain_colors=MagickMin((
unsigned int)
8006 (visual_info->colormap_size-image->colors),256);
8007 for (i=0; i < (ssize_t) retain_colors; i++)
8008 *p++=server_colors[i];
8009 number_colors+=retain_colors;
8011 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8012 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8018 if (status == False)
8023 colormap=XCreateColormap(display,
8024 XRootWindow(display,visual_info->screen),visual_info->visual,
8026 if (colormap == (Colormap) NULL)
8027 ThrowXWindowFatalException(ResourceLimitFatalError,
8028 "UnableToCreateColormap",image->filename);
8029 map_info->colormap=colormap;
8030 if ((
int) image->colors < visual_info->colormap_size)
8036 retain_colors=MagickMin((
unsigned int)
8037 (visual_info->colormap_size-image->colors),256);
8038 p=colors+image->colors;
8039 for (i=0; i < (ssize_t) retain_colors; i++)
8041 p->pixel=(
unsigned long) i;
8044 (void) XQueryColors(display,
8045 XDefaultColormap(display,visual_info->screen),
8046 colors+image->colors,(int) retain_colors);
8050 (void) XAllocColorCells(display,colormap,MagickFalse,
8051 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8053 p=colors+image->colors;
8054 for (i=0; i < (ssize_t) retain_colors; i++)
8056 p->pixel=pixel->pixels[i];
8059 (void) XStoreColors(display,colormap,colors+image->colors,
8060 (
int) retain_colors);
8061 number_colors+=retain_colors;
8063 (void) XAllocColorCells(display,colormap,MagickFalse,
8064 (
unsigned long *) NULL,0,pixel->pixels,(
unsigned int)
8071 color.flags=(char) (DoRed | DoGreen | DoBlue);
8072 for (i=0; i < (ssize_t) image->colors; i++)
8074 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8075 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8076 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8077 if (visual_info->klass != PseudoColor)
8079 gray_value=(
unsigned short) XPixelIntensity(&color);
8080 color.red=gray_value;
8081 color.green=gray_value;
8082 color.blue=gray_value;
8084 color.pixel=pixel->pixels[i];
8087 (void) XStoreColors(display,colormap,colors,(
int) image->colors);
8100 number_colors=(
unsigned int) ((map_info->red_max*map_info->red_mult)+
8101 (map_info->green_max*map_info->green_mult)+
8102 (map_info->blue_max*map_info->blue_mult)+1);
8103 linear_colormap=(number_colors > 4096) ||
8104 (((
int) (map_info->red_max+1) == visual_info->colormap_size) &&
8105 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8106 ((
int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8107 MagickTrue : MagickFalse;
8108 if (linear_colormap != MagickFalse)
8109 number_colors=(size_t) visual_info->colormap_size;
8113 colors=(XColor *) AcquireQuantumMemory(number_colors,
sizeof(*colors));
8114 if (colors == (XColor *) NULL)
8115 ThrowXWindowFatalException(ResourceLimitFatalError,
8116 "UnableToCreateColormap",image->filename);
8121 color.flags=(char) (DoRed | DoGreen | DoBlue);
8122 if (linear_colormap != MagickFalse)
8123 for (i=0; i < (ssize_t) number_colors; i++)
8125 color.blue=(
unsigned short) 0;
8126 if (map_info->blue_max != 0)
8127 color.blue=(
unsigned short) ((
size_t)
8128 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8129 color.green=color.blue;
8130 color.red=color.blue;
8131 color.pixel=XStandardPixel(map_info,&color);
8135 for (i=0; i < (ssize_t) number_colors; i++)
8137 color.red=(
unsigned short) 0;
8138 if (map_info->red_max != 0)
8139 color.red=(
unsigned short) ((
size_t)
8140 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8141 color.green=(
unsigned int) 0;
8142 if (map_info->green_max != 0)
8143 color.green=(
unsigned short) ((
size_t)
8144 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8145 map_info->green_max));
8146 color.blue=(
unsigned short) 0;
8147 if (map_info->blue_max != 0)
8148 color.blue=(
unsigned short) ((
size_t)
8149 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8150 color.pixel=XStandardPixel(map_info,&color);
8153 if ((visual_info->klass == DirectColor) &&
8154 (colormap != XDefaultColormap(display,visual_info->screen)))
8155 (void) XStoreColors(display,colormap,colors,(
int) number_colors);
8157 for (i=0; i < (ssize_t) number_colors; i++)
8158 (
void) XAllocColor(display,colormap,&colors[i]);
8162 if ((visual_info->klass != DirectColor) &&
8163 (visual_info->klass != TrueColor))
8168 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8169 &pixel->foreground_color);
8170 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8171 &pixel->background_color);
8172 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8177 pixel->background_color.red=(~pixel->foreground_color.red);
8178 pixel->background_color.green=
8179 (~pixel->foreground_color.green);
8180 pixel->background_color.blue=
8181 (~pixel->foreground_color.blue);
8182 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8183 &pixel->background_color);
8185 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8186 &pixel->border_color);
8187 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8188 &pixel->matte_color);
8189 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8190 &pixel->highlight_color);
8191 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8192 &pixel->shadow_color);
8193 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8194 &pixel->depth_color);
8195 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8196 &pixel->trough_color);
8197 for (i=0; i < MaxNumberPens; i++)
8199 XBestPixel(display,colormap,colors,(
unsigned int) number_colors,
8200 &pixel->pen_colors[i]);
8201 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8203 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8205 colors=(XColor *) RelinquishMagickMemory(colors);
8206 if ((GetLogEventMask() & X11Event) != 0)
8208 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Standard Colormap:");
8209 (void) LogMagickEvent(X11Event,GetMagickModule(),
" colormap id: 0x%lx",
8210 map_info->colormap);
8211 (void) LogMagickEvent(X11Event,GetMagickModule(),
8212 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8213 map_info->green_max,map_info->blue_max);
8214 (void) LogMagickEvent(X11Event,GetMagickModule(),
8215 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8216 map_info->green_mult,map_info->blue_mult);
8257 MagickExport
void XMakeWindow(Display *display,Window parent,
char **argv,
8258 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8259 XWindowInfo *window_info)
8261 #define MinWindowSize 64
8269 static XTextProperty
8282 assert(display != (Display *) NULL);
8283 assert(window_info != (XWindowInfo *) NULL);
8284 if (IsEventLogging() != MagickFalse)
8285 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8286 size_hints=XAllocSizeHints();
8287 if (size_hints == (XSizeHints *) NULL)
8288 ThrowXWindowFatalException(XServerFatalError,
"UnableToMakeXWindow",argv[0]);
8289 size_hints->flags=(int) window_info->flags;
8290 size_hints->x=window_info->x;
8291 size_hints->y=window_info->y;
8292 size_hints->width=(
int) window_info->width;
8293 size_hints->height=(int) window_info->height;
8294 if (window_info->immutable != MagickFalse)
8299 size_hints->min_width=size_hints->width;
8300 size_hints->min_height=size_hints->height;
8301 size_hints->max_width=size_hints->width;
8302 size_hints->max_height=size_hints->height;
8303 size_hints->flags|=PMinSize;
8304 size_hints->flags|=PMaxSize;
8311 size_hints->min_width=(int) window_info->min_width;
8312 size_hints->min_height=(
int) window_info->min_height;
8313 size_hints->flags|=PResizeInc;
8314 size_hints->width_inc=(int) window_info->width_inc;
8315 size_hints->height_inc=(
int) window_info->height_inc;
8316 #if !defined(PRE_R4_ICCCM)
8317 size_hints->flags|=PBaseSize;
8318 size_hints->base_width=size_hints->width_inc;
8319 size_hints->base_height=size_hints->height_inc;
8322 gravity=NorthWestGravity;
8323 if (window_info->geometry != (
char *) NULL)
8326 default_geometry[MaxTextExtent],
8327 geometry[MaxTextExtent];
8338 (void) FormatLocaleString(default_geometry,MaxTextExtent,
"%dx%d",
8339 size_hints->width,size_hints->height);
8340 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8342 while (strlen(p) != 0)
8344 if ((isspace((
int) ((
unsigned char) *p)) == 0) && (*p !=
'%'))
8347 (
void) memmove(p,p+1,MaxTextExtent-(p-geometry));
8349 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8350 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8351 &size_hints->width,&size_hints->height,&gravity);
8352 if ((flags & WidthValue) && (flags & HeightValue))
8353 size_hints->flags|=USSize;
8354 if ((flags & XValue) && (flags & YValue))
8356 size_hints->flags|=USPosition;
8357 window_info->x=size_hints->x;
8358 window_info->y=size_hints->y;
8361 #if !defined(PRE_R4_ICCCM)
8362 size_hints->win_gravity=gravity;
8363 size_hints->flags|=PWinGravity;
8365 if (window_info->id == (Window) NULL)
8366 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8367 (
unsigned int) size_hints->width,(
unsigned int) size_hints->height,
8368 window_info->border_width,(
int) window_info->depth,InputOutput,
8369 window_info->visual,(
unsigned long) window_info->mask,
8370 &window_info->attributes);
8385 (void) XChangeWindowAttributes(display,window_info->id,(
unsigned long)
8386 window_info->mask,&window_info->attributes);
8387 mask=ConfigureNotify;
8388 while (XCheckTypedWindowEvent(display,window_info->id,(
int) mask,&sans_event)) ;
8389 window_changes.x=window_info->x;
8390 window_changes.y=window_info->y;
8391 window_changes.width=(int) window_info->width;
8392 window_changes.height=(
int) window_info->height;
8393 mask=(MagickStatusType) (CWWidth | CWHeight);
8394 if (window_info->flags & USPosition)
8396 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8397 mask,&window_changes);
8399 if (window_info->id == (Window) NULL)
8400 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateWindow",
8402 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8403 if (status == False)
8404 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8406 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8407 if (status == False)
8408 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateTextProperty",
8409 window_info->icon_name);
8410 if (window_info->icon_geometry != (
char *) NULL)
8420 size_hints->flags|=USPosition;
8421 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8422 (
char *) NULL,0,size_hints,&manager_hints->icon_x,
8423 &manager_hints->icon_y,&width,&height,&gravity);
8424 if ((flags & XValue) && (flags & YValue))
8425 manager_hints->flags|=IconPositionHint;
8427 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8428 size_hints,manager_hints,class_hint);
8429 if (window_name.value != (
void *) NULL)
8431 (void) XFree((
void *) window_name.value);
8432 window_name.value=(
unsigned char *) NULL;
8433 window_name.nitems=0;
8435 if (icon_name.value != (
void *) NULL)
8437 (void) XFree((
void *) icon_name.value);
8438 icon_name.value=(
unsigned char *) NULL;
8441 atom_list[0]=XInternAtom(display,
"WM_DELETE_WINDOW",MagickFalse);
8442 atom_list[1]=XInternAtom(display,
"WM_TAKE_FOCUS",MagickFalse);
8443 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8444 (void) XFree((
void *) size_hints);
8445 if (window_info->shape != MagickFalse)
8447 #if defined(MAGICKCORE_HAVE_SHAPE)
8457 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8458 window_info->shape=MagickFalse;
8460 window_info->shape=MagickFalse;
8463 window_info->shape=MagickFalse;
8464 if (window_info->shared_memory != MagickFalse)
8466 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8470 if (XShmQueryExtension(display) == 0)
8471 window_info->shared_memory=MagickFalse;
8473 window_info->shared_memory=MagickFalse;
8476 window_info->image=NewImageList();
8477 window_info->destroy=MagickFalse;
8513 static const char *GetLocaleMonitorMessage(
const char *text)
8516 message[MaxTextExtent],
8525 (void) CopyMagickString(tag,text,MaxTextExtent);
8527 if (p != (
char *) NULL)
8529 (void) FormatLocaleString(message,MaxTextExtent,
"Monitor/%s",tag);
8530 locale_message=GetLocaleMessage(message);
8531 if (locale_message == message)
8533 return(locale_message);
8536 MagickExport MagickBooleanType XMagickProgressMonitor(
const char *tag,
8537 const MagickOffsetType quantum,
const MagickSizeType span,
8538 void *magick_unused(client_data))
8543 magick_unreferenced(client_data);
8545 windows=XSetWindows((XWindows *) ~0);
8546 if (windows == (XWindows *) NULL)
8548 if (windows->info.mapped != MagickFalse)
8549 XProgressMonitorWidget(windows->display,windows,
8550 GetLocaleMonitorMessage(tag),quantum,span);
8580 MagickExport MagickBooleanType XQueryColorDatabase(
const char *target,
8587 *display = (Display *) NULL;
8598 assert(color != (XColor *) NULL);
8602 color->flags=(char) (DoRed | DoGreen | DoBlue);
8603 if ((target == (
char *) NULL) || (*target ==
'\0'))
8604 target=
"#ffffffffffff";
8608 if (display == (Display *) NULL)
8609 display=XOpenDisplay((
char *) NULL);
8610 if (display == (Display *) NULL)
8611 ThrowXWindowFatalException(XServerError,
"ColorIsNotKnownToServer",target);
8612 colormap=XDefaultColormap(display,XDefaultScreen(display));
8613 status=XParseColor(display,colormap,(
char *) target,&xcolor);
8614 if (status == False)
8615 ThrowXWindowException(XServerError,
"ColorIsNotKnownToServer",target)
8618 color->red=xcolor.red;
8619 color->green=xcolor.green;
8620 color->blue=xcolor.blue;
8621 color->flags=xcolor.flags;
8623 return(status != False ? MagickTrue : MagickFalse);
8657 MagickExport
void XQueryPosition(Display *display,
const Window window,
int *x,
int *y)
8669 assert(display != (Display *) NULL);
8670 assert(window != (Window) NULL);
8671 assert(x != (
int *) NULL);
8672 assert(y != (
int *) NULL);
8673 if (IsEventLogging() != MagickFalse)
8674 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8675 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8708 MagickExport
void XRefreshWindow(Display *display,
const XWindowInfo *window,
8709 const XEvent *event)
8719 assert(display != (Display *) NULL);
8720 assert(window != (XWindowInfo *) NULL);
8721 if (IsEventLogging() != MagickFalse)
8722 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8723 if (window->ximage == (XImage *) NULL)
8725 if (event != (XEvent *) NULL)
8732 width=(
unsigned int) event->xexpose.width;
8733 height=(
unsigned int)
event->xexpose.height;
8745 width=window->width;
8746 height=window->height;
8747 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8748 if (window->matte_pixmap != (Pixmap) NULL)
8750 #if defined(MAGICKCORE_HAVE_SHAPE)
8751 if (window->shape != MagickFalse)
8752 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8753 window->matte_pixmap,ShapeSet);
8760 if ((window->ximage->width-(x+window->x)) < (
int) width)
8761 width=(
unsigned int) (window->ximage->width-(x+window->x));
8762 if ((window->ximage->height-(y+window->y)) < (int) height)
8763 height=(
unsigned int) (window->ximage->height-(y+window->y));
8767 if (window->matte_pixmap != (Pixmap) NULL)
8768 (
void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8769 if (window->pixmap != (Pixmap) NULL)
8771 if (window->depth > 1)
8772 (void) XCopyArea(display,window->pixmap,window->id,
8773 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8775 (
void) XCopyPlane(display,window->pixmap,window->id,
8776 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8781 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8782 if (window->shared_memory)
8783 (void) XShmPutImage(display,window->id,window->annotate_context,
8784 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8786 if (window->shared_memory == MagickFalse)
8787 (void) XPutImage(display,window->id,window->annotate_context,
8788 window->ximage,x+window->x,y+window->y,x,y,width,height);
8790 if (window->matte_pixmap != (Pixmap) NULL)
8791 (
void) XSetClipMask(display,window->annotate_context,None);
8792 (void) XFlush(display);
8824 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8825 const char *window,
const char *filename)
8834 assert(filename != (
char *) NULL);
8835 if (IsEventLogging() != MagickFalse)
8836 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
8837 if (display == (Display *) NULL)
8838 display=XOpenDisplay((
char *) NULL);
8839 if (display == (Display *) NULL)
8841 ThrowXWindowException(XServerError,
"UnableToOpenXServer",filename);
8842 return(MagickFalse);
8844 remote_atom=XInternAtom(display,
"IM_PROTOCOLS",MagickFalse);
8845 remote_window=(Window) NULL;
8846 root_window=XRootWindow(display,XDefaultScreen(display));
8847 if (window != (
char *) NULL)
8852 if (isdigit((
int) ((
unsigned char) *window)) != 0)
8853 remote_window=XWindowByID(display,root_window,(Window)
8854 strtol((
char *) window,(
char **) NULL,0));
8855 if (remote_window == (Window) NULL)
8856 remote_window=XWindowByName(display,root_window,window);
8858 if (remote_window == (Window) NULL)
8859 remote_window=XWindowByProperty(display,root_window,remote_atom);
8860 if (remote_window == (Window) NULL)
8862 ThrowXWindowException(XServerError,
"UnableToConnectToRemoteDisplay",
8864 return(MagickFalse);
8869 remote_atom=XInternAtom(display,
"IM_REMOTE_COMMAND",MagickFalse);
8870 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8871 PropModeReplace,(
unsigned char *) filename,(int) strlen(filename));
8872 (void) XSync(display,MagickFalse);
8906 MagickPrivate MagickBooleanType XRenderImage(
Image *image,
8917 *display = (Display *) NULL;
8922 static XAnnotateInfo
8931 static XResourceInfo
8937 static XStandardColormap
8943 if (display == (Display *) NULL)
8954 display=XOpenDisplay(draw_info->server_name);
8955 if (display == (Display *) NULL)
8957 ThrowXWindowException(XServerError,
"UnableToOpenXServer",
8958 draw_info->server_name);
8959 return(MagickFalse);
8964 (void) XSetErrorHandler(XError);
8965 image_info=AcquireImageInfo();
8966 client_name=GetClientName();
8967 resource_database=XGetResourceDatabase(display,client_name);
8968 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
8969 resource_info.close_server=MagickFalse;
8970 resource_info.colormap=PrivateColormap;
8971 resource_info.font=AcquireString(draw_info->font);
8972 resource_info.background_color=AcquireString(
"#ffffffffffff");
8973 resource_info.foreground_color=AcquireString(
"#000000000000");
8974 map_info=XAllocStandardColormap();
8975 visual_info=(XVisualInfo *) NULL;
8976 font_info=(XFontStruct *) NULL;
8977 pixel.pixels=(
unsigned long *) NULL;
8978 if (map_info == (XStandardColormap *) NULL)
8980 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
8982 return(MagickFalse);
8987 visual_info=XBestVisualInfo(display,map_info,&resource_info);
8988 if (visual_info == (XVisualInfo *) NULL)
8990 XFreeResources(display,visual_info,map_info,&pixel,font_info,
8991 &resource_info,(XWindowInfo *) NULL);
8992 ThrowXWindowException(XServerError,
"UnableToGetVisual",
8994 return(MagickFalse);
8996 map_info->colormap=(Colormap) NULL;
9000 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9002 XGetPixelPacket(display,visual_info,map_info,&resource_info,
9003 (
Image *) NULL,&pixel);
9004 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9008 font_info=XBestFont(display,&resource_info,MagickFalse);
9009 if (font_info == (XFontStruct *) NULL)
9011 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9012 &resource_info,(XWindowInfo *) NULL);
9013 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9015 return(MagickFalse);
9017 cache_info=(*draw_info);
9022 XGetAnnotateInfo(&annotate_info);
9023 annotate_info.stencil=ForegroundStencil;
9024 if (cache_info.font != draw_info->font)
9029 (void) XFreeFont(display,font_info);
9030 (void) CloneString(&resource_info.font,draw_info->font);
9031 font_info=XBestFont(display,&resource_info,MagickFalse);
9032 if (font_info == (XFontStruct *) NULL)
9034 ThrowXWindowException(XServerError,
"UnableToLoadFont",
9036 return(MagickFalse);
9039 if (draw_info->debug != MagickFalse)
9040 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9041 "Font %s; pointsize %g",draw_info->font != (
char *) NULL ?
9042 draw_info->font :
"none",draw_info->pointsize);
9043 cache_info=(*draw_info);
9044 annotate_info.font_info=font_info;
9045 annotate_info.text=(
char *) draw_info->text;
9046 annotate_info.width=(
unsigned int) XTextWidth(font_info,draw_info->text,(
int)
9047 strlen(draw_info->text));
9048 annotate_info.height=(
unsigned int) font_info->ascent+font_info->descent;
9049 metrics->pixels_per_em.x=(
double) font_info->max_bounds.width;
9050 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9051 metrics->ascent=(
double) font_info->ascent+4;
9052 metrics->descent=(double) (-font_info->descent);
9053 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9054 metrics->height=font_info->ascent+font_info->descent;
9055 metrics->max_advance=(double) font_info->max_bounds.width;
9056 metrics->bounds.x1=0.0;
9057 metrics->bounds.y1=metrics->descent;
9058 metrics->bounds.x2=metrics->ascent+metrics->descent;
9059 metrics->bounds.y2=metrics->ascent+metrics->descent;
9060 metrics->underline_position=(-2.0);
9061 metrics->underline_thickness=1.0;
9062 if (draw_info->render == MagickFalse)
9064 if (draw_info->fill.opacity == TransparentOpacity)
9069 width=annotate_info.width;
9070 height=annotate_info.height;
9071 if ((draw_info->affine.rx != 0.0) || (draw_info->affine.ry != 0.0))
9073 if (((draw_info->affine.sx-draw_info->affine.sy) == 0.0) &&
9074 ((draw_info->affine.rx+draw_info->affine.ry) == 0.0))
9075 annotate_info.degrees=(180.0/MagickPI)*
9076 atan2(draw_info->affine.rx,draw_info->affine.sx);
9078 (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent,
9079 "%.20gx%.20g%+.20g%+.20g",(
double) width,(double) height,
9080 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9081 draw_info->interline_spacing-0.5));
9082 pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red);
9083 pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green);
9084 pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue);
9085 status=XAnnotateImage(display,&pixel,&annotate_info,image);
9088 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
9090 return(MagickFalse);
9121 MagickExport
void XRetainWindowColors(Display *display,
const Window window)
9132 assert(display != (Display *) NULL);
9133 assert(window != (Window) NULL);
9134 if (IsEventLogging() != MagickFalse)
9135 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9136 property=XInternAtom(display,
"_XSETROOT_ID",MagickFalse);
9137 if (property == (Atom) NULL)
9138 ThrowXWindowFatalException(XServerError,
"UnableToCreateProperty",
9140 pixmap=XCreatePixmap(display,window,1,1,1);
9141 if (pixmap == (Pixmap) NULL)
9142 ThrowXWindowFatalException(XServerError,
"UnableToCreateBitmap",
"");
9143 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9144 (
unsigned char *) &pixmap,1);
9145 (void) XSetCloseDownMode(display,RetainPermanent);
9178 static Window XSelectWindow(Display *display,
RectangleInfo *crop_info)
9180 #define MinimumCropArea (unsigned int) 9
9209 assert(display != (Display *) NULL);
9211 if (IsEventLogging() != MagickFalse)
9212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9213 root_window=XRootWindow(display,XDefaultScreen(display));
9214 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9215 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9216 context_values.function=GXinvert;
9217 context_values.plane_mask=
9218 context_values.background ^ context_values.foreground;
9219 context_values.subwindow_mode=IncludeInferiors;
9220 annotate_context=XCreateGC(display,root_window,(
size_t) (GCBackground |
9221 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9222 if (annotate_context == (GC) NULL)
9223 return(MagickFalse);
9227 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9228 XDefaultScreen(display)),(
char * )
"white",(
char * )
"black");
9229 status=XGrabPointer(display,root_window,MagickFalse,(
unsigned int)
9230 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9231 GrabModeAsync,root_window,target_cursor,CurrentTime);
9232 if (status != GrabSuccess)
9233 ThrowXWindowFatalException(XServerError,
"UnableToGrabMouse",
"");
9238 crop_info->height=0;
9240 target_window=(Window) NULL;
9243 (void) XGrabServer(display);
9246 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9247 (
void) XDrawRectangle(display,root_window,annotate_context,
9248 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9249 (
unsigned int) crop_info->height-1);
9253 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9254 (void) XWindowEvent(display,root_window,ButtonPressMask |
9255 ButtonReleaseMask | ButtonMotionMask,&event);
9256 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9257 (
void) XDrawRectangle(display,root_window,annotate_context,
9258 (
int) crop_info->x,(
int) crop_info->y,(
unsigned int) crop_info->width-1,
9259 (
unsigned int) crop_info->height-1);
9264 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9265 event.xbutton.x,event.xbutton.y);
9266 if (target_window == (Window) NULL)
9267 target_window=root_window;
9268 x_offset=
event.xbutton.x_root;
9269 y_offset=
event.xbutton.y_root;
9270 crop_info->x=(ssize_t) x_offset;
9271 crop_info->y=(ssize_t) y_offset;
9273 crop_info->height=0;
9287 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9288 crop_info->x=(ssize_t) event.xmotion.x;
9289 crop_info->y=(ssize_t)
event.xmotion.y;
9293 if ((
int) crop_info->x < x_offset)
9294 crop_info->width=(
size_t) (x_offset-crop_info->x);
9297 crop_info->width=(size_t) (crop_info->x-x_offset);
9298 crop_info->x=(ssize_t) x_offset;
9300 if ((
int) crop_info->y < y_offset)
9301 crop_info->height=(
size_t) (y_offset-crop_info->y);
9304 crop_info->height=(size_t) (crop_info->y-y_offset);
9305 crop_info->y=(ssize_t) y_offset;
9311 }
while ((target_window == (Window) NULL) || (presses > 0));
9312 (void) XUngrabServer(display);
9313 (void) XUngrabPointer(display,CurrentTime);
9314 (void) XFreeCursor(display,target_cursor);
9315 (void) XFreeGC(display,annotate_context);
9316 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9319 crop_info->height=0;
9321 if ((crop_info->width != 0) && (crop_info->height != 0))
9322 target_window=root_window;
9323 return(target_window);
9355 MagickExport
void XSetCursorState(Display *display,XWindows *windows,
9356 const MagickStatusType state)
9358 assert(display != (Display *) NULL);
9359 assert(windows != (XWindows *) NULL);
9360 if (IsEventLogging() != MagickFalse)
9361 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9364 (void) XCheckDefineCursor(display,windows->image.id,
9365 windows->image.busy_cursor);
9366 (void) XCheckDefineCursor(display,windows->pan.id,
9367 windows->pan.busy_cursor);
9368 (void) XCheckDefineCursor(display,windows->magnify.id,
9369 windows->magnify.busy_cursor);
9370 (void) XCheckDefineCursor(display,windows->command.id,
9371 windows->command.busy_cursor);
9375 (void) XCheckDefineCursor(display,windows->image.id,
9376 windows->image.cursor);
9377 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9378 (void) XCheckDefineCursor(display,windows->magnify.id,
9379 windows->magnify.cursor);
9380 (void) XCheckDefineCursor(display,windows->command.id,
9381 windows->command.cursor);
9382 (void) XCheckDefineCursor(display,windows->command.id,
9383 windows->widget.cursor);
9384 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9386 windows->info.mapped=MagickFalse;
9412 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9415 *windows = (XWindows *) NULL;
9417 if (windows_info != (XWindows *) ~0)
9419 windows=(XWindows *) RelinquishMagickMemory(windows);
9420 windows=windows_info;
9447 MagickExport
void XUserPreferences(XResourceInfo *resource_info)
9449 #if defined(X11_PREFERENCES_PATH)
9451 cache[MaxTextExtent],
9452 filename[MaxTextExtent],
9453 specifier[MaxTextExtent];
9460 preferences_database;
9465 assert(resource_info != (XResourceInfo *) NULL);
9466 client_name=GetClientName();
9467 preferences_database=XrmGetStringDatabase(
"");
9468 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.backdrop",client_name);
9469 value=resource_info->backdrop ?
"True" :
"False";
9470 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9471 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.colormap",client_name);
9472 value=resource_info->colormap == SharedColormap ?
"Shared" :
"Private";
9473 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9474 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.confirmExit",
9476 value=resource_info->confirm_exit ?
"True" :
"False";
9477 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9478 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.confirmEdit",
9480 value=resource_info->confirm_edit ?
"True" :
"False";
9481 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9482 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.displayWarnings",
9484 value=resource_info->display_warnings ?
"True" :
"False";
9485 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9486 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.dither",client_name);
9487 value=resource_info->quantize_info->dither ?
"True" :
"False";
9488 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9489 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.gammaCorrect",
9491 value=resource_info->gamma_correct ?
"True" :
"False";
9492 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9493 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.undoCache",client_name);
9494 (void) FormatLocaleString(cache,MaxTextExtent,
"%.20g",(
double)
9495 resource_info->undo_cache);
9496 XrmPutStringResource(&preferences_database,specifier,cache);
9497 (void) FormatLocaleString(specifier,MaxTextExtent,
"%s.usePixmap",client_name);
9498 value=resource_info->use_pixmap ?
"True" :
"False";
9499 XrmPutStringResource(&preferences_database,specifier,(
char *) value);
9500 (void) FormatLocaleString(filename,MaxTextExtent,
"%s%src",
9501 X11_PREFERENCES_PATH,client_name);
9502 ExpandFilename(filename);
9503 XrmPutFileDatabase(preferences_database,filename);
9532 static const char *XVisualClassName(
const int visual_class)
9534 switch (visual_class)
9536 case StaticGray:
return(
"StaticGray");
9537 case GrayScale:
return(
"GrayScale");
9538 case StaticColor:
return(
"StaticColor");
9539 case PseudoColor:
return(
"PseudoColor");
9540 case TrueColor:
return(
"TrueColor");
9541 case DirectColor:
return(
"DirectColor");
9543 return(
"unknown visual class");
9574 MagickExport
void XWarning(
const ExceptionType magick_unused(warning),
9575 const char *reason,
const char *description)
9578 text[MaxTextExtent];
9583 magick_unreferenced(warning);
9585 if (reason == (
char *) NULL)
9587 (void) CopyMagickString(text,reason,MaxTextExtent);
9588 (void) ConcatenateMagickString(text,
":",MaxTextExtent);
9589 windows=XSetWindows((XWindows *) ~0);
9590 XNoticeWidget(windows->display,windows,text,(
char *) description);
9623 MagickExport Window XWindowByID(Display *display,
const Window root_window,
9643 assert(display != (Display *) NULL);
9644 assert(root_window != (Window) NULL);
9645 if (IsEventLogging() != MagickFalse)
9646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9648 return(XSelectWindow(display,&rectangle_info));
9649 if (root_window ==
id)
9650 return(root_window);
9651 status=XQueryTree(display,root_window,&child,&child,&children,
9653 if (status == False)
9654 return((Window) NULL);
9655 window=(Window) NULL;
9656 for (i=0; i < (int) number_children; i++)
9661 window=XWindowByID(display,children[i],
id);
9662 if (window != (Window) NULL)
9665 if (children != (Window *) NULL)
9666 (void) XFree((
void *) children);
9702 MagickExport Window XWindowByName(Display *display,
const Window root_window,
9722 assert(display != (Display *) NULL);
9723 assert(root_window != (Window) NULL);
9724 assert(name != (
char *) NULL);
9725 if (IsEventLogging() != MagickFalse)
9726 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",name);
9727 if (XGetWMName(display,root_window,&window_name) != 0)
9728 if (LocaleCompare((
char *) window_name.value,name) == 0)
9729 return(root_window);
9730 status=XQueryTree(display,root_window,&child,&child,&children,
9732 if (status == False)
9733 return((Window) NULL);
9734 window=(Window) NULL;
9735 for (i=0; i < (int) number_children; i++)
9740 window=XWindowByName(display,children[i],name);
9741 if (window != (Window) NULL)
9744 if (children != (Window *) NULL)
9745 (void) XFree((
void *) children);
9780 MagickExport Window XWindowByProperty(Display *display,
const Window window,
9781 const Atom property)
9809 assert(display != (Display *) NULL);
9810 assert(window != (Window) NULL);
9811 assert(property != (Atom) NULL);
9812 if (IsEventLogging() != MagickFalse)
9813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
9814 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9815 if (status == False)
9816 return((Window) NULL);
9818 child=(Window) NULL;
9819 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9821 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9822 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9824 (void) XFree((
void *) data);
9825 if ((status == Success) && (type != (Atom) NULL))
9828 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9829 child=XWindowByProperty(display,children[i],property);
9830 if (children != (Window *) NULL)
9831 (
void) XFree((
void *) children);
9863 assert(image_info != (
const ImageInfo *) NULL);
9864 assert(image_info->signature == MagickCoreSignature);
9866 if (IsEventLogging() != MagickFalse)
9867 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
9868 image_info->filename);
9870 return((
Image *) NULL);
9903 MagickPrivate MagickBooleanType XRenderImage(
Image *image,
9909 (void) ThrowMagickException(&image->exception,GetMagickModule(),
9910 MissingDelegateError,
"DelegateLibrarySupportNotBuiltIn",
"`%s' (X11)",
9912 return(MagickFalse);
9934 MagickExport MagickBooleanType XComponentGenesis(
void)
9961 MagickExport
void XGetImportInfo(
XImportInfo *ximage_info)
9964 ximage_info->frame=MagickFalse;
9965 ximage_info->borders=MagickFalse;
9966 ximage_info->screen=MagickFalse;
9967 ximage_info->descend=MagickTrue;
9968 ximage_info->silent=MagickFalse;