88 #include "MagickCore/version.h" 92 #if defined(MAGICKCORE_X11_DELEGATE) 93 #include <X11/Xproto.h> 94 #include <X11/Xlocale.h> 95 #if defined(MAGICK_HAVE_POLL) 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/(double) blue_gamma)* \ 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/(double) green_gamma)* \ 133 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \ 134 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \ 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,
511 assert(display != (Display *) NULL);
512 assert(pixel != (XPixelInfo *) NULL);
513 assert(annotate_info != (XAnnotateInfo *) NULL);
514 assert(image != (
Image *) NULL);
520 annotate_pixmap=
XCreatePixmap(display,root_window,annotate_info->width,
521 annotate_info->height,depth);
522 if (annotate_pixmap == (Pixmap) NULL)
527 context_values.background=0;
528 context_values.foreground=(size_t) (~0);
529 context_values.font=annotate_info->font_info->fid;
530 annotate_context=
XCreateGC(display,root_window,(
unsigned long)
531 (GCBackground | GCFont | GCForeground),&context_values);
532 if (annotate_context == (GC) NULL)
538 (
int) annotate_info->font_info->ascent,annotate_info->text,
539 (int) strlen(annotate_info->text));
540 (void)
XFreeGC(display,annotate_context);
544 annotate_ximage=
XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
545 annotate_info->height,AllPlanes,ZPixmap);
546 if (annotate_ximage == (XImage *) NULL)
553 if (annotate_image == (
Image *) NULL)
555 annotate_image->
columns=annotate_info->width;
556 annotate_image->
rows=annotate_info->height;
560 width=(
unsigned int) image->
columns;
561 height=(
unsigned int) image->
rows;
564 (void)
XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
567 if (annotate_info->stencil == ForegroundStencil)
570 for (y=0; y < (int) annotate_image->
rows; y++)
579 annotate_image->
columns,1,exception);
582 for (x=0; x < (int) annotate_image->
columns; x++)
585 if (XGetPixel(annotate_ximage,x,y) == 0)
591 pixel->box_color.red),q);
593 pixel->box_color.green),q);
595 pixel->box_color.blue),q);
596 if ((annotate_info->stencil == ForegroundStencil) ||
597 (annotate_info->stencil == OpaqueStencil))
606 pixel->pen_color.red),q);
608 pixel->pen_color.green),q);
610 pixel->pen_color.blue),q);
611 if (annotate_info->stencil == BackgroundStencil)
620 XDestroyImage(annotate_ximage);
624 (void)
XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
625 if ((width != (
unsigned int) annotate_image->
columns) ||
626 (height != (
unsigned int) annotate_image->
rows))
636 (void)
TransformImage(&annotate_image,(
char *) NULL,image_geometry,
639 if (annotate_info->degrees != 0.0)
653 rotate_image=
RotateImage(annotate_image,annotate_info->degrees,exception);
654 if (rotate_image == (
Image *) NULL)
657 annotate_image=rotate_image;
661 normalized_degrees=annotate_info->degrees;
662 while (normalized_degrees < -45.0)
663 normalized_degrees+=360.0;
664 for (rotations=0; normalized_degrees > 45.0; rotations++)
665 normalized_degrees-=90.0;
666 switch (rotations % 4)
676 x-=(int) annotate_image->
columns/2;
677 y+=(
int) annotate_image->
columns/2;
685 x=x-(int) annotate_image->
columns;
693 x=x-(int) annotate_image->
columns/2;
694 y=y-(
int) (annotate_image->
rows-(annotate_image->
columns/2));
702 (void)
XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
745 static char **FontToList(
char *font)
760 if (font == (
char *) NULL)
761 return((
char **) NULL);
766 for (p=font; *p !=
'\0'; p++)
767 if ((*p ==
':') || (*p ==
';') || (*p ==
','))
770 if (fontlist == (
char **) NULL)
773 return((
char **) NULL);
776 for (i=0; i < (int) fonts; i++)
778 for (q=p; *q !=
'\0'; q++)
779 if ((*q ==
':') || (*q ==
';') || (*q ==
','))
782 sizeof(*fontlist[i]));
783 if (fontlist[i] == (
char *) NULL)
786 return((
char **) NULL);
791 fontlist[i]=(
char *) NULL;
801 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
802 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
803 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
804 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
805 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
806 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
813 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
814 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
815 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
829 font_info=(XFontStruct *) NULL;
833 if ((font_name != (
char *) NULL) && (*font_name !=
'\0'))
844 fontlist=FontToList(font_name);
845 if (fontlist != (
char **) NULL)
847 for (i=0; fontlist[i] != (
char *) NULL; i++)
849 if (font_info == (XFontStruct *) NULL)
855 if (font_info == (XFontStruct *) NULL)
856 ThrowXWindowException(
XServerError,
"UnableToLoadFont",font_name);
866 while (*p != (
char *) NULL)
868 if (font_info != (XFontStruct *) NULL)
903 MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
930 assert(display != (Display *) NULL);
931 assert(window != (XWindowInfo *) NULL);
932 assert(image != (
Image *) NULL);
933 window->width=MaxIconSize;
934 window->height=MaxIconSize;
935 icon_size=(XIconSize *) NULL;
938 if (
XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
939 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
941 if (icon_size == (XIconSize *) NULL)
947 if (icon_size == (XIconSize *) NULL)
953 icon_size->min_width=1;
954 icon_size->max_width=MaxIconSize;
955 icon_size->min_height=1;
956 icon_size->max_height=MaxIconSize;
957 icon_size->width_inc=1;
958 icon_size->height_inc=1;
963 width=(
unsigned int) image->
columns;
964 height=(
unsigned int) image->
rows;
966 if (window->crop_geometry)
967 (void)
XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
971 scale_factor=(double) icon_size->max_width/width;
972 if (scale_factor > ((
double) icon_size->max_height/height))
973 scale_factor=(double) icon_size->max_height/height;
974 icon_width=(
unsigned int) icon_size->min_width;
975 while ((
int) icon_width < icon_size->max_width)
977 if (icon_width >= (
unsigned int) (scale_factor*width+0.5))
979 icon_width+=icon_size->width_inc;
981 icon_height=(
unsigned int) icon_size->min_height;
982 while ((
int) icon_height < icon_size->max_height)
984 if (icon_height >= (
unsigned int) (scale_factor*height+0.5))
986 icon_height+=icon_size->height_inc;
988 (void)
XFree((
void *) icon_size);
989 window->width=icon_width;
990 window->height=icon_height;
1032 XColor *colors,
unsigned int number_colors,XColor *color)
1057 assert(display != (Display *) NULL);
1058 assert(color != (XColor *) NULL);
1060 if (status != False)
1069 if (colors == (XColor *) NULL)
1075 for (i=0; i < (int) number_colors; i++)
1076 colors[i].pixel=(
size_t) i;
1077 if (number_colors > 256)
1079 (void)
XQueryColors(display,colormap,colors,(
int) number_colors);
1084 for (i=0; i < (int) number_colors; i++)
1086 pixel.
red=colors[i].red-(double) color->red;
1087 distance=pixel.
red*pixel.
red;
1088 if (distance > min_distance)
1090 pixel.
green=colors[i].green-(double) color->green;
1092 if (distance > min_distance)
1094 pixel.
blue=colors[i].blue-(double) color->blue;
1096 if (distance > min_distance)
1098 min_distance=distance;
1099 color->pixel=colors[i].pixel;
1152 MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
1155 #define MaxStandardColormaps 7 1156 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\ 1157 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \ 1158 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \ 1159 (unsigned long) visual_info->colormap_size),1UL << visual_info->depth) 1188 assert(display != (Display *) NULL);
1189 assert(map_info != (XStandardColormap *) NULL);
1193 visual_mask=VisualScreenMask;
1198 if (
resource_info->colors <= (one << (
size_t) visual_template.depth))
1199 visual_mask|=VisualDepthMask;
1200 if (visual_type != (
char *) NULL)
1207 visual_mask|=VisualClassMask;
1208 visual_template.klass=StaticGray;
1213 visual_mask|=VisualClassMask;
1214 visual_template.klass=GrayScale;
1219 visual_mask|=VisualClassMask;
1220 visual_template.klass=StaticColor;
1225 visual_mask|=VisualClassMask;
1226 visual_template.klass=PseudoColor;
1231 visual_mask|=VisualClassMask;
1232 visual_template.klass=TrueColor;
1237 visual_mask|=VisualClassMask;
1238 visual_template.klass=DirectColor;
1243 visual_mask|=VisualIDMask;
1248 if (isdigit((
int) ((
unsigned char) *visual_type)) != 0)
1250 visual_mask|=VisualIDMask;
1251 visual_template.visualid=
1252 strtol(visual_type,(
char **) NULL,0);
1256 "UnrecognizedVisualSpecifier",visual_type);
1264 visual_mask=VisualScreenMask | VisualIDMask;
1265 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1270 ThrowXWindowException(
XServerWarning,
"UnableToGetVisual",visual_type);
1275 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1276 return((XVisualInfo *) NULL);
1278 XVisualClassName(visual_list->klass));
1281 if ((map_info != (XStandardColormap *) NULL) && (map_type != (
char *) NULL))
1314 "RGB_%s_MAP",map_type);
1317 if (map_property != (Atom) NULL)
1324 *colormap[MaxStandardColormaps]=
1326 "_HP_RGB_SMOOTH_MAP_LIST",
1338 for (i=0; i < MaxStandardColormaps; i++)
1341 if (map_property == (Atom) NULL)
1345 if (status != False)
1350 if (status == False)
1352 ThrowXWindowException(
XServerError,
"UnableToGetStandardColormap",
1354 return((XVisualInfo *) NULL);
1359 *map_info=map_list[0];
1360 #if !defined(PRE_R4_ICCCM) 1362 for (i=0; i < number_maps; i++)
1363 for (j=0; j < number_visuals; j++)
1364 if (map_list[i].visualid ==
1367 *map_info=map_list[i];
1369 visual_list[j].visual);
1372 if (map_info->visualid != visual_template.visualid)
1375 "UnableToMatchVisualToStandardColormap",map_type);
1376 return((XVisualInfo *) NULL);
1379 if (map_info->colormap == (
Colormap) NULL)
1381 ThrowXWindowException(
XServerError,
"StandardColormapIsNotInitialized",
1383 return((XVisualInfo *) NULL);
1385 (void)
XFree((
void *) map_list);
1389 static const unsigned int 1406 visual_info=visual_list;
1408 for (i=1; i < number_visuals; i++)
1411 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1414 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1415 if (rank[p->klass] > rank[visual_info->klass])
1420 (void)
XFree((
void *) visual_list);
1426 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1427 return((XVisualInfo *) NULL);
1428 return(visual_info);
1458 MagickPrivate int XCheckDefineCursor(Display *display,Window window,
1462 assert(display != (Display *) NULL);
1494 MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
1503 assert(display != (Display *) NULL);
1504 assert(windows != (XWindows *) NULL);
1505 XDelay(display,SuspendTime);
1506 id=windows->command.id;
1508 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1509 id=windows->image.id;
1511 XRefreshWindow(display,&windows->image,&event);
1512 XDelay(display,SuspendTime << 1);
1513 id=windows->command.id;
1515 (void) XCommandWidget(display,windows,(
char const **) NULL,&event);
1516 id=windows->image.id;
1518 XRefreshWindow(display,&windows->image,&event);
1553 MagickPrivate void XClientMessage(Display *display,
const Window window,
1554 const Atom protocol,
const Atom reason,
const Time timestamp)
1559 assert(display != (Display *) NULL);
1560 (void) memset(&client_event,0,
sizeof(client_event));
1561 client_event.type=ClientMessage;
1562 client_event.window=window;
1563 client_event.message_type=protocol;
1564 client_event.format=32;
1565 client_event.data.l[0]=(long) reason;
1566 client_event.data.l[1]=(long) timestamp;
1602 static Window XClientWindow(Display *display,Window target_window)
1625 assert(display != (Display *) NULL);
1627 if (state == (Atom) NULL)
1628 return(target_window);
1631 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1632 if ((status == Success) && (type != (Atom) NULL))
1633 return(target_window);
1634 client_window=XWindowByProperty(display,target_window,state);
1635 if (client_window == (Window) NULL)
1636 return(target_window);
1637 return(client_window);
1660 DestroyXResources();
1696 MagickPrivate void XConfigureImageColormap(Display *display,
1707 XCheckRefreshWindows(display,windows);
1708 XMakeStandardColormap(display,windows->visual_info,
resource_info,image,
1709 windows->map_info,windows->pixel_info,exception);
1710 colormap=windows->map_info->colormap;
1719 XClientMessage(display,windows->image.id,windows->im_protocols,
1720 windows->im_update_colormap,CurrentTime);
1749 MagickPrivate void XConstrainWindowPosition(Display *display,
1750 XWindowInfo *window_info)
1756 assert(display != (Display *) NULL);
1757 assert(window_info != (XWindowInfo *) NULL);
1758 limit=
XDisplayWidth(display,window_info->screen)-window_info->width;
1759 if (window_info->x < 0)
1762 if (window_info->x > (
int) limit)
1763 window_info->x=(int) limit;
1764 limit=
XDisplayHeight(display,window_info->screen)-window_info->height;
1765 if (window_info->y < 0)
1768 if (window_info->y > limit)
1769 window_info->y=limit;
1799 MagickPrivate void XDelay(Display *display,
const size_t milliseconds)
1801 assert(display != (Display *) NULL);
1871 MagickPrivate void XDestroyWindowColors(Display *display,Window window)
1894 assert(display != (Display *) NULL);
1896 if (property == (Atom) NULL)
1898 ThrowXWindowException(
XServerError,
"UnableToCreateProperty",
1903 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1904 if (status != Success)
1906 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1908 (void)
XKillClient(display,(XID) (*((Pixmap *) data)));
1912 (void)
XFree((
void *) data);
1980 assert(display != (Display *) NULL);
1982 assert(windows != (XWindows *) NULL);
1983 assert(image != (
Image *) NULL);
1988 if (unique_file != -1)
1989 file=fdopen(unique_file,
"w");
1990 if ((unique_file == -1) || (file == (FILE *) NULL))
1992 XNoticeWidget(display,windows,
"Unable to display image info",filename);
2003 XVisualClassName((
int) windows->image.storage_class));
2005 if (windows->visual_info->colormap_size != 0)
2007 windows->visual_info->colormap_size);
2013 windows->image.ximage->width,windows->image.ximage->height);
2014 if (windows->image.crop_geometry != (
char *) NULL)
2016 windows->image.crop_geometry);
2017 if (windows->image.pixmap == (Pixmap) NULL)
2038 for (levels=0; undo_image != (
Image *) NULL; levels++)
2046 ((bytes+(1 << 19)) >> 20));
2053 (void) fclose(file);
2056 if (text == (
char *) NULL)
2058 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
2059 "UnableToDisplayImageInfo");
2063 if (textlist != (
char **) NULL)
2071 (void)
XWithdrawWindow(display,windows->info.id,windows->info.screen);
2075 (
char const **) textlist);
2076 for (i=0; textlist[i] != (
char *) NULL; i++)
2115 static const short int 2118 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2119 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2121 dither_green[2][16]=
2123 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2124 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2128 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2129 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2167 for (i=0; i < 2; i++)
2168 for (j=0; j < 16; j++)
2173 sizeof(*green_map));
2180 for (i=0; i < 2; i++)
2181 for (j=0; j < 16; j++)
2182 for (x=0; x < 256; x++)
2187 value+=dither_red[i][j];
2188 red_map[i][j][x]=(
unsigned char)
2189 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2193 value+=dither_green[i][j];
2194 green_map[i][j][x]=(
unsigned char)
2195 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2199 value+=((size_t) dither_blue[i][j] << 1);
2200 blue_map[i][j][x]=(
unsigned char)
2201 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2206 scanline_pad=(
unsigned int) (ximage->bytes_per_line-
2207 ((
size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2212 for (y=0; y < (int) image->
rows; y++)
2216 if (p == (
const Quantum *) NULL)
2218 for (x=0; x < (int) image->
columns; x++)
2221 (int) ScaleQuantumToChar(
GetPixelRed(image,p))] << 8));
2225 (int) ScaleQuantumToChar(
GetPixelBlue(image,p))] << 8));
2226 pixel=(size_t) (((
size_t) color.
red & 0xe0) |
2227 (((
size_t) color.
green & 0xe0) >> 3) |
2228 (((size_t) color.
blue & 0xc0) >> 6));
2244 for (i=0; i < 2; i++)
2245 for (j=0; j < 16; j++)
2286 const XPixelInfo *pixel,XDrawInfo *draw_info,
Image *image,
2325 assert(display != (Display *) NULL);
2326 assert(pixel != (XPixelInfo *) NULL);
2327 assert(draw_info != (XDrawInfo *) NULL);
2328 assert(image != (
Image *) NULL);
2336 draw_pixmap=
XCreatePixmap(display,root_window,draw_info->width,
2337 draw_info->height,depth);
2338 if (draw_pixmap == (Pixmap) NULL)
2343 context_values.background=(size_t) (~0);
2344 context_values.foreground=0;
2345 context_values.line_width=(int) draw_info->line_width;
2346 draw_context=
XCreateGC(display,root_window,(
size_t)
2347 (GCBackground | GCForeground | GCLineWidth),&context_values);
2348 if (draw_context == (GC) NULL)
2353 (void)
XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2360 if (draw_info->stipple != (Pixmap) NULL)
2362 (void)
XSetFillStyle(display,draw_context,FillOpaqueStippled);
2363 (void)
XSetStipple(display,draw_context,draw_info->stipple);
2365 switch (draw_info->element)
2370 (void)
XDrawLines(display,draw_pixmap,draw_context,
2371 draw_info->coordinate_info,(
int) draw_info->number_coordinates,
2377 (void)
XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2378 draw_info->line_info.y1,draw_info->line_info.x2,
2379 draw_info->line_info.y2);
2382 case RectangleElement:
2385 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2386 (
unsigned int) draw_info->rectangle_info.width,
2387 (
unsigned int) draw_info->rectangle_info.height);
2390 case FillRectangleElement:
2393 (
int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2394 (
unsigned int) draw_info->rectangle_info.width,
2395 (
unsigned int) draw_info->rectangle_info.height);
2399 case EllipseElement:
2401 (void)
XDrawArc(display,draw_pixmap,draw_context,
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,0,360*64);
2407 case FillCircleElement:
2408 case FillEllipseElement:
2410 (void)
XFillArc(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 PolygonElement:
2421 coordinate_info=draw_info->coordinate_info;
2422 (void)
XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2423 (
int) draw_info->number_coordinates,CoordModeOrigin);
2424 (void)
XDrawLine(display,draw_pixmap,draw_context,
2425 coordinate_info[draw_info->number_coordinates-1].x,
2426 coordinate_info[draw_info->number_coordinates-1].y,
2427 coordinate_info[0].x,coordinate_info[0].y);
2430 case FillPolygonElement:
2433 draw_info->coordinate_info,(
int) draw_info->number_coordinates,Complex,
2438 (void)
XFreeGC(display,draw_context);
2442 draw_ximage=
XGetImage(display,draw_pixmap,0,0,draw_info->width,
2443 draw_info->height,AllPlanes,ZPixmap);
2444 if (draw_ximage == (XImage *) NULL)
2451 if (draw_image == (
Image *) NULL)
2453 draw_image->
columns=draw_info->width;
2454 draw_image->
rows=draw_info->height;
2458 width=(
unsigned int) image->
columns;
2459 height=(
unsigned int) image->
rows;
2469 for (y=0; y < (int) draw_image->
rows; y++)
2481 for (x=0; x < (int) draw_image->
columns; x++)
2483 if (XGetPixel(draw_ximage,x,y) == 0)
2498 pixel->pen_color.red),q);
2500 pixel->pen_color.green),q);
2502 pixel->pen_color.blue),q);
2512 XDestroyImage(draw_ximage);
2517 if ((width != (
unsigned int) draw_image->
columns) ||
2518 (height != (
unsigned int) draw_image->
rows))
2531 if (draw_info->degrees != 0.0)
2545 rotate_image=
RotateImage(draw_image,draw_info->degrees,exception);
2546 if (rotate_image == (
Image *) NULL)
2549 draw_image=rotate_image;
2553 normalized_degrees=draw_info->degrees;
2554 while (normalized_degrees < -45.0)
2555 normalized_degrees+=360.0;
2556 for (rotations=0; normalized_degrees > 45.0; rotations++)
2557 normalized_degrees-=90.0;
2558 switch (rotations % 4)
2568 x=x-(int) draw_image->
columns/2;
2569 y=y+(
int) draw_image->
columns/2;
2577 x=x-(int) draw_image->
columns;
2585 x=x-(int) draw_image->
columns/2;
2586 y=y-(
int) (draw_image->
rows-(draw_image->
columns/2));
2595 for (y=0; y < (int) draw_image->
rows; y++)
2607 for (x=0; x < (int) draw_image->
columns; x++)
2618 if (draw_info->stencil == TransparentStencil)
2620 (ssize_t) x,(ssize_t) y,exception);
2625 (ssize_t) x,(ssize_t) y,exception);
2661 #if defined(__cplusplus) || defined(c_plusplus) 2665 MagickExport int XError(Display *display,XErrorEvent *error)
2668 assert(display != (Display *) NULL);
2669 assert(error != (XErrorEvent *) NULL);
2671 switch (error->request_code)
2675 if ((
int) error->error_code == BadDrawable)
2679 case X_GetWindowAttributes:
2682 if ((
int) error->error_code == BadWindow)
2688 if ((
int) error->error_code == BadValue)
2696 #if defined(__cplusplus) || defined(c_plusplus) 2740 MagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
2741 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2745 assert(display != (Display *) NULL);
2747 if (window_info != (XWindowInfo *) NULL)
2752 if (window_info->ximage != (XImage *) NULL)
2753 XDestroyImage(window_info->ximage);
2754 if (window_info->id != (Window) NULL)
2759 if (window_info->id !=
XRootWindow(display,visual_info->screen))
2761 if (window_info->annotate_context != (GC) NULL)
2762 (
void)
XFreeGC(display,window_info->annotate_context);
2763 if (window_info->highlight_context != (GC) NULL)
2764 (void)
XFreeGC(display,window_info->highlight_context);
2765 if (window_info->widget_context != (GC) NULL)
2766 (
void)
XFreeGC(display,window_info->widget_context);
2767 if (window_info->cursor != (Cursor) NULL)
2769 window_info->cursor=(Cursor) NULL;
2770 if (window_info->busy_cursor != (Cursor) NULL)
2771 (
void)
XFreeCursor(display,window_info->busy_cursor);
2772 window_info->busy_cursor=(Cursor) NULL;
2778 if (font_info != (XFontStruct *) NULL)
2781 font_info=(XFontStruct *) NULL;
2783 if (map_info != (XStandardColormap *) NULL)
2789 (
void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2790 (void)
XFree((
void *) map_info);
2795 if (visual_info != (XVisualInfo *) NULL)
2796 (
void)
XFree((
void *) visual_info);
2835 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2841 assert(display != (Display *) NULL);
2842 assert(visual_info != (XVisualInfo *) NULL);
2843 assert(map_info != (XStandardColormap *) NULL);
2845 if (map_info->colormap != (
Colormap) NULL)
2850 if (pixel != (XPixelInfo *) NULL)
2851 if ((visual_info->klass != TrueColor) &&
2852 (visual_info->klass != DirectColor))
2853 (void)
XFreeColors(display,map_info->colormap,pixel->pixels,
2854 (
int) pixel->colors,0);
2856 map_info->colormap=(
Colormap) NULL;
2857 if (pixel != (XPixelInfo *) NULL)
2859 if (pixel->pixels != (
unsigned long *) NULL)
2861 pixel->pixels=(
unsigned long *) NULL;
2887 MagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2893 assert(annotate_info != (XAnnotateInfo *) NULL);
2896 annotate_info->width=0;
2897 annotate_info->height=0;
2898 annotate_info->stencil=ForegroundStencil;
2899 annotate_info->degrees=0.0;
2900 annotate_info->font_info=(XFontStruct *) NULL;
2901 annotate_info->text=(
char *) NULL;
2902 *annotate_info->geometry=
'\0';
2903 annotate_info->previous=(XAnnotateInfo *) NULL;
2904 annotate_info->next=(XAnnotateInfo *) NULL;
2937 MagickPrivate void XGetMapInfo(
const XVisualInfo *visual_info,
2938 const Colormap colormap,XStandardColormap *map_info)
2944 assert(visual_info != (XVisualInfo *) NULL);
2945 assert(map_info != (XStandardColormap *) NULL);
2946 map_info->colormap=colormap;
2947 map_info->red_max=visual_info->red_mask;
2948 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2949 if (map_info->red_max != 0)
2950 while ((map_info->red_max & 0x01) == 0)
2952 map_info->red_max>>=1;
2953 map_info->red_mult<<=1;
2955 map_info->green_max=visual_info->green_mask;
2956 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2957 if (map_info->green_max != 0)
2958 while ((map_info->green_max & 0x01) == 0)
2960 map_info->green_max>>=1;
2961 map_info->green_mult<<=1;
2963 map_info->blue_max=visual_info->blue_mask;
2964 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2965 if (map_info->blue_max != 0)
2966 while ((map_info->blue_max & 0x01) == 0)
2968 map_info->blue_max>>=1;
2969 map_info->blue_mult<<=1;
2971 map_info->base_pixel=0;
3013 const XVisualInfo *visual_info,
const XStandardColormap *map_info,
3017 *PenColors[MaxNumberPens]=
3048 assert(display != (Display *) NULL);
3049 assert(visual_info != (XVisualInfo *) NULL);
3050 assert(map_info != (XStandardColormap *) NULL);
3052 assert(pixel != (XPixelInfo *) NULL);
3054 if (image != (
Image *) NULL)
3056 pixel->colors=(ssize_t) image->
colors;
3057 packets=(
unsigned int)
3058 MagickMax((
int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3059 if (pixel->pixels != (
unsigned long *) NULL)
3062 sizeof(*pixel->pixels));
3063 if (pixel->pixels == (
unsigned long *) NULL)
3069 colormap=map_info->colormap;
3071 &pixel->foreground_color);
3073 &pixel->foreground_color);
3074 if (status == False)
3075 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3077 pixel->foreground_color.pixel=
3078 XStandardPixel(map_info,&pixel->foreground_color);
3079 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3083 (void)
XParseColor(display,colormap,
"#d6d6d6d6d6d6",&pixel->background_color);
3085 &pixel->background_color);
3086 if (status == False)
3087 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3089 pixel->background_color.pixel=
3090 XStandardPixel(map_info,&pixel->background_color);
3091 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3096 &pixel->border_color);
3098 &pixel->border_color);
3099 if (status == False)
3100 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3102 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3103 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3107 pixel->matte_color=pixel->background_color;
3114 &pixel->matte_color);
3115 if (status == False)
3116 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3118 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3119 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3124 pixel->highlight_color.red=(
unsigned short) (((
double)
3127 pixel->highlight_color.green=(
unsigned short) (((
double)
3130 pixel->highlight_color.blue=(
unsigned short) (((
double)
3133 pixel->highlight_color.pixel=XStandardPixel(map_info,&pixel->highlight_color);
3134 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3138 pixel->shadow_color.red=(
unsigned short) (((
double)
3139 pixel->matte_color.red*ScaleQuantumToShort(
ShadowModulate))/65535L);
3140 pixel->shadow_color.green=(
unsigned short) (((
double)
3141 pixel->matte_color.green*ScaleQuantumToShort(
ShadowModulate))/65535L);
3142 pixel->shadow_color.blue=(
unsigned short) (((
double)
3143 pixel->matte_color.blue*ScaleQuantumToShort(
ShadowModulate))/65535L);
3144 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3145 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3149 pixel->depth_color.red=(
unsigned short) (((
double)
3150 pixel->matte_color.red*ScaleQuantumToShort(
DepthModulate))/65535L);
3151 pixel->depth_color.green=(
unsigned short) (((
double)
3152 pixel->matte_color.green*ScaleQuantumToShort(
DepthModulate))/65535L);
3153 pixel->depth_color.blue=(
unsigned short) (((
double)
3154 pixel->matte_color.blue*ScaleQuantumToShort(
DepthModulate))/65535L);
3155 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3156 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3160 pixel->trough_color.red=(
unsigned short) (((
double)
3161 pixel->matte_color.red*ScaleQuantumToShort(
TroughModulate))/65535L);
3162 pixel->trough_color.green=(
unsigned short) (((
double)
3163 pixel->matte_color.green*ScaleQuantumToShort(
TroughModulate))/65535L);
3164 pixel->trough_color.blue=(
unsigned short) (((
double)
3165 pixel->matte_color.blue*ScaleQuantumToShort(
TroughModulate))/65535L);
3166 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3167 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3171 for (i=0; i < MaxNumberPens; i++)
3173 (void)
XParseColor(display,colormap,(
char *) PenColors[i],
3174 &pixel->pen_colors[i]);
3176 &pixel->pen_colors[i]);
3177 if (status == False)
3178 ThrowXWindowException(
XServerError,
"ColorIsNotKnownToServer",
3180 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3181 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3183 pixel->box_color=pixel->background_color;
3184 pixel->pen_color=pixel->foreground_color;
3187 if (image != (
Image *) NULL)
3190 (image->
gamma != 0.0))
3202 red_gamma=geometry_info.
rho;
3203 green_gamma=geometry_info.
sigma;
3205 green_gamma=red_gamma;
3206 blue_gamma=geometry_info.
xi;
3208 blue_gamma=red_gamma;
3209 red_gamma*=image->
gamma;
3210 green_gamma*=image->
gamma;
3211 blue_gamma*=image->
gamma;
3218 for (i=0; i < (ssize_t) image->
colors; i++)
3219 pixel->pixels[i]=XGammaPacket(map_info,image->
colormap+i);
3220 for (i=0; i < MaxNumberPens; i++)
3221 pixel->pixels[image->
colors+i]=pixel->pen_colors[i].pixel;
3222 pixel->colors+=MaxNumberPens;
3261 MagickExport char *XGetResourceClass(XrmDatabase database,
3262 const char *client_name,
const char *keyword,
char *resource_default)
3277 if (database == (XrmDatabase) NULL)
3278 return(resource_default);
3279 *resource_name=
'\0';
3280 *resource_class=
'\0';
3281 if (keyword != (
char *) NULL)
3291 client_name,keyword);
3292 c=(int) (*client_name);
3293 if ((c >= XK_a) && (c <= XK_z))
3296 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3297 c-=(XK_agrave-XK_Agrave);
3299 if ((c >= XK_oslash) && (c <= XK_thorn))
3300 c-=(XK_oslash-XK_Ooblique);
3302 if ((k >= XK_a) && (k <= XK_z))
3305 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3306 k-=(XK_agrave-XK_Agrave);
3308 if ((k >= XK_oslash) && (k <= XK_thorn))
3309 k-=(XK_oslash-XK_Ooblique);
3311 client_name+1,k,keyword+1);
3313 status=
XrmGetResource(database,resource_name,resource_class,&resource_type,
3315 if (status == False)
3316 return(resource_default);
3317 return(resource_value.addr);
3350 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3351 const char *client_name)
3366 if (display == (Display *) NULL)
3367 return((XrmDatabase) NULL);
3368 assert(client_name != (
char *) NULL);
3373 (void)
XGetDefault(display,(
char *) client_name,
"dummy");
3378 p=client_name+(strlen(client_name)-1);
3379 while ((p > client_name) && (*p !=
'/'))
3383 c=(int) (*client_name);
3384 if ((c >= XK_a) && (c <= XK_z))
3387 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3388 c-=(XK_agrave-XK_Agrave);
3390 if ((c >= XK_oslash) && (c <= XK_thorn))
3391 c-=(XK_oslash-XK_Ooblique);
3392 #if defined(X11_APPLICATION_PATH) 3394 X11_APPLICATION_PATH,c,client_name+1);
3408 #if defined(X11_PREFERENCES_PATH) 3414 return(resource_database);
3449 XrmDatabase database,
const char *client_name,XResourceInfo *
resource_info)
3464 XMagickProgressMonitor,(
void *) NULL);
3468 resource_value=XGetResourceClass(database,client_name,
"backdrop",
3471 resource_info->background_color=XGetResourceInstance(database,client_name,
3472 "background",(
char *)
"#d6d6d6d6d6d6");
3473 resource_info->border_color=XGetResourceInstance(database,client_name,
3475 resource_value=XGetResourceClass(database,client_name,
"borderWidth",
3479 resource_value=XGetResourceClass(database,client_name,
"colormap",
3487 ThrowXWindowException(
OptionError,
"UnrecognizedColormapType",
3489 resource_value=XGetResourceClass(database,client_name,
3490 "colorRecovery",(
char *)
"False");
3492 resource_value=XGetResourceClass(database,client_name,
"confirmExit",
3495 resource_value=XGetResourceClass(database,client_name,
"confirmEdit",
3498 resource_value=XGetResourceClass(database,client_name,
"delay",(
char *)
"1");
3500 resource_info->display_gamma=XGetResourceClass(database,client_name,
3501 "displayGamma",(
char *)
"2.2");
3502 resource_value=XGetResourceClass(database,client_name,
"displayWarnings",
3505 resource_info->font=XGetResourceClass(database,client_name,
"font",
3507 resource_info->font=XGetResourceClass(database,client_name,
"fontList",
3509 resource_info->font_name[0]=XGetResourceClass(database,client_name,
"font1",
3511 resource_info->font_name[1]=XGetResourceClass(database,client_name,
"font2",
3512 (
char *)
"variable");
3513 resource_info->font_name[2]=XGetResourceClass(database,client_name,
"font3",
3515 resource_info->font_name[3]=XGetResourceClass(database,client_name,
"font4",
3517 resource_info->font_name[4]=XGetResourceClass(database,client_name,
"font5",
3518 (
char *)
"7x13bold");
3519 resource_info->font_name[5]=XGetResourceClass(database,client_name,
"font6",
3520 (
char *)
"8x13bold");
3521 resource_info->font_name[6]=XGetResourceClass(database,client_name,
"font7",
3522 (
char *)
"9x15bold");
3523 resource_info->font_name[7]=XGetResourceClass(database,client_name,
"font8",
3525 resource_info->font_name[8]=XGetResourceClass(database,client_name,
"font9",
3527 resource_info->font_name[9]=XGetResourceClass(database,client_name,
"font0",
3529 resource_info->font_name[10]=XGetResourceClass(database,client_name,
"font0",
3531 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3533 resource_value=XGetResourceClass(database,client_name,
"gammaCorrect",
3537 client_name,
"geometry",(
char *) NULL));
3538 resource_value=XGetResourceClass(database,client_name,
"gravity",
3544 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3545 "iconGeometry",(
char *) NULL);
3546 resource_value=XGetResourceClass(database,client_name,
"iconic",
3549 resource_value=XGetResourceClass(database,client_name,
"immutable",
3550 LocaleCompare(client_name,
"PerlMagick") == 0 ? (
char *)
"True" :
3553 resource_value=XGetResourceClass(database,client_name,
"magnify",
3556 resource_info->map_type=XGetResourceClass(database,client_name,
"map",
3558 resource_info->matte_color=XGetResourceInstance(database,client_name,
3559 "mattecolor",(
char *) NULL);
3561 "name",(
char *) NULL));
3562 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,
"pen1",
3564 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,
"pen2",
3566 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,
"pen3",
3568 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,
"pen4",
3570 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,
"pen5",
3572 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,
"pen6",
3574 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,
"pen7",
3575 (
char *)
"magenta");
3576 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,
"pen8",
3578 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,
"pen9",
3580 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,
"pen0",
3582 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,
"pen0",
3584 resource_value=XGetResourceClass(database,client_name,
"pause",(
char *)
"0");
3586 resource_value=XGetResourceClass(database,client_name,
"quantum",(
char *)
"1");
3588 resource_info->text_font=XGetResourceClass(database,client_name,(
char *)
3589 "font",(
char *)
"fixed");
3590 resource_info->text_font=XGetResourceClass(database,client_name,
3592 resource_info->title=XGetResourceClass(database,client_name,
"title",
3594 resource_value=XGetResourceClass(database,client_name,
"undoCache",
3597 resource_value=XGetResourceClass(database,client_name,
"update",
3600 resource_value=XGetResourceClass(database,client_name,
"usePixmap",
3603 resource_value=XGetResourceClass(database,client_name,
"sharedMemory",
3606 resource_info->visual_type=XGetResourceClass(database,client_name,
"visual",
3608 resource_info->window_group=XGetResourceClass(database,client_name,
3609 "windowGroup",(
char *) NULL);
3610 resource_info->window_id=XGetResourceClass(database,client_name,
"window",
3612 resource_info->write_filename=XGetResourceClass(database,client_name,
3613 "writeFilename",(
char *) NULL);
3650 MagickExport char *XGetResourceInstance(XrmDatabase database,
3651 const char *client_name,
const char *keyword,
const char *resource_default)
3663 if (database == (XrmDatabase) NULL)
3664 return((
char *) resource_default);
3665 *resource_name=
'\0';
3666 if (keyword != (
char *) NULL)
3669 status=
XrmGetResource(database,resource_name,
"ImageMagick",&resource_type,
3671 if (status == False)
3672 return((
char *) resource_default);
3673 return(resource_value.addr);
3715 x_density=((((double) DisplayWidth(display,
XDefaultScreen(display)))*25.4)/
3717 y_density=((((double) DisplayHeight(display,
XDefaultScreen(display)))*25.4)/
3759 static Window XGetSubwindow(Display *display,Window window,
int x,
int y)
3772 assert(display != (Display *) NULL);
3774 if (window == (Window) NULL)
3775 return(source_window);
3776 target_window=window;
3780 &x_offset,&y_offset,&target_window);
3783 if (target_window == (Window) NULL)
3785 source_window=window;
3786 window=target_window;
3790 if (target_window == (Window) NULL)
3791 target_window=window;
3792 return(target_window);
3861 assert(display != (Display *) NULL);
3862 assert(name != (
char *) NULL);
3865 target_window=XSelectWindow(display,&crop_info);
3866 if (target_window == (Window) NULL)
3869 client_window=target_window;
3870 if (target_window != root_window)
3878 status=
XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3879 if (status != False)
3881 client_window=XClientWindow(display,target_window);
3882 target_window=client_window;
3889 if ((status == False) || (window_attributes.map_state != IsViewable))
3895 (
int) crop_info.
x,(int) crop_info.
y,&x,&y,&child);
3896 ximage=
XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3897 if (ximage == (XImage *) NULL)
3899 color.pixel=XGetPixel(ximage,0,0);
3900 XDestroyImage(ximage);
3904 (void)
XQueryColor(display,window_attributes.colormap,&color);
3905 pixel.
red=(double) ScaleShortToQuantum(color.red);
3906 pixel.
green=(double) ScaleShortToQuantum(color.green);
3907 pixel.
blue=(double) ScaleShortToQuantum(color.blue);
3956 static Image *XGetWindowImage(Display *display,
const Window window,
3957 const unsigned int borders,
const unsigned int level,
ExceptionInfo *exception)
3971 typedef struct _WindowInfo
4030 assert(display != (Display *) NULL);
4032 if ((status == False) || (window_attributes.map_state != IsViewable))
4033 return((
Image *) NULL);
4040 crop_info.
x=(ssize_t) x_offset;
4041 crop_info.
y=(ssize_t) y_offset;
4042 crop_info.
width=(size_t) window_attributes.width;
4043 crop_info.
height=(
size_t) window_attributes.height;
4049 crop_info.
x-=(ssize_t) window_attributes.border_width;
4050 crop_info.
y-=(ssize_t) window_attributes.border_width;
4051 crop_info.
width+=(size_t) (window_attributes.border_width << 1);
4052 crop_info.
height+=(size_t) (window_attributes.border_width << 1);
4057 if (crop_info.
x < 0)
4059 crop_info.
width+=crop_info.
x;
4062 if (crop_info.
y < 0)
4064 crop_info.
height+=crop_info.
y;
4068 if ((
int) (crop_info.
x+crop_info.
width) > display_width)
4069 crop_info.
width=(size_t) (display_width-crop_info.
x);
4071 if ((
int) (crop_info.
y+crop_info.
height) > display_height)
4072 crop_info.
height=(size_t) (display_height-crop_info.
y);
4076 if (number_windows >= max_windows)
4082 if (window_info == (WindowInfo *) NULL)
4084 sizeof(*window_info));
4087 max_windows,
sizeof(*window_info));
4089 if (window_info == (WindowInfo *) NULL)
4092 return((
Image *) NULL);
4094 id=number_windows++;
4095 window_info[id].window=window;
4096 window_info[id].visual=window_attributes.visual;
4097 window_info[id].colormap=window_attributes.colormap;
4098 window_info[id].bounds.x1=(short) crop_info.
x;
4099 window_info[
id].bounds.y1=(
short) crop_info.
y;
4100 window_info[id].bounds.x2=(short) (crop_info.
x+(
int) crop_info.
width-1);
4101 window_info[id].bounds.y2=(short) (crop_info.
y+(
int) crop_info.
height-1);
4102 crop_info.
x-=x_offset;
4103 crop_info.
y-=y_offset;
4104 window_info[id].crop_info=crop_info;
4116 status=
XQueryTree(display,window,&root_window,&window_info[
id].parent,
4117 &children,&number_children);
4118 for (i=0; i < id; i++)
4119 if ((window_info[i].window == window_info[
id].parent) &&
4120 (window_info[i].visual == window_info[
id].visual) &&
4121 (window_info[i].colormap == window_info[
id].colormap))
4123 if ((window_info[
id].bounds.x1 < window_info[i].bounds.x1) ||
4124 (window_info[
id].bounds.x2 > window_info[i].bounds.x2) ||
4125 (window_info[
id].bounds.y1 < window_info[i].bounds.y1) ||
4126 (window_info[
id].bounds.y2 > window_info[i].bounds.y2))
4135 if ((status == True) && (number_children != 0))
4137 for (i=0; i < (int) number_children; i++)
4138 (
void) XGetWindowImage(display,children[i],
MagickFalse,level+1,
4140 (void)
XFree((
void *) children);
4184 for (
id=0;
id < number_windows;
id++)
4189 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4190 (window_info[
id].bounds.x1 <= window_info[0].bounds.x2) &&
4191 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4192 (window_info[
id].bounds.y1 <= window_info[0].bounds.y2)) ?
4197 for (j=0; j < id; j++)
4198 if ((window_info[
id].visual == window_info[j].visual) &&
4199 (window_info[id].colormap == window_info[j].colormap))
4201 if ((window_info[
id].bounds.x1 >= window_info[j].bounds.x1) &&
4202 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4203 (window_info[
id].bounds.y1 >= window_info[j].bounds.y1) &&
4204 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4212 ximage=
XGetImage(display,window_info[
id].window,(
int)
4213 window_info[
id].crop_info.
x,(
int) window_info[
id].crop_info.y,
4214 (
unsigned int) window_info[
id].crop_info.width,(
unsigned int)
4215 window_info[
id].crop_info.height,AllPlanes,ZPixmap);
4216 if (ximage == (XImage *) NULL)
4222 colors=(XColor *) NULL;
4223 if (window_info[
id].colormap != (
Colormap) NULL)
4231 number_colors=(
unsigned int) window_info[
id].visual->map_entries;
4232 for (p=colormap_info; p != (
ColormapInfo *) NULL; p=p->next)
4233 if (p->colormap == window_info[
id].colormap)
4242 if (colors == (XColor *) NULL)
4244 XDestroyImage(ximage);
4245 return((
Image *) NULL);
4247 if ((window_info[
id].visual->klass != DirectColor) &&
4248 (window_info[
id].visual->klass != TrueColor))
4249 for (i=0; i < (int) number_colors; i++)
4251 colors[i].pixel=(size_t) i;
4270 red_bit=window_info[id].visual->red_mask &
4271 (~(window_info[id].visual->red_mask)+1);
4272 green_bit=window_info[id].visual->green_mask &
4273 (~(window_info[id].visual->green_mask)+1);
4274 blue_bit=window_info[id].visual->blue_mask &
4275 (~(window_info[id].visual->blue_mask)+1);
4276 for (i=0; i < (int) number_colors; i++)
4278 colors[i].pixel=(
unsigned long) (red | green | blue);
4281 if (red > window_info[
id].visual->red_mask)
4284 if (green > window_info[
id].visual->green_mask)
4287 if (blue > window_info[
id].visual->blue_mask)
4291 (void)
XQueryColors(display,window_info[
id].colormap,colors,
4292 (
int) number_colors);
4298 return((
Image *) NULL);
4299 p->colormap=window_info[id].colormap;
4301 p->next=colormap_info;
4310 if (composite_image == (
Image *) NULL)
4312 XDestroyImage(ximage);
4313 return((
Image *) NULL);
4318 if ((window_info[
id].visual->klass != TrueColor) &&
4319 (window_info[
id].visual->klass != DirectColor))
4321 composite_image->
columns=(size_t) ximage->width;
4322 composite_image->
rows=(
size_t) ximage->height;
4344 red_mask=window_info[id].visual->red_mask;
4346 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4351 green_mask=window_info[id].visual->green_mask;
4353 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4358 blue_mask=window_info[id].visual->blue_mask;
4360 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4368 if ((number_colors != 0) &&
4369 (window_info[
id].visual->klass == DirectColor))
4370 for (y=0; y < (int) composite_image->
rows; y++)
4373 composite_image->
columns,1,exception);
4376 for (x=0; x < (int) composite_image->
columns; x++)
4378 pixel=XGetPixel(ximage,x,y);
4379 index=(pixel >> red_shift) & red_mask;
4381 ScaleShortToQuantum(colors[index].red),q);
4382 index=(pixel >> green_shift) & green_mask;
4384 ScaleShortToQuantum(colors[index].green),q);
4385 index=(pixel >> blue_shift) & blue_mask;
4387 ScaleShortToQuantum(colors[index].blue),q);
4395 for (y=0; y < (int) composite_image->
rows; y++)
4398 composite_image->
columns,1,exception);
4401 for (x=0; x < (int) composite_image->
columns; x++)
4403 pixel=XGetPixel(ximage,x,y);
4404 color=(pixel >> red_shift) & red_mask;
4406 color=(65535UL*color)/red_mask;
4408 (
unsigned short) color),q);
4409 color=(pixel >> green_shift) & green_mask;
4410 if (green_mask != 0)
4411 color=(65535UL*color)/green_mask;
4413 (
unsigned short) color),q);
4414 color=(pixel >> blue_shift) & blue_mask;
4416 color=(65535UL*color)/blue_mask;
4418 (
unsigned short) color),q);
4436 XDestroyImage(ximage);
4438 return((
Image *) NULL);
4440 for (i=0; i < (int) composite_image->
colors; i++)
4442 composite_image->
colormap[colors[i].pixel].
red=(double)
4443 ScaleShortToQuantum(colors[i].red);
4445 ScaleShortToQuantum(colors[i].green);
4446 composite_image->
colormap[colors[i].pixel].
blue=(double)
4447 ScaleShortToQuantum(colors[i].blue);
4452 for (y=0; y < (int) composite_image->
rows; y++)
4455 composite_image->
columns,1,exception);
4458 for (x=0; x < (int) composite_image->
columns; x++)
4460 index=(
Quantum) XGetPixel(ximage,x,y);
4463 composite_image->
colormap+(ssize_t) index,q);
4474 XDestroyImage(ximage);
4475 if (image == (
Image *) NULL)
4477 image=composite_image;
4484 &x_offset,&y_offset,&child);
4485 x_offset-=(int) crop_info.
x;
4488 y_offset-=(int) crop_info.
y;
4492 (ssize_t) x_offset,(ssize_t) y_offset,exception);
4500 next=colormap_info->next;
4502 colormap_info->colors);
4515 return((
Image *) NULL);
4556 MagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4557 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4564 assert(display != (Display *) NULL);
4565 assert(visual_info != (XVisualInfo *) NULL);
4566 assert(map_info != (XStandardColormap *) NULL);
4567 assert(pixel != (XPixelInfo *) NULL);
4569 assert(window != (XWindowInfo *) NULL);
4570 if (window->id != (Window) NULL)
4572 if (window->cursor != (Cursor) NULL)
4574 if (window->busy_cursor != (Cursor) NULL)
4576 if (window->highlight_stipple != (Pixmap) NULL)
4577 (void)
XFreePixmap(display,window->highlight_stipple);
4578 if (window->shadow_stipple != (Pixmap) NULL)
4579 (
void)
XFreePixmap(display,window->shadow_stipple);
4580 if (window->name == (
char *) NULL)
4582 if (window->icon_name == (
char *) NULL)
4590 window->id=(Window) NULL;
4591 if (window->name == (
char *) NULL)
4593 if (window->icon_name == (
char *) NULL)
4597 window->ximage=(XImage *) NULL;
4598 window->matte_image=(XImage *) NULL;
4599 window->pixmap=(Pixmap) NULL;
4600 window->matte_pixmap=(Pixmap) NULL;
4604 window->segment_info=(
void *) NULL;
4605 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 4610 if (window->segment_info == (
void *) NULL)
4612 segment_info=(XShmSegmentInfo *) window->segment_info;
4613 segment_info[0].shmid=(-1);
4614 segment_info[0].shmaddr=(
char *) NULL;
4615 segment_info[1].shmid=(-1);
4616 segment_info[1].shmaddr=(
char *) NULL;
4623 window->screen=visual_info->screen;
4624 window->root=
XRootWindow(display,visual_info->screen);
4625 window->visual=visual_info->visual;
4626 window->storage_class=(
unsigned int) visual_info->klass;
4627 window->depth=(
unsigned int) visual_info->depth;
4628 window->visual_info=visual_info;
4629 window->map_info=map_info;
4630 window->pixel_info=pixel;
4631 window->font_info=font_info;
4634 window->geometry=(
char *) NULL;
4635 window->icon_geometry=(
char *) NULL;
4638 window->crop_geometry=(
char *) NULL;
4639 window->flags=(size_t) PSize;
4642 window->min_width=1;
4643 window->min_height=1;
4644 window->width_inc=1;
4645 window->height_inc=1;
4647 window->annotate_context=pixel->annotate_context;
4648 window->highlight_context=pixel->highlight_context;
4649 window->widget_context=pixel->widget_context;
4650 window->shadow_stipple=(Pixmap) NULL;
4651 window->highlight_stipple=(Pixmap) NULL;
4656 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4657 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4658 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4659 window->attributes.background_pixel=pixel->background_color.pixel;
4660 window->attributes.background_pixmap=(Pixmap) NULL;
4662 window->attributes.backing_store=WhenMapped;
4664 window->attributes.border_pixel=pixel->border_color.pixel;
4665 window->attributes.colormap=map_info->colormap;
4666 window->attributes.cursor=window->cursor;
4667 window->attributes.do_not_propagate_mask=NoEventMask;
4668 window->attributes.event_mask=NoEventMask;
4706 MagickPrivate void XHighlightEllipse(Display *display,Window window,
4710 assert(display != (Display *) NULL);
4711 assert(window != (Window) NULL);
4712 assert(annotate_context != (GC) NULL);
4714 if ((highlight_info->
width < 4) || (highlight_info->
height < 4))
4716 (void)
XDrawArc(display,window,annotate_context,(
int) highlight_info->
x,
4717 (int) highlight_info->
y,(
unsigned int) highlight_info->
width-1,
4718 (
unsigned int) highlight_info->
height-1,0,360*64);
4719 (void)
XDrawArc(display,window,annotate_context,(
int) highlight_info->
x+1,
4720 (int) highlight_info->
y+1,(
unsigned int) highlight_info->
width-3,
4721 (
unsigned int) highlight_info->
height-3,0,360*64);
4756 MagickPrivate void XHighlightLine(Display *display,Window window,
4757 GC annotate_context,
const XSegment *highlight_info)
4760 assert(display != (Display *) NULL);
4761 assert(window != (Window) NULL);
4762 assert(annotate_context != (GC) NULL);
4763 assert(highlight_info != (XSegment *) NULL);
4764 (void)
XDrawLine(display,window,annotate_context,highlight_info->x1,
4765 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4800 MagickPrivate void XHighlightRectangle(Display *display,Window window,
4803 assert(display != (Display *) NULL);
4805 assert(window != (Window) NULL);
4806 assert(annotate_context != (GC) NULL);
4808 if ((highlight_info->
width < 4) || (highlight_info->
height < 4))
4810 (void)
XDrawRectangle(display,window,annotate_context,(
int) highlight_info->
x,
4811 (int) highlight_info->
y,(
unsigned int) highlight_info->
width-1,
4812 (
unsigned int) highlight_info->
height-1);
4813 (void)
XDrawRectangle(display,window,annotate_context,(
int) highlight_info->
x+
4814 1,(int) highlight_info->
y+1,(
unsigned int) highlight_info->
width-3,
4815 (
unsigned int) highlight_info->
height-3);
4881 assert(image_info != (
const ImageInfo *) NULL);
4888 if (display == (Display *) NULL)
4890 ThrowXWindowException(
XServerError,
"UnableToOpenXServer",
4892 return((
Image *) NULL);
4906 target=(Window) NULL;
4916 if (isdigit((
int) ((
unsigned char) *image_info->
filename)) != 0)
4917 target=XWindowByID(display,root,(Window)
4918 strtol(image_info->
filename,(
char **) NULL,0));
4919 if (target == (Window) NULL)
4920 target=XWindowByName(display,root,image_info->
filename);
4921 if (target == (Window) NULL)
4922 ThrowXWindowException(
XServerError,
"NoWindowWithSpecifiedIDExists",
4929 prior_target=target;
4930 if (target == (Window) NULL)
4931 target=XSelectWindow(display,&crop_info);
4932 if (target == (Window) NULL)
4933 ThrowXWindowException(
XServerError,
"UnableToReadXWindowImage",
4941 status=
XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4942 if (status != False)
4952 status=
XQueryTree(display,target,&root,&parent,&children,&d);
4953 if ((status != False) && (children != (Window *) NULL))
4954 (void)
XFree((
char *) children);
4955 if ((status == False) || (parent == (Window) NULL) ||
4963 client=XClientWindow(display,target);
4968 target=prior_target;
4986 if (status == False)
4988 ThrowXWindowException(
XServerError,
"UnableToReadXWindowAttributes",
4991 return((
Image *) NULL);
4994 crop_info.
x=(ssize_t) x;
4995 crop_info.
y=(ssize_t) y;
4996 crop_info.
width=(size_t) window_attributes.width;
4997 crop_info.
height=(
size_t) window_attributes.height;
4998 if (ximage_info->
borders != 0)
5003 crop_info.
x-=window_attributes.border_width;
5004 crop_info.
y-=window_attributes.border_width;
5005 crop_info.
width+=window_attributes.border_width << 1;
5006 crop_info.
height+=window_attributes.border_width << 1;
5015 if ((status == True) && (number_windows > 0))
5018 (void)
XFree ((
char *) children);
5021 if (number_colormaps > 0)
5023 if (number_colormaps > 1)
5025 (void)
XFree((
char *) colormaps);
5031 (void)
XBell(display,0);
5036 image=XGetWindowImage(display,target,ximage_info->
borders,
5037 ximage_info->
descend ? 1U : 0U,exception);
5039 if (image == (
Image *) NULL)
5040 ThrowXWindowException(
XServerError,
"UnableToReadXWindowImage",
5046 if ((crop_info.
width != 0) && (crop_info.
height != 0))
5054 crop_image=
CropImage(image,&crop_info,exception);
5055 if (crop_image != (
Image *) NULL)
5061 status=
XGetWMName(display,target,&window_name);
5066 (size_t) window_name.nitems+1);
5067 (void)
XFree((
void *) window_name.value);
5075 (void)
XBell(display,0);
5076 (void)
XBell(display,0);
5110 MagickPrivate XWindows *XInitializeWindows(Display *display,
5123 if (windows == (XWindows *) NULL)
5127 return((XWindows *) NULL);
5129 (void) memset(windows,0,
sizeof(*windows));
5131 sizeof(*windows->pixel_info));
5133 sizeof(*windows->icon_pixel));
5135 sizeof(*windows->icon_resources));
5136 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5137 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5138 (windows->icon_resources == (XResourceInfo *) NULL))
5142 return((XWindows *) NULL);
5147 windows->display=display;
5152 windows->im_remote_command=
5155 windows->im_update_colormap=
5162 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 5172 " Window Manager: 0x%lx",windows->wm_protocols);
5174 " delete window: 0x%lx",windows->wm_delete_window);
5176 windows->wm_take_focus);
5178 windows->im_protocols);
5180 " remote command: 0x%lx",windows->im_remote_command);
5182 " update widget: 0x%lx",windows->im_update_widget);
5184 " update colormap: 0x%lx",windows->im_update_colormap);
5186 " former image: 0x%lx",windows->im_former_image);
5188 windows->im_next_image);
5190 " retain colors: 0x%lx",windows->im_retain_colors);
5194 windows->dnd_protocols);
5201 if ((windows->map_info == (XStandardColormap *) NULL) ||
5202 (windows->icon_map == (XStandardColormap *) NULL))
5205 windows->map_info->colormap=(
Colormap) NULL;
5206 windows->icon_map->colormap=(
Colormap) NULL;
5207 windows->pixel_info->pixels=(
unsigned long *) NULL;
5208 windows->pixel_info->annotate_context=(GC) NULL;
5209 windows->pixel_info->highlight_context=(GC) NULL;
5210 windows->pixel_info->widget_context=(GC) NULL;
5211 windows->font_info=(XFontStruct *) NULL;
5212 windows->icon_pixel->annotate_context=(GC) NULL;
5213 windows->icon_pixel->pixels=(
unsigned long *) NULL;
5217 *windows->icon_resources=(*resource_info);
5218 windows->icon_resources->visual_type=(
char *)
"default";
5219 windows->icon_resources->colormap=SharedColormap;
5220 windows->visual_info=
5222 windows->icon_visual=
5223 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5224 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5225 (windows->icon_visual == (XVisualInfo *) NULL))
5232 windows->visual_info->visualid);
5234 XVisualClassName(windows->visual_info->klass));
5236 windows->visual_info->depth);
5238 " size of colormap: %d entries",windows->visual_info->colormap_size);
5240 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5241 windows->visual_info->red_mask,windows->visual_info->green_mask,
5242 windows->visual_info->blue_mask);
5244 " significant bits in color: %d bits",
5245 windows->visual_info->bits_per_rgb);
5252 if ((windows->class_hints == (XClassHint *) NULL) ||
5253 (windows->manager_hints == (XWMHints *) NULL))
5259 root_window=
XRootWindow(display,windows->visual_info->screen);
5260 windows->group_leader.id=(Window) NULL;
5263 if (isdigit((
int) ((
unsigned char) *
resource_info->window_group)) != 0)
5264 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5265 strtol((
char *)
resource_info->window_group,(
char **) NULL,0));
5266 if (windows->group_leader.id == (Window) NULL)
5267 windows->group_leader.id=
5268 XWindowByName(display,root_window,
resource_info->window_group);
5307 MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5308 Colormap colormap,
char *background_color,
char *foreground_color)
5310 #define scope_height 17 5311 #define scope_x_hot 8 5312 #define scope_y_hot 8 5313 #define scope_width 17 5315 static const unsigned char 5318 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5319 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5320 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5321 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5322 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5326 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5327 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5328 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5329 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5330 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5344 assert(display != (Display *) NULL);
5345 assert(window != (Window) NULL);
5346 assert(colormap != (
Colormap) NULL);
5347 assert(background_color != (
char *) NULL);
5348 assert(foreground_color != (
char *) NULL);
5353 scope_width,scope_height);
5354 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5356 ThrowXWindowException(
XServerError,
"UnableToCreatePixmap",
"...");
5357 return((Cursor) NULL);
5359 (void)
XParseColor(display,colormap,background_color,&background);
5360 (void)
XParseColor(display,colormap,foreground_color,&foreground);
5362 scope_x_hot,scope_y_hot);
5410 unsigned int width,
unsigned int height,
ExceptionInfo *exception)
5412 #define CheckOverflowException(length,width,height) \ 5413 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width))) 5427 assert(display != (Display *) NULL);
5429 assert(window != (XWindowInfo *) NULL);
5431 assert(height != 0);
5432 if ((window->width == 0) || (window->height == 0))
5437 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5439 depth=(int) window->depth;
5440 if (window->destroy)
5442 window->image=image;
5444 if (window->image != (
Image *) NULL)
5446 if (window->crop_geometry != (
char *) NULL)
5457 window->image->page.
x=0;
5458 window->image->page.y=0;
5460 &crop_info,exception);
5461 crop_image=
CropImage(window->image,&crop_info,exception);
5462 if (crop_image != (
Image *) NULL)
5464 if (window->image != image)
5466 window->image=crop_image;
5470 if ((width != (
unsigned int) window->image->columns) ||
5471 (height != (
unsigned int) window->image->rows))
5480 if ((window->pixel_info->colors == 0) &&
5481 (window->image->rows > (
unsigned long)
XDisplayHeight(display,window->screen)) &&
5482 (window->image->columns > (
unsigned long)
XDisplayWidth(display,window->screen)))
5483 resize_image=
ResizeImage(window->image,width,height,
5484 image->
filter,exception);
5488 resize_image=
SampleImage(window->image,width,height,
5494 if (resize_image != (
Image *) NULL)
5496 if (window->image != image)
5498 window->image=resize_image;
5502 width=(
unsigned int) window->image->columns;
5503 assert((
size_t) width == window->image->columns);
5504 height=(
unsigned int) window->image->rows;
5505 assert((
size_t) height == window->image->rows);
5510 ximage=(XImage *) NULL;
5511 format=(depth == 1) ? XYBitmap : ZPixmap;
5512 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 5518 segment_info=(XShmSegmentInfo *) window->segment_info;
5519 segment_info[1].shmid=(-1);
5520 segment_info[1].shmaddr=(
char *) NULL;
5521 ximage=XShmCreateImage(display,window->visual,(
unsigned int) depth,format,
5522 (
char *) NULL,&segment_info[1],width,height);
5524 if (ximage == (XImage *) NULL)
5528 length=(size_t) ximage->bytes_per_line*ximage->height;
5529 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5533 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5535 segment_info[1].shmaddr=(
char *) shmat(segment_info[1].shmid,0,0);
5536 if (segment_info[1].shmid < 0)
5539 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5542 if (ximage != (XImage *) NULL)
5543 XDestroyImage(ximage);
5544 ximage=(XImage *) NULL;
5545 if (segment_info[1].shmaddr)
5547 (void) shmdt(segment_info[1].shmaddr);
5548 segment_info[1].shmaddr=(
char *) NULL;
5550 if (segment_info[1].shmid >= 0)
5552 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5553 segment_info[1].shmid=(-1);
5561 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 5562 if (window->shared_memory)
5572 segment_info=(XShmSegmentInfo *) window->segment_info;
5573 ximage->data=segment_info[1].shmaddr;
5575 status=XShmAttach(display,&segment_info[1]);
5576 if (status != False)
5578 if ((status == False) || (xerror_alert !=
MagickFalse))
5581 if (status != False)
5582 XShmDetach(display,&segment_info[1]);
5584 XDestroyImage(ximage);
5585 ximage=(XImage *) NULL;
5586 if (segment_info[1].shmid >= 0)
5588 if (segment_info[1].shmaddr != NULL)
5589 (void) shmdt(segment_info[1].shmaddr);
5590 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5591 segment_info[1].shmid=(-1);
5592 segment_info[1].shmaddr=(
char *) NULL;
5598 ximage=
XCreateImage(display,window->visual,(
unsigned int) depth,format,0,
5599 (
char *) NULL,width,height,
XBitmapPad(display),0);
5600 if (ximage == (XImage *) NULL)
5605 (void) XCheckDefineCursor(display,window->id,window->cursor);
5608 length=(size_t) ximage->bytes_per_line*ximage->height;
5613 ximage->width,ximage->height);
5617 ximage->byte_order);
5619 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5620 ximage->bitmap_bit_order,ximage->bitmap_pad);
5624 ximage->bytes_per_line);
5626 ximage->bits_per_pixel);
5628 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5629 ximage->green_mask,ximage->blue_mask);
5633 if (ximage->format == XYBitmap)
5636 ximage->bytes_per_line,(size_t) ximage->depth*ximage->height);
5637 if (ximage->data != (
char *) NULL)
5638 (
void) memset(ximage->data,0,(
size_t)
5639 ximage->bytes_per_line*ximage->depth*ximage->height);
5644 ximage->bytes_per_line,(size_t) ximage->height);
5645 if (ximage->data != (
char *) NULL)
5646 (
void) memset(ximage->data,0,(
size_t)
5647 ximage->bytes_per_line*ximage->height);
5650 if (ximage->data == (
char *) NULL)
5655 XDestroyImage(ximage);
5656 ximage=(XImage *) NULL;
5657 (void) XCheckDefineCursor(display,window->id,window->cursor);
5660 if (window->ximage != (XImage *) NULL)
5665 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5666 #
if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5667 if (window->segment_info != (XShmSegmentInfo *) NULL)
5672 segment_info=(XShmSegmentInfo *) window->segment_info;
5673 if (segment_info[0].shmid >= 0)
5676 (void) XShmDetach(display,&segment_info[0]);
5678 if (segment_info[0].shmaddr != (
char *) NULL)
5679 (
void) shmdt(segment_info[0].shmaddr);
5680 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5681 segment_info[0].shmid=(-1);
5682 segment_info[0].shmaddr=(
char *) NULL;
5683 window->ximage->data=(
char *) NULL;
5687 if (window->ximage->data != (
char *) NULL)
5688 free(window->ximage->data);
5689 window->ximage->data=(
char *) NULL;
5690 XDestroyImage(window->ximage);
5691 window->ximage=(XImage *) NULL;
5693 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY) 5694 if (window->segment_info != (XShmSegmentInfo *) NULL)
5699 segment_info=(XShmSegmentInfo *) window->segment_info;
5700 segment_info[0]=segment_info[1];
5703 window->ximage=ximage;
5704 matte_image=(XImage *) NULL;
5713 matte_image=
XCreateImage(display,window->visual,1,XYBitmap,0,
5714 (
char *) NULL,width,height,
XBitmapPad(display),0);
5719 " width, height: %dx%d",matte_image->width,matte_image->height);
5721 if (matte_image != (XImage *) NULL)
5726 matte_image->data=(
char *) malloc((
size_t)
5727 matte_image->bytes_per_line*matte_image->depth*
5728 matte_image->height);
5729 if (matte_image->data == (
char *) NULL)
5731 XDestroyImage(matte_image);
5732 matte_image=(XImage *) NULL;
5736 if (window->matte_image != (XImage *) NULL)
5741 if (window->matte_image->data != (
char *) NULL)
5742 free(window->matte_image->data);
5743 window->matte_image->data=(
char *) NULL;
5744 XDestroyImage(window->matte_image);
5745 window->matte_image=(XImage *) NULL;
5747 window->matte_image=matte_image;
5748 if (window->matte_pixmap != (Pixmap) NULL)
5751 window->matte_pixmap=(Pixmap) NULL;
5752 #if defined(MAGICKCORE_HAVE_SHAPE) 5761 if (window->image != (
Image *) NULL)
5763 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5764 (ximage->bitmap_bit_order == LSBFirst)))
5765 XMakeImageLSBFirst(
resource_info,window,window->image,ximage,
5766 matte_image,exception);
5768 XMakeImageMSBFirst(
resource_info,window,window->image,ximage,
5769 matte_image,exception);
5771 if (window->matte_image != (XImage *) NULL)
5776 window->matte_pixmap=
XCreatePixmap(display,window->id,width,height,1);
5777 if (window->matte_pixmap != (Pixmap) NULL)
5788 context_values.background=0;
5789 context_values.foreground=1;
5790 graphics_context=
XCreateGC(display,window->matte_pixmap,
5791 (
size_t) (GCBackground | GCForeground),&context_values);
5792 (void)
XPutImage(display,window->matte_pixmap,graphics_context,
5793 window->matte_image,0,0,0,0,width,height);
5794 (void)
XFreeGC(display,graphics_context);
5795 #if defined(MAGICKCORE_HAVE_SHAPE) 5798 window->matte_pixmap,ShapeSet);
5806 (void) XCheckDefineCursor(display,window->id,window->cursor);
5849 static void XMakeImageLSBFirst(
const XResourceInfo *
resource_info,
5850 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
5886 assert(window != (XWindowInfo *) NULL);
5887 assert(image != (
Image *) NULL);
5907 resource_info->image_info->texture :
"pattern:checkerboard",
5912 pattern=
ReadImage(image_info,exception);
5914 if (pattern != (
Image *) NULL)
5917 if (canvas != (
Image *) NULL)
5923 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
5924 ximage->bits_per_pixel) >> 3));
5925 map_info=window->map_info;
5926 pixels=window->pixel_info->pixels;
5927 q=(
unsigned char *) ximage->data;
5930 if (ximage->format == XYBitmap)
5942 background=(
unsigned char)
5943 (XPixelIntensity(&window->pixel_info->foreground_color) <
5944 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5945 foreground=(
unsigned char)
5946 (XPixelIntensity(&window->pixel_info->background_color) <
5947 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5953 for (y=0; y < (int) canvas->
rows; y++)
5957 if (p == (
const Quantum *) NULL)
5961 for (x=0; x < (int) canvas->
columns; x++)
5983 if (window->pixel_info->colors != 0)
5984 switch (ximage->bits_per_pixel)
5994 for (y=0; y < (int) canvas->
rows; y++)
5998 if (p == (
const Quantum *) NULL)
6001 for (x=0; x < (int) canvas->
columns; x++)
6008 *q=(
unsigned char) pixel;
6014 *q|=(
unsigned char) (pixel << 2);
6020 *q|=(
unsigned char) (pixel << 4);
6026 *q|=(
unsigned char) (pixel << 6);
6046 for (y=0; y < (int) canvas->
rows; y++)
6050 if (p == (
const Quantum *) NULL)
6053 for (x=0; x < (int) canvas->
columns; x++)
6060 *q=(
unsigned char) pixel;
6066 *q|=(
unsigned char) (pixel << 4);
6087 XDitherImage(canvas,ximage,exception);
6090 for (y=0; y < (int) canvas->
rows; y++)
6094 if (p == (
const Quantum *) NULL)
6096 for (x=0; x < (int) canvas->
columns; x++)
6099 *q++=(
unsigned char) pixel;
6117 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
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 for (k=0; k < (int) bytes_per_pixel; k++)
6129 *q++=(
unsigned char) (pixel & 0xff);
6140 switch (ximage->bits_per_pixel)
6150 for (y=0; y < (int) canvas->
rows; y++)
6155 if (p == (
const Quantum *) NULL)
6157 for (x=0; x < (int) canvas->
columns; x++)
6159 pixel=XGammaPixel(canvas,map_info,p);
6165 *q=(
unsigned char) pixel;
6171 *q|=(
unsigned char) (pixel << 2);
6177 *q|=(
unsigned char) (pixel << 4);
6183 *q|=(
unsigned char) (pixel << 6);
6203 for (y=0; y < (int) canvas->
rows; y++)
6207 if (p == (
const Quantum *) NULL)
6210 for (x=0; x < (int) canvas->
columns; x++)
6212 pixel=XGammaPixel(canvas,map_info,p);
6218 *q=(
unsigned char) pixel;
6224 *q|=(
unsigned char) (pixel << 4);
6245 XDitherImage(canvas,ximage,exception);
6248 for (y=0; y < (int) canvas->
rows; y++)
6252 if (p == (
const Quantum *) NULL)
6254 for (x=0; x < (int) canvas->
columns; x++)
6256 pixel=XGammaPixel(canvas,map_info,p);
6257 *q++=(
unsigned char) pixel;
6266 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6267 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6268 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6269 (map_info->blue_mult == 1))
6274 for (y=0; y < (int) canvas->
rows; y++)
6278 if (p == (
const Quantum *) NULL)
6280 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6281 (blue_gamma != 1.0))
6286 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6288 *q++=ScaleQuantumToChar(XBlueGamma(
6290 *q++=ScaleQuantumToChar(XGreenGamma(
6292 *q++=ScaleQuantumToChar(XRedGamma(
6299 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6310 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6311 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6312 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6313 (map_info->blue_mult == 65536L))
6318 for (y=0; y < (int) canvas->
rows; y++)
6322 if (p == (
const Quantum *) NULL)
6324 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6325 (blue_gamma != 1.0))
6330 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6332 *q++=ScaleQuantumToChar(XRedGamma(
6334 *q++=ScaleQuantumToChar(XGreenGamma(
6336 *q++=ScaleQuantumToChar(XBlueGamma(
6343 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6364 bytes_per_pixel=(
unsigned int) (ximage->bits_per_pixel >> 3);
6365 for (y=0; y < (int) canvas->
rows; y++)
6369 if (p == (
const Quantum *) NULL)
6371 for (x=0; x < (int) canvas->
columns; x++)
6373 pixel=XGammaPixel(canvas,map_info,p);
6374 for (k=0; k < (int) bytes_per_pixel; k++)
6376 *q++=(
unsigned char) (pixel & 0xff);
6387 if (matte_image != (XImage *) NULL)
6392 scanline_pad=(
unsigned int) (matte_image->bytes_per_line-
6393 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6394 q=(
unsigned char *) matte_image->data;
6395 for (y=0; y < (int) canvas->
rows; y++)
6399 if (p == (
const Quantum *) NULL)
6403 for (x=(
int) canvas->
columns-1; x >= 0; x--)
6423 if (canvas != image)
6466 static void XMakeImageMSBFirst(
const XResourceInfo *
resource_info,
6467 const XWindowInfo *window,
Image *image,XImage *ximage,XImage *matte_image,
6503 assert(window != (XWindowInfo *) NULL);
6504 assert(image != (
Image *) NULL);
6524 resource_info->image_info->texture :
"pattern:checkerboard",
6529 pattern=
ReadImage(image_info,exception);
6531 if (pattern != (
Image *) NULL)
6534 if (canvas != (
Image *) NULL)
6540 scanline_pad=(
unsigned int) (ximage->bytes_per_line-((ximage->width*
6541 ximage->bits_per_pixel) >> 3));
6542 map_info=window->map_info;
6543 pixels=window->pixel_info->pixels;
6544 q=(
unsigned char *) ximage->data;