92 #if defined(MAGICKCORE_X11_DELEGATE) 93 #include <X11/Xproto.h> 94 #include <X11/Xlocale.h> 95 #if defined(MAGICK_HAVE_POLL) 96 # include <sys/poll.h> 98 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 99 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H) 100 # include <machine/param.h> 104 #include <X11/extensions/XShm.h> 106 #if defined(MAGICKCORE_HAVE_SHAPE) 107 #include <X11/extensions/shape.h> 113 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \ 114 (color) : ((pow(((double) QuantumScale*(color)),1.0* \ 115 PerceptibleReciprocal((double) blue_gamma))*QuantumRange))) 116 #define XGammaPacket(map,color) (size_t) (map->base_pixel+ \ 117 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \ 119 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \ 121 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \ 123 #define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \ 124 ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \ 126 ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \ 128 ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \ 130 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \ 131 (color) : ((pow(((double) QuantumScale*(color)),1.0* \ 132 PerceptibleReciprocal((double) green_gamma))*QuantumRange))) 133 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \ 134 (color) : ((pow(((double) QuantumScale*(color)),1.0* \ 135 PerceptibleReciprocal((double) red_gamma))*QuantumRange))) 136 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \ 137 (((color)->red*map->red_max/65535L)*map->red_mult)+ \ 138 (((color)->green*map->green_max/65535L)*map->green_mult)+ \ 139 (((color)->blue*map->blue_max/65535L)*map->blue_mult)) 141 #define AccentuateModulate ScaleCharToQuantum(80) 142 #define HighlightModulate ScaleCharToQuantum(125) 143 #define ShadowModulate ScaleCharToQuantum(135) 144 #define DepthModulate ScaleCharToQuantum(185) 145 #define TroughModulate ScaleCharToQuantum(110) 147 #define XLIB_ILLEGAL_ACCESS 1 149 #undef NorthWestGravity 151 #undef NorthEastGravity 155 #undef SouthWestGravity 157 #undef SouthEastGravity 164 #define XFD_SET fd_set 184 typedef struct _DiversityPacket
208 *XVisualClassName(
const int);
216 XMakePixmap(Display *,
const XResourceInfo *,XWindowInfo *);
219 XMakeImageLSBFirst(
const XResourceInfo *,
const XWindowInfo *,
Image *,
221 XMakeImageMSBFirst(
const XResourceInfo *,
const XWindowInfo *,
Image *,
256 *magick_windows[MaxXWindows];
262 windows=XSetWindows((XWindows *) ~0);
263 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
266 magick_windows[number_windows++]=(&windows->context);
267 magick_windows[number_windows++]=(&windows->group_leader);
268 magick_windows[number_windows++]=(&windows->backdrop);
269 magick_windows[number_windows++]=(&windows->icon);
270 magick_windows[number_windows++]=(&windows->image);
271 magick_windows[number_windows++]=(&windows->info);
272 magick_windows[number_windows++]=(&windows->magnify);
273 magick_windows[number_windows++]=(&windows->pan);
274 magick_windows[number_windows++]=(&windows->command);
275 magick_windows[number_windows++]=(&windows->widget);
276 magick_windows[number_windows++]=(&windows->popup);
277 for (i=0; i < (int) number_windows; i++)
282 magick_windows[i]->screen);
285 if (magick_windows[i]->name != (
char *) NULL)
286 magick_windows[i]->name=(
char *)
288 if (magick_windows[i]->icon_name != (
char *) NULL)
289 magick_windows[i]->icon_name=(
char *)
291 if (magick_windows[i]->cursor != (Cursor) NULL)
293 (void)
XFreeCursor(windows->display,magick_windows[i]->cursor);
294 magick_windows[i]->cursor=(Cursor) NULL;
296 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
298 (void)
XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
299 magick_windows[i]->busy_cursor=(Cursor) NULL;
301 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
304 magick_windows[i]->highlight_stipple);
305 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
307 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
309 (void)
XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
310 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
312 if (magick_windows[i]->matte_image != (XImage *) NULL)
314 XDestroyImage(magick_windows[i]->matte_image);
315 magick_windows[i]->matte_image=(XImage *) NULL;
317 if (magick_windows[i]->ximage != (XImage *) NULL)
319 XDestroyImage(magick_windows[i]->ximage);
320 magick_windows[i]->ximage=(XImage *) NULL;
322 if (magick_windows[i]->pixmap != (Pixmap) NULL)
324 (void)
XFreePixmap(windows->display,magick_windows[i]->pixmap);
325 magick_windows[i]->pixmap=(Pixmap) NULL;
327 if (magick_windows[i]->
id != (Window) NULL)
330 magick_windows[i]->id=(Window) NULL;
334 if (magick_windows[i]->image != (
Image *) NULL)
336 magick_windows[i]->image=
DestroyImage(magick_windows[i]->image);
339 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
342 magick_windows[i]->matte_pixmap);
343 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
346 if (magick_windows[i]->segment_info != (
void *) NULL)
348 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 352 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
353 if (segment_info != (XShmSegmentInfo *) NULL)
354 if (segment_info[0].shmid >= 0)
356 if (segment_info[0].shmaddr != NULL)
357 (void) shmdt(segment_info[0].shmaddr);
358 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
359 segment_info[0].shmaddr=NULL;
360 segment_info[0].shmid=(-1);
363 magick_windows[i]->segment_info=(
void *)
367 windows->icon_resources=(XResourceInfo *)
369 if (windows->icon_pixel != (XPixelInfo *) NULL)
371 if (windows->icon_pixel->pixels != (
unsigned long *) NULL)
372 windows->icon_pixel->pixels=(
unsigned long *)
374 if (windows->icon_pixel->annotate_context != (GC) NULL)
375 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
376 windows->icon_pixel=(XPixelInfo *)
379 if (windows->pixel_info != (XPixelInfo *) NULL)
381 if (windows->pixel_info->pixels != (
unsigned long *) NULL)
382 windows->pixel_info->pixels=(
unsigned long *)
384 if (windows->pixel_info->annotate_context != (GC) NULL)
385 XFreeGC(windows->display,windows->pixel_info->annotate_context);
386 if (windows->pixel_info->widget_context != (GC) NULL)
387 XFreeGC(windows->display,windows->pixel_info->widget_context);
388 if (windows->pixel_info->highlight_context != (GC) NULL)
389 XFreeGC(windows->display,windows->pixel_info->highlight_context);
390 windows->pixel_info=(XPixelInfo *)
393 if (windows->font_info != (XFontStruct *) NULL)
395 XFreeFont(windows->display,windows->font_info);
396 windows->font_info=(XFontStruct *) NULL;
398 if (windows->class_hints != (XClassHint *) NULL)
400 if (windows->class_hints->res_name != (
char *) NULL)
402 windows->class_hints->res_name);
403 if (windows->class_hints->res_class != (
char *) NULL)
405 windows->class_hints->res_class);
406 XFree(windows->class_hints);
407 windows->class_hints=(XClassHint *) NULL;
409 if (windows->manager_hints != (XWMHints *) NULL)
411 XFree(windows->manager_hints);
412 windows->manager_hints=(XWMHints *) NULL;
414 if (windows->map_info != (XStandardColormap *) NULL)
416 XFree(windows->map_info);
417 windows->map_info=(XStandardColormap *) NULL;
419 if (windows->icon_map != (XStandardColormap *) NULL)
421 XFree(windows->icon_map);
422 windows->icon_map=(XStandardColormap *) NULL;
424 if (windows->visual_info != (XVisualInfo *) NULL)
426 XFree(windows->visual_info);
427 windows->visual_info=(XVisualInfo *) NULL;
429 if (windows->icon_visual != (XVisualInfo *) NULL)
431 XFree(windows->icon_visual);
432 windows->icon_visual=(XVisualInfo *) NULL;
434 (void) XSetWindows((XWindows *) NULL);
471 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,
Image *image,
510 assert(display != (Display *) NULL);
511 assert(pixel != (XPixelInfo *) NULL);
512 assert(annotate_info != (XAnnotateInfo *) NULL);
513 assert(image != (
Image *) NULL);
521 annotate_pixmap=
XCreatePixmap(display,root_window,annotate_info->width,
522 annotate_info->height,depth);
523 if (annotate_pixmap == (Pixmap) NULL)
528 context_values.background=0;
529 context_values.foreground=(size_t) (~0);
530 context_values.font=annotate_info->font_info->fid;
531 annotate_context=
XCreateGC(display,root_window,(
unsigned long)
532 (GCBackground | GCFont | GCForeground),&context_values);
533 if (annotate_context == (GC) NULL)
539 (
int) annotate_info->font_info->ascent,annotate_info->text,
540 (int) strlen(annotate_info->text));
541 (void)
XFreeGC(display,annotate_context);
545 annotate_ximage=
XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
546 annotate_info->height,AllPlanes,ZPixmap);
547 if (annotate_ximage == (XImage *) NULL)
554 if (annotate_image == (
Image *) NULL)
556 annotate_image->
columns=annotate_info->width;
557 annotate_image->
rows=annotate_info->height;
561 width=(
unsigned int) image->
columns;
562 height=(
unsigned int) image->
rows;
565 (void)
XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
568 if (annotate_info->stencil == ForegroundStencil)
571 for (y=0; y < (int) annotate_image->
rows; y++)
580 annotate_image->
columns,1,exception);
583 for (x=0; x < (int) annotate_image->
columns; x++)
586 if (XGetPixel(annotate_ximage,x,y) == 0)
592 pixel->box_color.red),q);
594 pixel->box_color.green),q);
596 pixel->box_color.blue),q);
597 if ((annotate_info->stencil == ForegroundStencil) ||
598 (annotate_info->stencil == OpaqueStencil))
607 pixel->pen_color.red),q);
609 pixel->pen_color.green),q);
611 pixel->pen_color.blue),q);
612 if (annotate_info->stencil == BackgroundStencil)
621 XDestroyImage(annotate_ximage);
625 (void)
XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
626 if ((width != (
unsigned int) annotate_image->
columns) ||
627 (height != (
unsigned int) annotate_image->
rows))
637 (void)
TransformImage(&annotate_image,(
char *) NULL,image_geometry,
640 if (annotate_info->degrees != 0.0)
654 rotate_image=
RotateImage(annotate_image,annotate_info->degrees,exception);
655 if (rotate_image == (
Image *) NULL)
658 annotate_image=rotate_image;
662 normalized_degrees=annotate_info->degrees;
663 while (normalized_degrees < -45.0)
664 normalized_degrees+=360.0;
665 for (rotations=0; normalized_degrees > 45.0; rotations++)
666 normalized_degrees-=90.0;
667 switch (rotations % 4)
677 x-=(int) annotate_image->
columns/2;
678 y+=(
int) annotate_image->
columns/2;
686 x=x-(int) annotate_image->
columns;
694 x=x-(int) annotate_image->
columns/2;
695 y=y-(
int) (annotate_image->
rows-(annotate_image->
columns/2));
703 (void)
XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
746 static char **FontToList(
char *font)
761 if (font == (
char *) NULL)
762 return((
char **) NULL);
767 for (p=font; *p !=
'\0'; p++)
768 if ((*p ==
':') || (*p ==
';') || (*p ==
','))
771 if (fontlist == (
char **) NULL)
774 return((
char **) NULL);
777 for (i=0; i < (int) fonts; i++)
779 for (q=p; *q !=
'\0'; q++)
780 if ((*q ==
':') || (*q ==
';') || (*q ==
','))
783 sizeof(*fontlist[i]));
784 if (fontlist[i] == (
char *) NULL)
787 return((
char **) NULL);
792 fontlist[i]=(
char *) NULL;
802 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
803 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
804 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
805 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
806 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
807 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
814 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
815 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
816 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
830 font_info=(XFontStruct *) NULL;
834 if ((font_name != (
char *) NULL) && (*font_name !=
'\0'))
845 fontlist=FontToList(font_name);
846 if (fontlist != (
char **) NULL)
848 for (i=0; fontlist[i] != (
char *) NULL; i++)
850 if (font_info == (XFontStruct *) NULL)
856 if (font_info == (XFontStruct *) NULL)
857 ThrowXWindowException(
XServerError,
"UnableToLoadFont",font_name);
867 while (*p != (
char *) NULL)
869 if (font_info != (XFontStruct *) NULL)
904 MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
930 assert(display != (Display *) NULL);
931 assert(window != (XWindowInfo *) NULL);
932 assert(image != (
Image *) NULL);
935 window->width=MaxIconSize;
936 window->height=MaxIconSize;
937 icon_size=(XIconSize *) NULL;
940 if (
XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
941 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
943 if (icon_size == (XIconSize *) NULL)
949 if (icon_size == (XIconSize *) NULL)
955 icon_size->min_width=1;
956 icon_size->max_width=MaxIconSize;
957 icon_size->min_height=1;
958 icon_size->max_height=MaxIconSize;
959 icon_size->width_inc=1;
960 icon_size->height_inc=1;
965 width=(
unsigned int) image->
columns;
966 height=(
unsigned int) image->
rows;
968 if (window->crop_geometry)
969 (void)
XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
973 scale_factor=(double) icon_size->max_width/width;
974 if (scale_factor > ((
double) icon_size->max_height/height))
975 scale_factor=(double) icon_size->max_height/height;
976 icon_width=(
unsigned int) icon_size->min_width;
977 while ((
int) icon_width < icon_size->max_width)
979 if (icon_width >= (
unsigned int) (scale_factor*width+0.5))
981 icon_width+=icon_size->width_inc;
983 icon_height=(
unsigned int) icon_size->min_height;
984 while ((
int) icon_height < icon_size->max_height)
986 if (icon_height >= (
unsigned int) (scale_factor*height+0.5))
988 icon_height+=icon_size->height_inc;
990 (void)
XFree((
void *) icon_size);
991 window->width=icon_width;
992 window->height=icon_height;
1034 XColor *colors,
unsigned int number_colors,XColor *color)
1058 assert(display != (Display *) NULL);
1059 assert(color != (XColor *) NULL);
1063 if (status != False)
1072 if (colors == (XColor *) NULL)
1078 for (i=0; i < (int) number_colors; i++)
1079 colors[i].pixel=(
size_t) i;
1080 if (number_colors > 256)
1082 (void)
XQueryColors(display,colormap,colors,(
int) number_colors);
1087 for (i=0; i < (int) number_colors; i++)
1089 pixel.
red=colors[i].red-(double) color->red;
1090 distance=pixel.
red*pixel.
red;
1091 if (distance > min_distance)
1093 pixel.
green=colors[i].green-(double) color->green;
1095 if (distance > min_distance)
1097 pixel.
blue=colors[i].blue-(double) color->blue;
1099 if (distance > min_distance)
1101 min_distance=distance;
1102 color->pixel=colors[i].pixel;
1155 MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
1158 #define MaxStandardColormaps 7 1159 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\ 1160 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \ 1161 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \ 1162 (unsigned long) visual_info->colormap_size),1UL << visual_info->depth) 1190 assert(display != (Display *) NULL);
1191 assert(map_info != (XStandardColormap *) NULL);
1197 visual_mask=VisualScreenMask;
1202 if (
resource_info->colors <= (one << (
size_t) visual_template.depth))
1203 visual_mask|=VisualDepthMask;
1204 if (visual_type != (
char *) NULL)
1211 visual_mask|=VisualClassMask;
1212 visual_template.klass=StaticGray;
1217 visual_mask|=VisualClassMask;
1218 visual_template.klass=GrayScale;
1223 visual_mask|=VisualClassMask;
1224 visual_template.klass=StaticColor;
1229 visual_mask|=VisualClassMask;
1230 visual_template.klass=PseudoColor;
1235 visual_mask|=VisualClassMask;
1236 visual_template.klass=TrueColor;
1241 visual_mask|=VisualClassMask;
1242 visual_template.klass=DirectColor;
1247 visual_mask|=VisualIDMask;
1252 if (isdigit((
int) ((
unsigned char) *visual_type)) != 0)
1254 visual_mask|=VisualIDMask;
1255 visual_template.visualid=
1256 strtol(visual_type,(
char **) NULL,0);
1260 "UnrecognizedVisualSpecifier",visual_type);
1268 visual_mask=VisualScreenMask | VisualIDMask;
1269 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1274 ThrowXWindowException(
XServerWarning,
"UnableToGetVisual",visual_type);
1279 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1280 return((XVisualInfo *) NULL);
1282 XVisualClassName(visual_list->klass));
1285 if ((map_info != (XStandardColormap *) NULL) && (map_type != (
char *) NULL))
1318 "RGB_%s_MAP",map_type);
1321 if (map_property != (Atom) NULL)
1328 *colormap[MaxStandardColormaps]=
1330 "_HP_RGB_SMOOTH_MAP_LIST",
1342 for (i=0; i < MaxStandardColormaps; i++)
1345 if (map_property == (Atom) NULL)
1349 if (status != False)
1354 if (status == False)
1356 ThrowXWindowException(
XServerError,
"UnableToGetStandardColormap",
1358 return((XVisualInfo *) NULL);
1363 *map_info=map_list[0];
1364 #if !defined(PRE_R4_ICCCM) 1366 for (i=0; i < number_maps; i++)
1367 for (j=0; j < number_visuals; j++)
1368 if (map_list[i].visualid ==
1371 *map_info=map_list[i];
1373 visual_list[j].visual);
1376 if (map_info->visualid != visual_template.visualid)
1379 "UnableToMatchVisualToStandardColormap",map_type);
1380 return((XVisualInfo *) NULL);
1383 if (map_info->colormap == (
Colormap) NULL)
1385 ThrowXWindowException(
XServerError,
"StandardColormapIsNotInitialized",
1387 return((XVisualInfo *) NULL);
1389 (void)
XFree((
void *) map_list);
1393 static const unsigned int 1410 visual_info=visual_list;
1412 for (i=1; i < number_visuals; i++)
1415 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1418 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1419 if (rank[p->klass] > rank[visual_info->klass])
1424 (void)
XFree((
void *) visual_list);
1430 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1431 return((XVisualInfo *) NULL);
1432 return(visual_info);
1462 MagickPrivate int XCheckDefineCursor(Display *display,Window window,
1465 assert(display != (Display *) NULL);
1499 MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
1507 assert(display != (Display *) NULL);
1508 assert(windows != (XWindows *) NULL);
1511 XDelay(display,SuspendTime);
1512 id=windows->command.id;
1514 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1515 id=windows->image.id;
1517 XRefreshWindow(display,&windows->image,&event);
1518 XDelay(display,SuspendTime << 1);
1519 id=windows->command.id;
1521 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1522 id=windows->image.id;
1524 XRefreshWindow(display,&windows->image,&event);
1559 MagickPrivate void XClientMessage(Display *display,
const Window window,
1560 const Atom protocol,
const Atom reason,
const Time timestamp)
1565 assert(display != (Display *) NULL);
1566 (void) memset(&client_event,0,
sizeof(client_event));
1567 client_event.type=ClientMessage;
1568 client_event.window=window;
1569 client_event.message_type=protocol;
1570 client_event.format=32;
1571 client_event.data.l[0]=(long) reason;
1572 client_event.data.l[1]=(long) timestamp;
1608 static Window XClientWindow(Display *display,Window target_window)
1630 assert(display != (Display *) NULL);
1634 if (state == (Atom) NULL)
1635 return(target_window);
1638 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1639 if ((status == Success) && (type != (Atom) NULL))
1640 return(target_window);
1641 client_window=XWindowByProperty(display,target_window,state);
1642 if (client_window == (Window) NULL)
1643 return(target_window);
1644 return(client_window);
1667 DestroyXResources();
1703 MagickPrivate void XConfigureImageColormap(Display *display,
1714 XCheckRefreshWindows(display,windows);
1715 XMakeStandardColormap(display,windows->visual_info,
resource_info,image,
1716 windows->map_info,windows->pixel_info,exception);
1717 colormap=windows->map_info->colormap;
1726 XClientMessage(display,windows->image.id,windows->im_protocols,
1727 windows->im_update_colormap,CurrentTime);
1756 MagickPrivate void XConstrainWindowPosition(Display *display,
1757 XWindowInfo *window_info)
1762 assert(display != (Display *) NULL);
1763 assert(window_info != (XWindowInfo *) NULL);
1766 limit=
XDisplayWidth(display,window_info->screen)-window_info->width;
1767 if (window_info->x < 0)
1770 if (window_info->x > (
int) limit)
1771 window_info->x=(int) limit;
1772 limit=
XDisplayHeight(display,window_info->screen)-window_info->height;
1773 if (window_info->y < 0)
1776 if (window_info->y > limit)
1777 window_info->y=limit;
1807 MagickPrivate void XDelay(Display *display,
const size_t milliseconds)
1809 assert(display != (Display *) NULL);
1879 MagickPrivate void XDestroyWindowColors(Display *display,Window window)
1901 assert(display != (Display *) NULL);
1905 if (property == (Atom) NULL)
1907 ThrowXWindowException(
XServerError,
"UnableToCreateProperty",
1912 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1913 if (status != Success)
1915 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1917 (void)
XKillClient(display,(XID) (*((Pixmap *) data)));
1921 (void)
XFree((
void *) data);
1989 assert(display != (Display *) NULL);
1991 assert(windows != (XWindows *) NULL);
1992 assert(image != (
Image *) NULL);
1997 if (unique_file != -1)
1998 file=fdopen(unique_file,
"w");
1999 if ((unique_file == -1) || (file == (FILE *) NULL))
2001 XNoticeWidget(display,windows,
"Unable to display image info",filename);
2012 XVisualClassName((
int) windows->image.storage_class));
2014 if (windows->visual_info->colormap_size != 0)
2016 windows->visual_info->colormap_size);
2022 windows->image.ximage->width,windows->image.ximage->height);
2023 if (windows->image.crop_geometry != (
char *) NULL)
2025 windows->image.crop_geometry);
2026 if (windows->image.pixmap == (Pixmap) NULL)
2047 for (levels=0; undo_image != (
Image *) NULL; levels++)
2055 ((bytes+(1 << 19)) >> 20));
2062 (void) fclose(file);
2065 if (text == (
char *) NULL)
2067 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
2068 "UnableToDisplayImageInfo");
2072 if (textlist != (
char **) NULL)
2080 (void)
XWithdrawWindow(display,windows->info.id,windows->info.screen);
2084 (
char const **) textlist);
2085 for (i=0; textlist[i] != (
char *) NULL; i++)
2124 static const short int 2127 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2128 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2130 dither_green[2][16]=
2132 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2133 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2137 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2138 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2176 for (i=0; i < 2; i++)
2177 for (j=0; j < 16; j++)
2182 sizeof(*green_map));
2189 for (i=0; i < 2; i++)
2190 for (j=0; j < 16; j++)
2191 for (x=0; x < 256; x++)
2196 value+=dither_red[i][j];
2197 red_map[i][j][x]=(
unsigned char)
2198 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2202 value+=dither_green[i][j];
2203 green_map[i][j][x]=(
unsigned char)
2204 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2208 value+=((size_t) dither_blue[i][j] << 1);
2209 blue_map[i][j][x]=(
unsigned char)
2210 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2215 scanline_pad=(
unsigned int) (ximage->bytes_per_line-
2216 ((
size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2221 for (y=0; y < (int) image->
rows; y++)
2225 if (p == (
const Quantum *) NULL)
2227 for (x=0; x < (int) image->
columns; x++)
2230 (int) ScaleQuantumToChar(
GetPixelRed(image,p))] << 8));
2234 (int) ScaleQuantumToChar(
GetPixelBlue(image,p))] << 8));
2235 pixel=(size_t) (((
size_t) color.
red & 0xe0) |
2236 (((
size_t) color.
green & 0xe0) >> 3) |
2237 (((size_t) color.
blue & 0xc0) >> 6));
2253 for (i=0; i < 2; i++)
2254 for (j=0; j < 16; j++)
2295 const XPixelInfo *pixel,XDrawInfo *draw_info,
Image *image,
2334 assert(display != (Display *) NULL);
2335 assert(pixel != (XPixelInfo *) NULL);
2336 assert(draw_info != (XDrawInfo *) NULL);
2337 assert(image != (
Image *) NULL);
2345 draw_pixmap=
XCreatePixmap(display,root_window,draw_info->width,
2346 draw_info->height,depth);
2347 if (draw_pixmap == (Pixmap) NULL)
2352 context_values.background=(size_t) (~0);
2353 context_values.foreground=0;
2354 context_values.line_width=(int) draw_info->line_width;
2355 draw_context=
XCreateGC(display,root_window,(
size_t)
2356 (GCBackground | GCForeground | GCLineWidth),&context_values);
2357 if (draw_context == (GC) NULL)
2362 (void)
XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2369 if (draw_info->stipple != (Pixmap) NULL)
2371 (void)
XSetFillStyle(display,draw_context,FillOpaqueStippled);
2372 (void)
XSetStipple(display,draw_context,draw_info->stipple);
2374 switch (draw_info->element)
2379 (void)
XDrawLines(display,draw_pixmap,draw_context,
2380 draw_info->coordinate_info,(
int) draw_info->number_coordinates,
2386 (void)
XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2387 draw_info->line_info.y1,draw_info->line_info.x2,
2388 draw_info->line_info.y2);
2391 case RectangleElement:
2394 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2395 (
unsigned int) draw_info->rectangle_info.width,
2396 (
unsigned int) draw_info->rectangle_info.height);
2399 case FillRectangleElement:
2402 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2403 (
unsigned int) draw_info->rectangle_info.width,
2404 (
unsigned int) draw_info->rectangle_info.height);
2408 case EllipseElement:
2410 (void)
XDrawArc(display,draw_pixmap,draw_context,
2411 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2412 (
unsigned int) draw_info->rectangle_info.width,
2413 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2416 case FillCircleElement:
2417 case FillEllipseElement:
2419 (void)
XFillArc(display,draw_pixmap,draw_context,
2420 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2421 (
unsigned int) draw_info->rectangle_info.width,
2422 (
unsigned int) draw_info->rectangle_info.height,0,360*64);
2425 case PolygonElement:
2430 coordinate_info=draw_info->coordinate_info;
2431 (void)
XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2432 (
int) draw_info->number_coordinates,CoordModeOrigin);
2433 (void)
XDrawLine(display,draw_pixmap,draw_context,
2434 coordinate_info[draw_info->number_coordinates-1].x,
2435 coordinate_info[draw_info->number_coordinates-1].y,
2436 coordinate_info[0].x,coordinate_info[0].y);
2439 case FillPolygonElement:
2442 draw_info->coordinate_info,(
int) draw_info->number_coordinates,Complex,
2447 (void)
XFreeGC(display,draw_context);
2451 draw_ximage=
XGetImage(display,draw_pixmap,0,0,draw_info->width,
2452 draw_info->height,AllPlanes,ZPixmap);
2453 if (draw_ximage == (XImage *) NULL)
2460 if (draw_image == (
Image *) NULL)
2462 draw_image->
columns=draw_info->width;
2463 draw_image->
rows=draw_info->height;
2467 width=(
unsigned int) image->
columns;
2468 height=(
unsigned int) image->
rows;
2478 for (y=0; y < (int) draw_image->
rows; y++)
2490 for (x=0; x < (int) draw_image->
columns; x++)
2492 if (XGetPixel(draw_ximage,x,y) == 0)
2507 pixel->pen_color.red),q);
2509 pixel->pen_color.green),q);
2511 pixel->pen_color.blue),q);
2521 XDestroyImage(draw_ximage);
2526 if ((width != (
unsigned int) draw_image->
columns) ||
2527 (height != (
unsigned int) draw_image->
rows))
2540 if (draw_info->degrees != 0.0)
2554 rotate_image=
RotateImage(draw_image,draw_info->degrees,exception);
2555 if (rotate_image == (
Image *) NULL)
2558 draw_image=rotate_image;
2562 normalized_degrees=draw_info->degrees;
2563 while (normalized_degrees < -45.0)
2564 normalized_degrees+=360.0;
2565 for (rotations=0; normalized_degrees > 45.0; rotations++)
2566 normalized_degrees-=90.0;
2567 switch (rotations % 4)
2577 x=x-(int) draw_image->
columns/2;
2578 y=y+(
int) draw_image->
columns/2;
2586 x=x-(int) draw_image->
columns;
2594 x=x-(int) draw_image->
columns/2;
2595 y=y-(
int) (draw_image->
rows-(draw_image->
columns/2));
2604 for (y=0; y < (int) draw_image->
rows; y++)
2616 for (x=0; x < (int) draw_image->
columns; x++)
2627 if (draw_info->stencil == TransparentStencil)
2629 (ssize_t) x,(ssize_t) y,exception);
2634 (ssize_t) x,(ssize_t) y,exception);
2670 #if defined(__cplusplus) || defined(c_plusplus) 2674 MagickExport int XError(Display *display,XErrorEvent *error)
2676 assert(display != (Display *) NULL);
2677 assert(error != (XErrorEvent *) NULL);
2681 switch (error->request_code)
2685 if ((
int) error->error_code == BadDrawable)
2689 case X_GetWindowAttributes:
2692 if ((
int) error->error_code == BadWindow)
2698 if ((
int) error->error_code == BadValue)
2706 #if defined(__cplusplus) || defined(c_plusplus) 2750 MagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
2751 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2754 assert(display != (Display *) NULL);
2758 if (window_info != (XWindowInfo *) NULL)
2763 if (window_info->ximage != (XImage *) NULL)
2764 XDestroyImage(window_info->ximage);
2765 if (window_info->id != (Window) NULL)
2770 if (window_info->id !=
XRootWindow(display,visual_info->screen))
2772 if (window_info->annotate_context != (GC) NULL)
2773 (void)
XFreeGC(display,window_info->annotate_context);
2774 if (window_info->highlight_context != (GC) NULL)
2775 (
void)
XFreeGC(display,window_info->highlight_context);
2776 if (window_info->widget_context != (GC) NULL)
2777 (void)
XFreeGC(display,window_info->widget_context);
2778 if (window_info->cursor != (Cursor) NULL)
2780 window_info->cursor=(Cursor) NULL;
2781 if (window_info->busy_cursor != (Cursor) NULL)
2782 (
void)
XFreeCursor(display,window_info->busy_cursor);
2783 window_info->busy_cursor=(Cursor) NULL;
2789 if (font_info != (XFontStruct *) NULL)
2792 font_info=(XFontStruct *) NULL;
2794 if (map_info != (XStandardColormap *) NULL)
2800 (
void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2801 (void)
XFree((
void *) map_info);
2806 if (visual_info != (XVisualInfo *) NULL)
2807 (
void)
XFree((
void *) visual_info);
2846 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2851 assert(display != (Display *) NULL);
2852 assert(visual_info != (XVisualInfo *) NULL);
2853 assert(map_info != (XStandardColormap *) NULL);
2857 if (map_info->colormap != (
Colormap) NULL)
2862 if (pixel != (XPixelInfo *) NULL)
2863 if ((visual_info->klass != TrueColor) &&
2864 (visual_info->klass != DirectColor))
2865 (void)
XFreeColors(display,map_info->colormap,pixel->pixels,
2866 (
int) pixel->colors,0);
2868 map_info->colormap=(
Colormap) NULL;
2869 if (pixel != (XPixelInfo *) NULL)
2871 if (pixel->pixels != (
unsigned long *) NULL)
2873 pixel->pixels=(
unsigned long *) NULL;
2899 MagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2904 assert(annotate_info != (XAnnotateInfo *) NULL);
2909 annotate_info->width=0;
2910 annotate_info->height=0;
2911 annotate_info->stencil=ForegroundStencil;
2912 annotate_info->degrees=0.0;
2913 annotate_info->font_info=(XFontStruct *) NULL;
2914 annotate_info->text=(
char *) NULL;
2915 *annotate_info->geometry=
'\0';
2916 annotate_info->previous=(XAnnotateInfo *) NULL;
2917 annotate_info->next=(XAnnotateInfo *) NULL;
2950 MagickPrivate void XGetMapInfo(
const XVisualInfo *visual_info,
2951 const Colormap colormap,XStandardColormap *map_info)
2956 assert(visual_info != (XVisualInfo *) NULL);
2957 assert(map_info != (XStandardColormap *) NULL);
2960 map_info->colormap=colormap;
2961 map_info->red_max=visual_info->red_mask;
2962 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2963 if (map_info->red_max != 0)
2964 while ((map_info->red_max & 0x01) == 0)
2966 map_info->red_max>>=1;
2967 map_info->red_mult<<=1;
2969 map_info->green_max=visual_info->green_mask;
2970 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2971 if (map_info->green_max != 0)
2972 while ((map_info->green_max & 0x01) == 0)
2974 map_info->green_max>>=1;
2975 map_info->green_mult<<=1;
2977 map_info->blue_max=visual_info->blue_mask;
2978 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2979 if (map_info->blue_max != 0)
2980 while ((map_info->blue_max & 0x01) == 0)
2982 map_info->blue_max>>=1;
2983 map_info->blue_mult<<=1;
2985 map_info->base_pixel=0;
3027 const XVisualInfo *visual_info,
const XStandardColormap *map_info,
3031 *PenColors[MaxNumberPens]=
3061 assert(display != (Display *) NULL);
3062 assert(visual_info != (XVisualInfo *) NULL);
3063 assert(map_info != (XStandardColormap *) NULL);
3065 assert(pixel != (XPixelInfo *) NULL);
3069 if (image != (
Image *) NULL)
3071 pixel->colors=(ssize_t) image->
colors;
3072 packets=(
unsigned int)
3073 MagickMax((
int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3074 if (pixel->pixels != (
unsigned long *) NULL)
3077 sizeof(*pixel->pixels));
3078 if (pixel->pixels == (
unsigned long *) NULL)
3084 colormap=map_info->colormap;
3086 &pixel->foreground_color);
3088 &pixel->foreground_color);
3089 if (status == False)
3090 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3092 pixel->foreground_color.pixel=
3093 XStandardPixel(map_info,&pixel->foreground_color);
3094 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3098 (void)
XParseColor(display,colormap,
"#d6d6d6d6d6d6",&pixel->background_color);
3100 &pixel->background_color);
3101 if (status == False)
3102 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3104 pixel->background_color.pixel=
3105 XStandardPixel(map_info,&pixel->background_color);
3106 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3111 &pixel->border_color);
3113 &pixel->border_color);
3114 if (status == False)
3115 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3117 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3118 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3122 pixel->matte_color=pixel->background_color;
3129 &pixel->matte_color);
3130 if (status == False)
3131 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3133 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3134 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3139 pixel->highlight_color.red=(
unsigned short) (((
double)
3142 pixel->highlight_color.green=(
unsigned short) (((
double)
3145 pixel->highlight_color.blue=(
unsigned short) (((
double)
3148 pixel->highlight_color.pixel=XStandardPixel(map_info,&pixel->highlight_color);
3149 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3153 pixel->shadow_color.red=(
unsigned short) (((
double)
3154 pixel->matte_color.red*ScaleQuantumToShort(
ShadowModulate))/65535L);
3155 pixel->shadow_color.green=(
unsigned short) (((
double)
3156 pixel->matte_color.green*ScaleQuantumToShort(
ShadowModulate))/65535L);
3157 pixel->shadow_color.blue=(
unsigned short) (((
double)
3158 pixel->matte_color.blue*ScaleQuantumToShort(
ShadowModulate))/65535L);
3159 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3160 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3164 pixel->depth_color.red=(
unsigned short) (((
double)
3165 pixel->matte_color.red*ScaleQuantumToShort(
DepthModulate))/65535L);
3166 pixel->depth_color.green=(
unsigned short) (((
double)
3167 pixel->matte_color.green*ScaleQuantumToShort(
DepthModulate))/65535L);
3168 pixel->depth_color.blue=(
unsigned short) (((
double)
3169 pixel->matte_color.blue*ScaleQuantumToShort(
DepthModulate))/65535L);
3170 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3171 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3175 pixel->trough_color.red=(
unsigned short) (((
double)
3176 pixel->matte_color.red*ScaleQuantumToShort(
TroughModulate))/65535L);
3177 pixel->trough_color.green=(
unsigned short) (((
double)
3178 pixel->matte_color.green*ScaleQuantumToShort(
TroughModulate))/65535L);
3179 pixel->trough_color.blue=(
unsigned short) (((
double)
3180 pixel->matte_color.blue*ScaleQuantumToShort(
TroughModulate))/65535L);
3181 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3182 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3186 for (i=0; i < MaxNumberPens; i++)
3188 (void)
XParseColor(display,colormap,(
char *) PenColors[i],
3189 &pixel->pen_colors[i]);
3191 &pixel->pen_colors[i]);
3192 if (status == False)
3193 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3195 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3196 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3198 pixel->box_color=pixel->background_color;
3199 pixel->pen_color=pixel->foreground_color;
3202 if (image != (
Image *) NULL)
3205 (image->
gamma != 0.0))
3218 red_gamma=geometry_info.
rho;
3219 green_gamma=red_gamma;
3221 green_gamma=geometry_info.
sigma;
3222 blue_gamma=red_gamma;
3224 blue_gamma=geometry_info.
xi;
3225 red_gamma*=image->
gamma;
3226 green_gamma*=image->
gamma;
3227 blue_gamma*=image->
gamma;
3234 for (i=0; i < (ssize_t) image->
colors; i++)
3235 pixel->pixels[i]=XGammaPacket(map_info,image->
colormap+i);
3236 for (i=0; i < MaxNumberPens; i++)
3237 pixel->pixels[image->
colors+i]=pixel->pen_colors[i].pixel;
3238 pixel->colors+=MaxNumberPens;
3277 MagickExport char *XGetResourceClass(XrmDatabase database,
3278 const char *client_name,
const char *keyword,
char *resource_default)
3293 if (database == (XrmDatabase) NULL)
3294 return(resource_default);
3295 *resource_name=
'\0';
3296 *resource_class=
'\0';
3297 if (keyword != (
char *) NULL)
3307 client_name,keyword);
3308 c=(int) (*client_name);
3309 if ((c >= XK_a) && (c <= XK_z))
3312 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3313 c-=(XK_agrave-XK_Agrave);
3315 if ((c >= XK_oslash) && (c <= XK_thorn))
3316 c-=(XK_oslash-XK_Ooblique);
3318 if ((k >= XK_a) && (k <= XK_z))
3321 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3322 k-=(XK_agrave-XK_Agrave);
3324 if ((k >= XK_oslash) && (k <= XK_thorn))
3325 k-=(XK_oslash-XK_Ooblique);
3327 client_name+1,k,keyword+1);
3329 status=
XrmGetResource(database,resource_name,resource_class,&resource_type,
3331 if (status == False)
3332 return(resource_default);
3333 return(resource_value.addr);
3366 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3367 const char *client_name)
3382 if (display == (Display *) NULL)
3383 return((XrmDatabase) NULL);
3384 assert(client_name != (
char *) NULL);
3389 (void)
XGetDefault(display,(
char *) client_name,
"dummy");
3394 p=client_name+(strlen(client_name)-1);
3395 while ((p > client_name) && (*p !=
'/'))
3399 c=(int) (*client_name);
3400 if ((c >= XK_a) && (c <= XK_z))
3403 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3404 c-=(XK_agrave-XK_Agrave);
3406 if ((c >= XK_oslash) && (c <= XK_thorn))
3407 c-=(XK_oslash-XK_Ooblique);
3408 #if defined(X11_APPLICATION_PATH) 3410 X11_APPLICATION_PATH,c,client_name+1);
3424 #if defined(X11_PREFERENCES_PATH) 3430 return(resource_database);
3465 XrmDatabase database,
const char *client_name,XResourceInfo *
resource_info)
3481 XMagickProgressMonitor,(
void *) NULL);
3485 resource_value=XGetResourceClass(database,client_name,
"backdrop",
3488 resource_info->background_color=XGetResourceInstance(database,client_name,
3489 "background",(
char *)
"#d6d6d6d6d6d6");
3490 resource_info->border_color=XGetResourceInstance(database,client_name,
3492 resource_value=XGetResourceClass(database,client_name,
"borderWidth",
3496 resource_value=XGetResourceClass(database,client_name,
"colormap",
3504 ThrowXWindowException(
OptionError,
"UnrecognizedColormapType",
3506 resource_value=XGetResourceClass(database,client_name,
3507 "colorRecovery",(
char *)
"False");
3509 resource_value=XGetResourceClass(database,client_name,
"confirmExit",
3512 resource_value=XGetResourceClass(database,client_name,
"confirmEdit",
3515 resource_value=XGetResourceClass(database,client_name,
"delay",(
char *)
"1");
3517 resource_info->display_gamma=XGetResourceClass(database,client_name,
3518 "displayGamma",(
char *)
"2.2");
3519 resource_value=XGetResourceClass(database,client_name,
"displayWarnings",
3522 resource_info->font=XGetResourceClass(database,client_name,
"font",
3524 resource_info->font=XGetResourceClass(database,client_name,
"fontList",
3526 resource_info->font_name[0]=XGetResourceClass(database,client_name,
"font1",
3528 resource_info->font_name[1]=XGetResourceClass(database,client_name,
"font2",
3529 (
char *)
"variable");
3530 resource_info->font_name[2]=XGetResourceClass(database,client_name,
"font3",
3532 resource_info->font_name[3]=XGetResourceClass(database,client_name,
"font4",
3534 resource_info->font_name[4]=XGetResourceClass(database,client_name,
"font5",
3535 (
char *)
"7x13bold");
3536 resource_info->font_name[5]=XGetResourceClass(database,client_name,
"font6",
3537 (
char *)
"8x13bold");
3538 resource_info->font_name[6]=XGetResourceClass(database,client_name,
"font7",
3539 (
char *)
"9x15bold");
3540 resource_info->font_name[7]=XGetResourceClass(database,client_name,
"font8",
3542 resource_info->font_name[8]=XGetResourceClass(database,client_name,
"font9",
3544 resource_info->font_name[9]=XGetResourceClass(database,client_name,
"font0",
3546 resource_info->font_name[10]=XGetResourceClass(database,client_name,
"font0",
3548 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3550 resource_value=XGetResourceClass(database,client_name,
"gammaCorrect",
3554 client_name,
"geometry",(
char *) NULL));
3555 resource_value=XGetResourceClass(database,client_name,
"gravity",
3561 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3562 "iconGeometry",(
char *) NULL);
3563 resource_value=XGetResourceClass(database,client_name,
"iconic",
3566 resource_value=XGetResourceClass(database,client_name,
"immutable",
3567 LocaleCompare(client_name,
"PerlMagick") == 0 ? (
char *)
"True" :
3570 resource_value=XGetResourceClass(database,client_name,
"magnify",
3573 resource_info->map_type=XGetResourceClass(database,client_name,
"map",
3575 resource_info->matte_color=XGetResourceInstance(database,client_name,
3576 "mattecolor",(
char *) NULL);
3578 "name",(
char *) NULL));
3579 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,
"pen1",
3581 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,
"pen2",
3583 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,
"pen3",
3585 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,
"pen4",
3587 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,
"pen5",
3589 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,
"pen6",
3591 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,
"pen7",
3592 (
char *)
"magenta");
3593 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,
"pen8",
3595 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,
"pen9",
3597 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,
"pen0",
3599 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,
"pen0",
3601 resource_value=XGetResourceClass(database,client_name,
"pause",(
char *)
"0");
3603 resource_value=XGetResourceClass(database,client_name,
"quantum",(
char *)
"1");
3605 resource_info->text_font=XGetResourceClass(database,client_name,(
char *)
3606 "font",(
char *)
"fixed");
3607 resource_info->text_font=XGetResourceClass(database,client_name,
3609 resource_info->title=XGetResourceClass(database,client_name,
"title",
3611 resource_value=XGetResourceClass(database,client_name,
"undoCache",
3614 resource_value=XGetResourceClass(database,client_name,
"update",
3617 resource_value=XGetResourceClass(database,client_name,
"usePixmap",
3620 resource_value=XGetResourceClass(database,client_name,
"sharedMemory",
3623 resource_info->visual_type=XGetResourceClass(database,client_name,
"visual",
3625 resource_info->window_group=XGetResourceClass(database,client_name,
3626 "windowGroup",(
char *) NULL);
3627 resource_info->window_id=XGetResourceClass(database,client_name,
"window",
3629 resource_info->write_filename=XGetResourceClass(database,client_name,
3630 "writeFilename",(
char *) NULL);
3669 MagickExport char *XGetResourceInstance(XrmDatabase database,
3670 const char *client_name,
const char *keyword,
const char *resource_default)
3682 if (database == (XrmDatabase) NULL)
3683 return((
char *) resource_default);
3684 *resource_name=
'\0';
3685 if (keyword != (
char *) NULL)
3688 status=
XrmGetResource(database,resource_name,
"ImageMagick",&resource_type,
3690 if (status == False)
3691 return((
char *) resource_default);
3692 return(resource_value.addr);
3734 x_density=((((double) DisplayWidth(display,
XDefaultScreen(display)))*25.4)/
3736 y_density=((((double) DisplayHeight(display,
XDefaultScreen(display)))*25.4)/
3778 static Window XGetSubwindow(Display *display,Window window,
int x,
int y)
3791 assert(display != (Display *) NULL);
3793 if (window == (Window) NULL)
3794 return(source_window);
3795 target_window=window;
3799 &x_offset,&y_offset,&target_window);
3802 if (target_window == (Window) NULL)
3804 source_window=window;
3805 window=target_window;
3809 if (target_window == (Window) NULL)
3810 target_window=window;
3811 return(target_window);
3880 assert(display != (Display *) NULL);
3881 assert(name != (
char *) NULL);
3885 target_window=XSelectWindow(display,&crop_info);
3886 if (target_window == (Window) NULL)
3889 client_window=target_window;
3890 if (target_window != root_window)
3898 status=
XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3899 if (status != False)
3901 client_window=XClientWindow(display,target_window);
3902 target_window=client_window;
3909 if ((status == False) || (window_attributes.map_state != IsViewable))
3915 (
int) crop_info.
x,(int) crop_info.
y,&x,&y,&child);
3916 ximage=
XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3917 if (ximage == (XImage *) NULL)
3919 color.pixel=XGetPixel(ximage,0,0);
3920 XDestroyImage(ximage);
3924 (void)
XQueryColor(display,window_attributes.colormap,&color);
3925 pixel.
red=(double) ScaleShortToQuantum(color.red);
3926 pixel.
green=(double) ScaleShortToQuantum(color.green);
3927 pixel.
blue=(double) ScaleShortToQuantum(color.blue);
3976 static Image *XGetWindowImage(Display *display,
const Window window,
3977 const unsigned int borders,
const unsigned int level,
ExceptionInfo *exception)
3991 typedef struct _WindowInfo
4049 assert(display != (Display *) NULL);
4053 if ((status == False) || (window_attributes.map_state != IsViewable))
4054 return((
Image *) NULL);
4061 crop_info.
x=(ssize_t) x_offset;
4062 crop_info.
y=(ssize_t) y_offset;
4063 crop_info.
width=(size_t) window_attributes.width;
4064 crop_info.
height=(
size_t) window_attributes.height;
4070 crop_info.
x-=(ssize_t) window_attributes.border_width;
4071 crop_info.
y-=(ssize_t) window_attributes.border_width;
4072 crop_info.
width+=(size_t) (window_attributes.border_width << 1);
4073 crop_info.
height+=(size_t) (window_attributes.border_width << 1);
4078 if (crop_info.
x < 0)
4080 crop_info.
width+=crop_info.
x;
4083 if (crop_info.
y < 0)
4085 crop_info.
height+=crop_info.
y;
4089 if ((
int) (crop_info.
x+crop_info.
width) > display_width)
4090 crop_info.
width=(size_t) (display_width-crop_info.
x);
4092 if ((
int) (crop_info.
y+crop_info.
height) > display_height)
4093 crop_info.
height=(size_t) (display_height-crop_info.
y);
4097 if (number_windows >= max_windows)
4103 if (window_info == (WindowInfo *) NULL)
4105 sizeof(*window_info));
4108 max_windows,
sizeof(*window_info));
4110 if (window_info == (WindowInfo *) NULL)
4113 return((
Image *) NULL);
4115 id=number_windows++;
4116 window_info[id].window=window;
4117 window_info[id].visual=window_attributes.visual;
4118 window_info[id].colormap=window_attributes.colormap;
4119 window_info[id].bounds.x1=(short) crop_info.
x;
4120 window_info[
id].bounds.y1=(
short) crop_info.
y;
4121 window_info[id].bounds.x2=(short) (crop_info.
x+(
int) crop_info.
width-1);
4122 window_info[id].bounds.y2=(short) (crop_info.
y+(
int) crop_info.
height-1);
4123 crop_info.
x-=x_offset;
4124 crop_info.
y-=y_offset;
4125 window_info[id].crop_info=crop_info;
4137 status=
XQueryTree(display,window,&root_window,&window_info[
id].parent,
4138 &children,&number_children);
4139 for (i=0; i < id; i++)
4140 if ((window_info[i].window == window_info[
id].parent) &&
4141 (window_info[i].visual == window_info[
id].visual) &&
4142 (window_info[i].colormap == window_info[
id].colormap))
4144 if ((window_info[
id].bounds.x1 < window_info[i].bounds.x1) ||
4145 (window_info[
id].bounds.x2 > window_info[i].bounds.x2) ||
4146 (window_info[
id].bounds.y1 < window_info[i].bounds.y1) ||
4147 (window_info[
id].bounds.y2 > window_info[i].bounds.y2))
4156 if ((status == True) && (number_children != 0))
4158 for (i=0; i < (int) number_children; i++)
4159 (
void) XGetWindowImage(display,children[i],
MagickFalse,level+1,
4161 (void)
XFree((
void *) children);
4205 for (
id=0;
id < number_windows;
id++)
4210 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4211 (window_info[
id].bounds.x1 <= window_info[0].bounds.x2) &&
4212 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4213 (window_info[
id].bounds.y1 <= window_info[0].bounds.y2)) ?
4218 for (j=0; j < id; j++)
4219 if ((window_info[
id].visual == window_info[j].visual) &&
4220 (window_info[id].colormap == window_info[j].colormap))
4222 if ((window_info[
id].bounds.x1 >= window_info[j].bounds.x1) &&
4223 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4224 (window_info[
id].bounds.y1 >= window_info[j].bounds.y1) &&
4225 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4233 ximage=
XGetImage(display,window_info[
id].window,(
int)
4234 window_info[
id].crop_info.
x,(
int) window_info[
id].crop_info.y,
4235 (
unsigned int) window_info[
id].crop_info.width,(
unsigned int)
4236 window_info[
id].crop_info.height,AllPlanes,ZPixmap);
4237 if (ximage == (XImage *) NULL)
4243 colors=(XColor *) NULL;
4244 if (window_info[
id].colormap != (
Colormap) NULL)
4252 number_colors=(
unsigned int) window_info[
id].visual->map_entries;
4253 for (p=colormap_info; p != (
ColormapInfo *) NULL; p=p->next)
4254 if (p->colormap == window_info[
id].colormap)
4263 if (colors == (XColor *) NULL)
4265 XDestroyImage(ximage);
4266 return((
Image *) NULL);
4268 if ((window_info[
id].visual->klass != DirectColor) &&
4269 (window_info[
id].visual->klass != TrueColor))
4270 for (i=0; i < (int) number_colors; i++)
4272 colors[i].pixel=(size_t) i;
4291 red_bit=window_info[id].visual->red_mask &
4292 (~(window_info[id].visual->red_mask)+1);
4293 green_bit=window_info[id].visual->green_mask &
4294 (~(window_info[id].visual->green_mask)+1);
4295 blue_bit=window_info[id].visual->blue_mask &
4296 (~(window_info[id].visual->blue_mask)+1);
4297 for (i=0; i < (int) number_colors; i++)
4299 colors[i].pixel=(
unsigned long) (red | green | blue);
4302 if (red > window_info[
id].visual->red_mask)
4305 if (green > window_info[
id].visual->green_mask)
4308 if (blue > window_info[
id].visual->blue_mask)
4312 (void)
XQueryColors(display,window_info[
id].colormap,colors,
4313 (
int) number_colors);
4319 return((
Image *) NULL);
4320 p->colormap=window_info[id].colormap;
4322 p->next=colormap_info;
4331 if (composite_image == (
Image *) NULL)
4333 XDestroyImage(ximage);
4334 return((
Image *) NULL);
4339 if ((window_info[
id].visual->klass != TrueColor) &&
4340 (window_info[
id].visual->klass != DirectColor))
4342 composite_image->
columns=(size_t) ximage->width;
4343 composite_image->
rows=(
size_t) ximage->height;
4365 red_mask=window_info[id].visual->red_mask;
4367 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4372 green_mask=window_info[id].visual->green_mask;
4374 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4379 blue_mask=window_info[id].visual->blue_mask;
4381 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4389 if ((number_colors != 0) &&
4390 (window_info[
id].visual->klass == DirectColor))
4391 for (y=0; y < (int) composite_image->
rows; y++)
4394 composite_image->
columns,1,exception);
4397 for (x=0; x < (int) composite_image->
columns; x++)
4399 pixel=XGetPixel(ximage,x,y);
4400 index=(pixel >> red_shift) & red_mask;
4402 ScaleShortToQuantum(colors[index].red),q);
4403 index=(pixel >> green_shift) & green_mask;
4405 ScaleShortToQuantum(colors[index].green),q);
4406 index=(pixel >> blue_shift) & blue_mask;
4408 ScaleShortToQuantum(colors[index].blue),q);
4416 for (y=0; y < (int) composite_image->
rows; y++)
4419 composite_image->
columns,1,exception);
4422 for (x=0; x < (int) composite_image->
columns; x++)
4424 pixel=XGetPixel(ximage,x,y);
4425 color=(pixel >> red_shift) & red_mask;
4427 color=(65535UL*color)/red_mask;
4429 (
unsigned short) color),q);
4430 color=(pixel >> green_shift) & green_mask;
4431 if (green_mask != 0)
4432 color=(65535UL*color)/green_mask;
4434 (
unsigned short) color),q);
4435 color=(pixel >> blue_shift) & blue_mask;
4437 color=(65535UL*color)/blue_mask;
4439 (
unsigned short) color),q);
4457 XDestroyImage(ximage);
4459 return((
Image *) NULL);
4461 for (i=0; i < (int) composite_image->
colors; i++)
4463 composite_image->
colormap[colors[i].pixel].
red=(double)
4464 ScaleShortToQuantum(colors[i].red);
4466 ScaleShortToQuantum(colors[i].green);
4467 composite_image->
colormap[colors[i].pixel].
blue=(double)
4468 ScaleShortToQuantum(colors[i].blue);
4473 for (y=0; y < (int) composite_image->
rows; y++)
4476 composite_image->
columns,1,exception);
4479 for (x=0; x < (int) composite_image->
columns; x++)
4481 index=(
Quantum) XGetPixel(ximage,x,y);
4484 composite_image->
colormap+(ssize_t) index,q);
4495 XDestroyImage(ximage);
4496 if (image == (
Image *) NULL)
4498 image=composite_image;
4505 &x_offset,&y_offset,&child);
4506 x_offset-=(int) crop_info.
x;
4509 y_offset-=(int) crop_info.
y;
4513 (ssize_t) x_offset,(ssize_t) y_offset,exception);
4521 next=colormap_info->next;
4523 colormap_info->colors);
4536 return((
Image *) NULL);
4577 MagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4578 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4584 assert(display != (Display *) NULL);
4585 assert(visual_info != (XVisualInfo *) NULL);
4586 assert(map_info != (XStandardColormap *) NULL);
4587 assert(pixel != (XPixelInfo *) NULL);
4589 assert(window != (XWindowInfo *) NULL);
4592 if (window->id != (Window) NULL)
4594 if (window->cursor != (Cursor) NULL)
4596 if (window->busy_cursor != (Cursor) NULL)
4598 if (window->highlight_stipple != (Pixmap) NULL)
4599 (
void)
XFreePixmap(display,window->highlight_stipple);
4600 if (window->shadow_stipple != (Pixmap) NULL)
4601 (void)
XFreePixmap(display,window->shadow_stipple);
4602 if (window->name == (
char *) NULL)
4604 if (window->icon_name == (
char *) NULL)
4612 window->id=(Window) NULL;
4613 if (window->name == (
char *) NULL)
4615 if (window->icon_name == (
char *) NULL)
4619 window->ximage=(XImage *) NULL;
4620 window->matte_image=(XImage *) NULL;
4621 window->pixmap=(Pixmap) NULL;
4622 window->matte_pixmap=(Pixmap) NULL;
4626 window->segment_info=(
void *) NULL;
4627 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 4632 if (window->segment_info == (
void *) NULL)
4634 segment_info=(XShmSegmentInfo *) window->segment_info;
4635 segment_info[0].shmid=(-1);
4636 segment_info[0].shmaddr=(
char *) NULL;
4637 segment_info[1].shmid=(-1);
4638 segment_info[1].shmaddr=(
char *) NULL;
4645 window->screen=visual_info->screen;
4646 window->root=
XRootWindow(display,visual_info->screen);
4647 window->visual=visual_info->visual;
4648 window->storage_class=(
unsigned int) visual_info->klass;
4649 window->depth=(
unsigned int) visual_info->depth;
4650 window->visual_info=visual_info;
4651 window->map_info=map_info;
4652 window->pixel_info=pixel;
4653 window->font_info=font_info;
4656 window->geometry=(
char *) NULL;
4657 window->icon_geometry=(
char *) NULL;
4660 window->crop_geometry=(
char *) NULL;
4661 window->flags=(size_t) PSize;
4664 window->min_width=1;
4665 window->min_height=1;
4666 window->width_inc=1;
4667 window->height_inc=1;
4669 window->annotate_context=pixel->annotate_context;
4670 window->highlight_context=pixel->highlight_context;
4671 window->widget_context=pixel->widget_context;
4672 window->shadow_stipple=(Pixmap) NULL;
4673 window->highlight_stipple=(Pixmap) NULL;
4678 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4679 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4680 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4681 window->attributes.background_pixel=pixel->background_color.pixel;
4682 window->attributes.background_pixmap=(Pixmap) NULL;
4684 window->attributes.backing_store=WhenMapped;
4686 window->attributes.border_pixel=pixel->border_color.pixel;
4687 window->attributes.colormap=map_info->colormap;
4688 window->attributes.cursor=window->cursor;
4689 window->attributes.do_not_propagate_mask=NoEventMask;
4690 window->attributes.event_mask=NoEventMask;
4728 MagickPrivate void XHighlightEllipse(Display *display,Window window,
4731 assert(display != (Display *) NULL);
4732 assert(window != (Window) NULL);
4733 assert(annotate_context != (GC) NULL);
4737 if ((highlight_info->
width < 4) || (highlight_info->
height < 4))
4739 (void)
XDrawArc(display,window,annotate_context,(
int) highlight_info->
x,
4740 (int) highlight_info->
y,(
unsigned int) highlight_info->
width-1,
4741 (
unsigned int) highlight_info->
height-1,0,360*64);
4742 (void)
XDrawArc(display,window,annotate_context,(
int) highlight_info->
x+1,
4743 (int) highlight_info->
y+1,(
unsigned int) highlight_info->
width-3,
4744 (
unsigned int) highlight_info->
height-3,0,360*64);
4779 MagickPrivate void XHighlightLine(Display *display,Window window,
4780 GC annotate_context,
const XSegment *highlight_info)
4782 assert(display != (Display *) NULL);
4783 assert(window != (Window) NULL);
4784 assert(annotate_context != (GC) NULL);
4785 assert(highlight_info != (XSegment *) NULL);
4788 (void)
XDrawLine(display,window,annotate_context,highlight_info->x1,
4789 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4824 MagickPrivate void XHighlightRectangle(Display *display,Window window,
4827 assert(display != (Display *) NULL);
4828 assert(window != (Window) NULL);
4829 assert(annotate_context != (GC) NULL);
4833 if ((highlight_info->
width < 4) || (highlight_info->
height < 4))
4835 (void)
XDrawRectangle(display,window,annotate_context,(
int) highlight_info->
x,
4836 (int) highlight_info->
y,(
unsigned int) highlight_info->
width-1,
4837 (
unsigned int) highlight_info->
height-1);
4838 (void)
XDrawRectangle(display,window,annotate_context,(
int) highlight_info->
x+
4839 1,(int) highlight_info->
y+1,(
unsigned int) highlight_info->
width-3,
4840 (
unsigned int) highlight_info->
height-3);
4906 assert(image_info != (
const ImageInfo *) NULL);
4913 if (display == (Display *) NULL)
4915 ThrowXWindowException(
XServerError,
"UnableToOpenXServer",
4917 return((
Image *) NULL);
4931 target=(Window) NULL;
4941 if (isdigit((
int) ((
unsigned char) *image_info->
filename)) != 0)
4942 target=XWindowByID(display,root,(Window)
4943 strtol(image_info->
filename,(
char **) NULL,0));
4944 if (target == (Window) NULL)
4945 target=XWindowByName(display,root,image_info->
filename);
4946 if (target == (Window) NULL)
4947 ThrowXWindowException(
XServerError,
"NoWindowWithSpecifiedIDExists",
4954 prior_target=target;
4955 if (target == (Window) NULL)
4956 target=XSelectWindow(display,&crop_info);
4957 if (target == (Window) NULL)
4958 ThrowXWindowException(
XServerError,
"UnableToReadXWindowImage",
4966 status=
XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4967 if (status != False)
4977 status=
XQueryTree(display,target,&root,&parent,&children,&d);
4978 if ((status != False) && (children != (Window *) NULL))
4979 (void)
XFree((
char *) children);
4980 if ((status == False) || (parent == (Window) NULL) ||
4988 client=XClientWindow(display,target);
4993 target=prior_target;
5011 if (status == False)
5013 ThrowXWindowException(
XServerError,
"UnableToReadXWindowAttributes",
5016 return((
Image *) NULL);
5019 crop_info.
x=(ssize_t) x;
5020 crop_info.
y=(ssize_t) y;
5021 crop_info.
width=(size_t) window_attributes.width;
5022 crop_info.
height=(
size_t) window_attributes.height;
5023 if (ximage_info->
borders != 0)
5028 crop_info.
x-=window_attributes.border_width;
5029 crop_info.
y-=window_attributes.border_width;
5030 crop_info.
width+=window_attributes.border_width << 1;
5031 crop_info.
height+=window_attributes.border_width << 1;
5040 if ((status == True) && (number_windows > 0))
5043 (void)
XFree ((
char *) children);
5046 if (number_colormaps > 0)
5048 if (number_colormaps > 1)
5050 (void)
XFree((
char *) colormaps);
5056 (void)
XBell(display,0);
5061 image=XGetWindowImage(display,target,ximage_info->
borders,
5062 ximage_info->
descend ? 1U : 0U,exception);
5064 if (image == (
Image *) NULL)
5065 ThrowXWindowException(
XServerError,
"UnableToReadXWindowImage",
5071 if ((crop_info.
width != 0) && (crop_info.
height != 0))
5079 crop_image=
CropImage(image,&crop_info,exception);
5080 if (crop_image != (
Image *) NULL)
5086 status=
XGetWMName(display,target,&window_name);
5091 (size_t) window_name.nitems+1);
5092 (void)
XFree((
void *) window_name.value);
5100 (void)
XBell(display,0);
5101 (void)
XBell(display,0);
5135 MagickPrivate XWindows *XInitializeWindows(Display *display,
5148 if (windows == (XWindows *) NULL)
5152 return((XWindows *) NULL);
5154 (void) memset(windows,0,
sizeof(*windows));
5156 sizeof(*windows->pixel_info));
5158 sizeof(*windows->icon_pixel));
5160 sizeof(*windows->icon_resources));
5161 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5162 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5163 (windows->icon_resources == (XResourceInfo *) NULL))
5167 return((XWindows *) NULL);
5172 windows->display=display;
5177 windows->im_remote_command=
5180 windows->im_update_colormap=
5187 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 5197 " Window Manager: 0x%lx",windows->wm_protocols);
5199 " delete window: 0x%lx",windows->wm_delete_window);
5201 windows->wm_take_focus);
5203 windows->im_protocols);
5205 " remote command: 0x%lx",windows->im_remote_command);
5207 " update widget: 0x%lx",windows->im_update_widget);
5209 " update colormap: 0x%lx",windows->im_update_colormap);
5211 " former image: 0x%lx",windows->im_former_image);
5213 windows->im_next_image);
5215 " retain colors: 0x%lx",windows->im_retain_colors);
5219 windows->dnd_protocols);
5226 if ((windows->map_info == (XStandardColormap *) NULL) ||
5227 (windows->icon_map == (XStandardColormap *) NULL))
5230 windows->map_info->colormap=(
Colormap) NULL;
5231 windows->icon_map->colormap=(
Colormap) NULL;
5232 windows->pixel_info->pixels=(
unsigned long *) NULL;
5233 windows->pixel_info->annotate_context=(GC) NULL;
5234 windows->pixel_info->highlight_context=(GC) NULL;
5235 windows->pixel_info->widget_context=(GC) NULL;
5236 windows->font_info=(XFontStruct *) NULL;
5237 windows->icon_pixel->annotate_context=(GC) NULL;
5238 windows->icon_pixel->pixels=(
unsigned long *) NULL;
5242 *windows->icon_resources=(*resource_info);
5243 windows->icon_resources->visual_type=(
char *)
"default";
5244 windows->icon_resources->colormap=SharedColormap;
5245 windows->visual_info=
5247 windows->icon_visual=
5248 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5249 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5250 (windows->icon_visual == (XVisualInfo *) NULL))
5257 windows->visual_info->visualid);
5259 XVisualClassName(windows->visual_info->klass));
5261 windows->visual_info->depth);
5263 " size of colormap: %d entries",windows->visual_info->colormap_size);
5265 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5266 windows->visual_info->red_mask,windows->visual_info->green_mask,
5267 windows->visual_info->blue_mask);
5269 " significant bits in color: %d bits",
5270 windows->visual_info->bits_per_rgb);
5277 if ((windows->class_hints == (XClassHint *) NULL) ||
5278 (windows->manager_hints == (XWMHints *) NULL))
5284 root_window=
XRootWindow(display,windows->visual_info->screen);
5285 windows->group_leader.id=(Window) NULL;
5288 if (isdigit((
int) ((
unsigned char) *
resource_info->window_group)) != 0)
5289 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5290 strtol((
char *)
resource_info->window_group,(
char **) NULL,0));
5291 if (windows->group_leader.id == (Window) NULL)
5292 windows->group_leader.id=
5293 XWindowByName(display,root_window,
resource_info->window_group);
5332 MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5333 Colormap colormap,
char *background_color,
char *foreground_color)
5335 #define scope_height 17 5336 #define scope_x_hot 8 5337 #define scope_y_hot 8 5338 #define scope_width 17 5340 static const unsigned char 5343 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5344 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5345 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5346 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5347 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5351 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5352 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5353 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5354 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5355 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5369 assert(display != (Display *) NULL);
5370 assert(window != (Window) NULL);
5371 assert(colormap != (
Colormap) NULL);
5372 assert(background_color != (
char *) NULL);
5373 assert(foreground_color != (
char *) NULL);
5379 scope_width,scope_height);
5380 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5382 ThrowXWindowException(
XServerError,
"UnableToCreatePixmap",
"...");
5383 return((Cursor) NULL);
5385 (void)
XParseColor(display,colormap,background_color,&background);
5386 (void)
XParseColor(display,colormap,foreground_color,&foreground);
5388 scope_x_hot,scope_y_hot);
5436 unsigned int width,
unsigned int height,
ExceptionInfo *exception)
5438 #define CheckOverflowException(length,width,height) \ 5439 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width))) 5452 assert(display != (Display *) NULL);
5454 assert(window != (XWindowInfo *) NULL);
5456 assert(height != 0);
5459 if ((window->width == 0) || (window->height == 0))
5465 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5467 depth=(int) window->depth;
5468 if (window->destroy)
5470 window->image=image;
5472 if (window->image != (
Image *) NULL)
5474 if (window->crop_geometry != (
char *) NULL)
5485 window->image->page.
x=0;
5486 window->image->page.y=0;
5488 &crop_info,exception);
5489 crop_image=
CropImage(window->image,&crop_info,exception);
5490 if (crop_image != (
Image *) NULL)
5492 if (window->image != image)
5494 window->image=crop_image;
5498 if ((width != (
unsigned int) window->image->columns) ||
5499 (height != (
unsigned int) window->image->rows))
5508 if ((window->pixel_info->colors == 0) &&
5509 (window->image->rows > (
unsigned long)
XDisplayHeight(display,window->screen)) &&
5510 (window->image->columns > (
unsigned long)
XDisplayWidth(display,window->screen)))
5511 resize_image=
ResizeImage(window->image,width,height,
5512 image->
filter,exception);
5516 resize_image=
SampleImage(window->image,width,height,
5522 if (resize_image != (
Image *) NULL)
5524 if (window->image != image)
5526 window->image=resize_image;
5530 width=(
unsigned int) window->image->columns;
5531 assert((
size_t) width == window->image->columns);
5532 height=(
unsigned int) window->image->rows;
5533 assert((
size_t) height == window->image->rows);
5538 ximage=(XImage *) NULL;
5539 format=(depth == 1) ? XYBitmap : ZPixmap;
5540 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 5546 segment_info=(XShmSegmentInfo *) window->segment_info;
5547 segment_info[1].shmid=(-1);
5548 segment_info[1].shmaddr=(
char *) NULL;
5549 ximage=XShmCreateImage(display,window->visual,(
unsigned int) depth,format,
5550 (
char *) NULL,&segment_info[1],width,height);
5552 if (ximage == (XImage *) NULL)
5556 length=(size_t) ximage->bytes_per_line*ximage->height;
5557 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5561 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5563 segment_info[1].shmaddr=(
char *) shmat(segment_info[1].shmid,0,0);
5564 if (segment_info[1].shmid < 0)
5567 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5570 if (ximage != (XImage *) NULL)
5571 XDestroyImage(ximage);
5572 ximage=(XImage *) NULL;
5573 if (segment_info[1].shmaddr)
5575 (void) shmdt(segment_info[1].shmaddr);
5576 segment_info[1].shmaddr=(
char *) NULL;
5578 if (segment_info[1].shmid >= 0)
5580 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5581 segment_info[1].shmid=(-1);
5589 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 5590 if (window->shared_memory)
5600 segment_info=(XShmSegmentInfo *) window->segment_info;
5601 ximage->data=segment_info[1].shmaddr;
5603 status=XShmAttach(display,&segment_info[1]);
5604 if (status != False)
5606 if ((status == False) || (xerror_alert !=
MagickFalse))
5609 if (status != False)
5610 XShmDetach(display,&segment_info[1]);
5612 XDestroyImage(ximage);
5613 ximage=(XImage *) NULL;
5614 if (segment_info[1].shmid >= 0)
5616 if (segment_info[1].shmaddr != NULL)
5617 (void) shmdt(segment_info[1].shmaddr);
5618 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5619 segment_info[1].shmid=(-1);
5620 segment_info[1].shmaddr=(
char *) NULL;
5626 ximage=
XCreateImage(display,window->visual,(
unsigned int) depth,format,0,
5627 (
char *) NULL,width,height,
XBitmapPad(display),0);
5628 if (ximage == (XImage *) NULL)
5633 (void) XCheckDefineCursor(display,window->id,window->cursor);
5636 length=(size_t) ximage->bytes_per_line*ximage->height;
5641 ximage->width,ximage->height);
5645 ximage->byte_order);
5647 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5648 ximage->bitmap_bit_order,ximage->bitmap_pad);
5652 ximage->bytes_per_line);
5654 ximage->bits_per_pixel);
5656 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5657 ximage->green_mask,ximage->blue_mask);
5661 if (ximage->format == XYBitmap)
5664 ximage->bytes_per_line,(size_t) ximage->depth*ximage->height);
5665 if (ximage->data != (
char *) NULL)
5666 (
void) memset(ximage->data,0,(
size_t)
5667 ximage->bytes_per_line*ximage->depth*ximage->height);
5672 ximage->bytes_per_line,(size_t) ximage->height);
5673 if (ximage->data != (
char *) NULL)
5674 (
void) memset(ximage->data,0,(
size_t)
5675 ximage->bytes_per_line*ximage->height);
5678 if (ximage->data == (
char *) NULL)
5683 XDestroyImage(ximage);
5684 ximage=(XImage *) NULL;
5685 (void) XCheckDefineCursor(display,window->id,window->cursor);
5688 if (window->ximage != (XImage *) NULL)
5693 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5695 if (window->segment_info != (XShmSegmentInfo *) NULL)
5700 segment_info=(XShmSegmentInfo *) window->segment_info;
5701 if (segment_info[0].shmid >= 0)
5704 (void) XShmDetach(display,&segment_info[0]);
5706 if (segment_info[0].shmaddr != (
char *) NULL)
5707 (
void) shmdt(segment_info[0].shmaddr);
5708 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5709 segment_info[0].shmid=(-1);
5710 segment_info[0].shmaddr=(
char *) NULL;
5711 window->ximage->data=(
char *) NULL;
5715 if (window->ximage->data != (
char *) NULL)
5716 free(window->ximage->data);
5717 window->ximage->data=(
char *) NULL;
5718 XDestroyImage(window->ximage);
5719 window->ximage=(XImage *) NULL;
5721 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 5722 if (window->segment_info != (XShmSegmentInfo *) NULL)
5727 segment_info=(XShmSegmentInfo *) window->segment_info;
5728 segment_info[0]=segment_info[1];
5731 window->ximage=ximage;
5732 matte_image=(XImage *) NULL;
5741 matte_image=
XCreateImage(display,window->visual,1,XYBitmap,0,
5742 (
char *) NULL,width,height,
XBitmapPad(display),0);
5747 " width, height: %dx%d",matte_image->width,matte_image->height);
5749 if (matte_image != (XImage *) NULL)
5754 matte_image->data=(
char *) malloc((
size_t)
5755 matte_image->bytes_per_line*matte_image->depth*
5756 matte_image->height);
5757 if (matte_image->data == (
char *) NULL)
5759 XDestroyImage(matte_image);
5760 matte_image=(XImage *) NULL;
5764 if (window->matte_image != (XImage *) NULL)
5769 if (window->matte_image->data != (
char *) NULL)
5770 free(window->matte_image->data);
5771 window->matte_image->data=(
char *) NULL;
5772 XDestroyImage(window->matte_image);
5773 window->matte_image=(XImage *) NULL;
5775 window->matte_image=matte_image;
5776 if (window->matte_pixmap != (Pixmap) NULL)
5779 window->matte_pixmap=(Pixmap) NULL;
5780 #if defined(MAGICKCORE_HAVE_SHAPE) 5789 if (window->image != (
Image *) NULL)
5791 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5792 (ximage->bitmap_bit_order == LSBFirst)))
5793 XMakeImageLSBFirst(
resource_info,window,window->image,ximage,
5794 matte_image,exception);
5796 XMakeImageMSBFirst(
resource_info,window,window->image,ximage,
5797 matte_image,exception);
5799 if (window->matte_image != (XImage *) NULL)
5804 window->matte_pixmap=
XCreatePixmap(display,window->id,width,height,1);
5805 if (window->matte_pixmap != (Pixmap) NULL)
5816 context_values.background=0;
5817 context_values.foreground=1;
5818 graphics_context=
XCreateGC(display,window->matte_pixmap,
5819 (
size_t) (GCBackground | GCForeground),&context_values);
5820 (void)
XPutImage(display,window->matte_pixmap,graphics_context,
5821 window->matte_image,0,0,0,0,width,height);
5822 (void)
XFreeGC(display,graphics_context);
5823 #if defined(MAGICKCORE_HAVE_SHAPE) 5826 window->matte_pixmap,ShapeSet);
5834 (void) XCheckDefineCursor(display,window->id,window->cursor);
5877 static void XMakeImageLSBFirst(
const XResourceInfo *
resource_info,
5878 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
5914 assert(window != (XWindowInfo *) NULL);
5915 assert(image != (
Image *) NULL);
5935 resource_info->image_info->texture :
"pattern:checkerboard",
5940 pattern=
ReadImage(image_info,exception);
5942 if (pattern != (
Image *) NULL)
5945 if (canvas != (
Image *) NULL)
5951 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
5952 ximage->bits_per_pixel) >> 3));
5953 map_info=window->map_info;
5954 pixels=window->pixel_info->pixels;
5955 q=(
unsigned char *) ximage->data;
5958 if (ximage->format == XYBitmap)
5970 background=(
unsigned char)
5971 (XPixelIntensity(&window->pixel_info->foreground_color) <
5972 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5973 foreground=(
unsigned char)
5974 (XPixelIntensity(&window->pixel_info->background_color) <
5975 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5981 for (y=0; y < (int) canvas->
rows; y++)
5985 if (p == (
const Quantum *) NULL)
5989 for (x=0; x < (int) canvas->
columns; x++)
6011 if (window->pixel_info->colors != 0)
6012 switch (ximage->bits_per_pixel)
6022 for (y=0; y < (int) canvas->
rows; y++)
6026 if (p == (
const Quantum *) NULL)
6029 for (x=0; x < (int) canvas->
columns; x++)
6036 *q=(
unsigned char) pixel;
6042 *q|=(
unsigned char) (pixel << 2);
6048 *q|=(
unsigned char) (pixel << 4);
6054 *q|=(
unsigned char) (pixel << 6);
6074 for (y=0; y < (int) canvas->
rows; y++)
6078 if (p == (
const Quantum *) NULL)
6081 for (x=0; x < (int) canvas->
columns; x++)
6088 *q=(
unsigned char) pixel;
6094 *q|=(
unsigned char) (pixel << 4);
6115 XDitherImage(canvas,ximage,exception);
6118 for (y=0; y < (int) canvas->
rows; y++)
6122 if (p == (
const Quantum *) NULL)
6124 for (x=0; x < (int) canvas->
columns; x++)
6127 *q++=(
unsigned char) pixel;
6145 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6146 for (y=0; y < (int) canvas->
rows; y++)
6150 if (p == (
const Quantum *) NULL)
6152 for (x=0; x < (int) canvas->
columns; x++)
6155 for (k=0; k < (int) bytes_per_pixel; k++)
6157 *q++=(
unsigned char) (pixel & 0xff);
6168 switch (ximage->bits_per_pixel)
6178 for (y=0; y < (int) canvas->
rows; y++)
6183 if (p == (
const Quantum *) NULL)
6185 for (x=0; x < (int) canvas->
columns; x++)
6187 pixel=XGammaPixel(canvas,map_info,p);
6193 *q=(
unsigned char) pixel;
6199 *q|=(
unsigned char) (pixel << 2);
6205 *q|=(
unsigned char) (pixel << 4);
6211 *q|=(
unsigned char) (pixel << 6);
6231 for (y=0; y < (int) canvas->
rows; y++)
6235 if (p == (
const Quantum *) NULL)
6238 for (x=0; x < (int) canvas->
columns; x++)
6240 pixel=XGammaPixel(canvas,map_info,p);
6246 *q=(
unsigned char) pixel;
6252 *q|=(
unsigned char) (pixel << 4);
6273 XDitherImage(canvas,ximage,exception);
6276 for (y=0; y < (int) canvas->
rows; y++)
6280 if (p == (
const Quantum *) NULL)
6282 for (x=0; x < (int) canvas->
columns; x++)
6284 pixel=XGammaPixel(canvas,map_info,p);
6285 *q++=(
unsigned char) pixel;
6294 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6295 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6296 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6297 (map_info->blue_mult == 1))
6302 for (y=0; y < (int) canvas->
rows; y++)
6306 if (p == (
const Quantum *) NULL)
6308 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6309 (blue_gamma != 1.0))
6314 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6316 *q++=ScaleQuantumToChar(XBlueGamma(
6318 *q++=ScaleQuantumToChar(XGreenGamma(
6320 *q++=ScaleQuantumToChar(XRedGamma(
6327 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6338 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6339 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6340 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6341 (map_info->blue_mult == 65536L))
6346 for (y=0; y < (int) canvas->
rows; y++)
6350 if (p == (
const Quantum *) NULL)
6352 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6353 (blue_gamma != 1.0))
6358 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6360 *q++=ScaleQuantumToChar(XRedGamma(
6362 *q++=ScaleQuantumToChar(XGreenGamma(
6364 *q++=ScaleQuantumToChar(XBlueGamma(
6371 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6392 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6393 for (y=0; y < (int) canvas->
rows; y++)
6397 if (p == (
const Quantum *) NULL)
6399 for (x=0; x < (int) canvas->
columns; x++)
6401 pixel=XGammaPixel(canvas,map_info,p);
6402 for (k=0; k < (int) bytes_per_pixel; k++)
6404 *q++=(
unsigned char) (pixel & 0xff);
6415 if (matte_image != (XImage *) NULL)
6420 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6421 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6422 q=(
unsigned char *) matte_image->data;
6423 for (y=0; y < (int) canvas->
rows; y++)
6427 if (p == (
const Quantum *) NULL)
6431 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6451 if (canvas != image)
6494 static void XMakeImageMSBFirst(
const XResourceInfo *
resource_info,
6495 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,