% MagickCore X11 Utility Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
if (fontlist == (char **) NULL)
{
- ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
- font);
+ ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
return((char **) NULL);
}
p=font;
sizeof(*fontlist[i]));
if (fontlist[i] == (char *) NULL)
{
- ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
- font);
+ ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
return((char **) NULL);
}
(void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
fontlist=(char **) RelinquishMagickMemory(fontlist);
}
if (font_info == (XFontStruct *) NULL)
- ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
+ ThrowXWindowException(XServerError,"UnableToLoadFont",font_name);
}
/*
Load fonts from list of fonts until one is found.
icon_size=XAllocIconSize();
if (icon_size == (XIconSize *) NULL)
{
- ThrowXWindowFatalException(ResourceLimitError,
- "MemoryAllocationFailed",image->filename);
+ ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+ image->filename);
return;
}
icon_size->min_width=1;
colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
if (colors == (XColor *) NULL)
{
- ThrowXWindowFatalException(ResourceLimitError,
- "MemoryAllocationFailed","...");
+ ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+ "...");
return;
}
for (i=0; i < (int) number_colors; i++)
strtol(visual_type,(char **) NULL,0);
}
else
- ThrowXWindowFatalException(XServerError,
+ ThrowXWindowException(XServerError,
"UnrecognizedVisualSpecifier",visual_type);
}
/*
/*
Failed to get visual; try using the default visual.
*/
- ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
- visual_type);
+ ThrowXWindowException(XServerWarning,"UnableToGetVisual",visual_type);
visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
XDefaultScreen(display)));
visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
&number_visuals);
if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
return((XVisualInfo *) NULL);
- ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
+ ThrowXWindowException(XServerWarning,"UsingDefaultVisual",
XVisualClassName(visual_list->klass));
}
resource_info->color_recovery=MagickFalse;
*/
root_window=XRootWindow(display,XDefaultScreen(display));
status=False;
+ number_maps=0;
if (LocaleCompare(map_type,"list") != 0)
{
/*
}
if (status == False)
{
- ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
+ ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
map_type);
return((XVisualInfo *) NULL);
}
}
if (map_info->visualid != visual_template.visualid)
{
- ThrowXWindowFatalException(XServerError,
+ ThrowXWindowException(XServerError,
"UnableToMatchVisualToStandardColormap",map_type);
return((XVisualInfo *) NULL);
}
#endif
if (map_info->colormap == (Colormap) NULL)
{
- ThrowXWindowFatalException(XServerError,
- "StandardColormapIsNotInitialized",map_type);
+ ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
+ map_type);
return((XVisualInfo *) NULL);
}
(void) XFree((void *) map_list);
property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
if (property == (Atom) NULL)
{
- ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
+ ThrowXWindowException(XServerError,"UnableToCreateProperty",
"_XSETROOT_ID");
return;
}
*/
(void) IdentifyImage(image,file,MagickTrue,exception);
(void) fclose(file);
- text=FileToString(filename,~0,exception);
+ text=FileToString(filename,~0UL,exception);
(void) RelinquishUniqueFileResource(filename);
if (text == (char *) NULL)
{
(green_map[i][j] == (unsigned char *) NULL) ||
(blue_map[i][j] == (unsigned char *) NULL))
{
- ThrowXWindowFatalException(ResourceLimitError,
- "MemoryAllocationFailed",image->filename);
+ ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+ image->filename);
return;
}
}
status=XParseColor(display,colormap,resource_info->foreground_color,
&pixel->foreground_color);
if (status == False)
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
resource_info->foreground_color);
pixel->foreground_color.pixel=
XStandardPixel(map_info,&pixel->foreground_color);
status=XParseColor(display,colormap,resource_info->background_color,
&pixel->background_color);
if (status == False)
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
resource_info->background_color);
pixel->background_color.pixel=
XStandardPixel(map_info,&pixel->background_color);
status=XParseColor(display,colormap,resource_info->border_color,
&pixel->border_color);
if (status == False)
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
resource_info->border_color);
pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
status=XParseColor(display,colormap,resource_info->matte_color,
&pixel->matte_color);
if (status == False)
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
resource_info->matte_color);
pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
status=XParseColor(display,colormap,resource_info->pen_colors[i],
&pixel->pen_colors[i]);
if (status == False)
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
resource_info->pen_colors[i]);
pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
if (LocaleCompare("shared",resource_value) == 0)
resource_info->colormap=SharedColormap;
if (resource_info->colormap == UndefinedColormap)
- ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
+ ThrowXWindowException(OptionError,"UnrecognizedColormapType",
resource_value);
resource_value=XGetResourceClass(database,client_name,
"colorRecovery",(char *) "False");
}
if (window_info == (WindowInfo *) NULL)
{
- ThrowXWindowFatalException(ResourceLimitError,
- "MemoryAllocationFailed","...");
+ ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed","...");
return((Image *) NULL);
}
id=number_windows++;
/*
Does target window intersect top level window?
*/
- import=
- ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
+ import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
(window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
(window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
(window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
(window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
(window_info[id].bounds.y1 >= window_info[j].bounds.y1) &&
(window_info[id].bounds.y2 <= window_info[j].bounds.y2))
- import=MagickFalse;
+ import=MagickFalse;
}
if (import == MagickFalse)
continue;
{
pixel=XGetPixel(ximage,x,y);
color=(pixel >> red_shift) & red_mask;
- color=(65535UL*color)/red_mask;
- SetPixelRed(composite_image,
- ScaleShortToQuantum((unsigned short) color),q);
+ if (red_mask != 0)
+ color=(65535UL*color)/red_mask;
+ SetPixelRed(composite_image,ScaleShortToQuantum(
+ (unsigned short) color),q);
color=(pixel >> green_shift) & green_mask;
- color=(65535UL*color)/green_mask;
- SetPixelGreen(composite_image,
- ScaleShortToQuantum((unsigned short) color),q);
+ if (green_mask != 0)
+ color=(65535UL*color)/green_mask;
+ SetPixelGreen(composite_image,ScaleShortToQuantum(
+ (unsigned short) color),q);
color=(pixel >> blue_shift) & blue_mask;
- color=(65535UL*color)/blue_mask;
- SetPixelBlue(composite_image,
- ScaleShortToQuantum((unsigned short) color),q);
+ if (blue_mask != 0)
+ color=(65535UL*color)/blue_mask;
+ SetPixelBlue(composite_image,ScaleShortToQuantum(
+ (unsigned short) color),q);
q+=GetPixelChannels(composite_image);
}
status=SyncCacheViewAuthenticPixels(composite_view,exception);
display=XOpenDisplay(image_info->server_name);
if (display == (Display *) NULL)
{
- ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
+ ThrowXWindowException(XServerError,"UnableToOpenXServer",
XDisplayName(image_info->server_name));
return((Image *) NULL);
}
/*
Select window by ID or name.
*/
- if (isdigit((unsigned char) *image_info->filename) != 0)
+ if (isdigit((int) ((unsigned char) *image_info->filename)) != 0)
target=XWindowByID(display,root,(Window)
strtol(image_info->filename,(char **) NULL,0));
if (target == (Window) NULL)
target=XWindowByName(display,root,image_info->filename);
if (target == (Window) NULL)
- ThrowXWindowFatalException(XServerError,
- "NoWindowWithSpecifiedIDExists",image_info->filename);
+ ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
+ image_info->filename);
}
}
/*
if (target == (Window) NULL)
target=XSelectWindow(display,&crop_info);
if (target == (Window) NULL)
- ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
+ ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
image_info->filename);
client=target; /* obsolete */
if (target != root)
status=XGetWindowAttributes(display,target,&window_attributes);
if (status == False)
{
- ThrowXWindowFatalException(XServerError,
- "UnableToReadXWindowAttributes",image_info->filename);
+ ThrowXWindowException(XServerError,"UnableToReadXWindowAttributes",
+ image_info->filename);
(void) XCloseDisplay(display);
return((Image *) NULL);
}
ximage_info->descend ? 1U : 0U,exception);
(void) XUngrabServer(display);
if (image == (Image *) NULL)
- ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
+ ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
image_info->filename)
else
{
windows->icon_map=XAllocStandardColormap();
if ((windows->map_info == (XStandardColormap *) NULL) ||
(windows->icon_map == (XStandardColormap *) NULL))
- ThrowXWindowFatalException(ResourceLimitFatalError,
- "MemoryAllocationFailed","...");
+ ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
+ "...");
windows->map_info->colormap=(Colormap) NULL;
windows->icon_map->colormap=(Colormap) NULL;
windows->pixel_info->pixels=(unsigned long *) NULL;
windows->manager_hints=XAllocWMHints();
if ((windows->class_hints == (XClassHint *) NULL) ||
(windows->manager_hints == (XWMHints *) NULL))
- ThrowXWindowFatalException(ResourceLimitFatalError,
- "MemoryAllocationFailed","...");
+ ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
+ "...");
/*
Determine group leader if we have one.
*/
windows->group_leader.id=(Window) NULL;
if (resource_info->window_group != (char *) NULL)
{
- if (isdigit((unsigned char) *resource_info->window_group) != 0)
+ if (isdigit((int) ((unsigned char) *resource_info->window_group)) != 0)
windows->group_leader.id=XWindowByID(display,root_window,(Window)
strtol((char *) resource_info->window_group,(char **) NULL,0));
if (windows->group_leader.id == (Window) NULL)
scope_width,scope_height);
if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
{
- ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
+ ThrowXWindowException(XServerError,"UnableToCreatePixmap","...");
return((Cursor) NULL);
}
(void) XParseColor(display,colormap,background_color,&background);
Resize image.
*/
resize_image=NewImageList();
- if (window->pixel_info->colors != 0)
- resize_image=SampleImage(window->image,width,height,exception);
+ if ((window->pixel_info->colors == 0) &&
+ (window->image->rows > (unsigned long) XDisplayHeight(display,window->screen)) &&
+ (window->image->columns > (unsigned long) XDisplayWidth(display,window->screen)))
+ resize_image=ResizeImage(window->image,width,height,
+ image->filter,exception);
else
- resize_image=ThumbnailImage(window->image,width,height,exception);
+ {
+ if (window->image->storage_class == PseudoClass)
+ resize_image=SampleImage(window->image,width,height,
+ exception);
+ else
+ resize_image=ThumbnailImage(window->image,width,height,
+ exception);
+ }
if (resize_image != (Image *) NULL)
{
if (window->image != image)
if (window->shared_memory == MagickFalse)
{
if (ximage->format != XYBitmap)
- ximage->data=(char *) AcquireQuantumMemory((size_t)
- ximage->bytes_per_line,(size_t) ximage->height);
+ ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
+ ximage->height);
else
- ximage->data=(char *) AcquireQuantumMemory((size_t)
- ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
+ ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
+ ximage->depth*ximage->height);
}
if (ximage->data == (char *) NULL)
{
/*
Allocate matte image pixel data.
*/
- matte_image->data=(char *) AcquireQuantumMemory((size_t)
- matte_image->bytes_per_line*matte_image->depth,
- (size_t) matte_image->height);
+ matte_image->data=(char *) malloc((size_t)
+ matte_image->bytes_per_line*matte_image->depth*
+ matte_image->height);
if (matte_image->data == (char *) NULL)
{
XDestroyImage(matte_image);
double
intensity;
- intensity=0.298839f*pixel->red+0.586811f*pixel->green+0.114350f*pixel->blue;
+ intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
return(intensity);
}
display=XOpenDisplay((char *) NULL);
if (display == (Display *) NULL)
{
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target);
return(MagickFalse);
}
colormap=XDefaultColormap(display,XDefaultScreen(display));
status=XParseColor(display,colormap,(char *) target,&xcolor);
if (status == False)
- ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
+ ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target)
else
{
color->red=xcolor.red;
/*
Search window hierarchy and identify any clients by name or ID.
*/
- if (isdigit((unsigned char) *window) != 0)
+ if (isdigit((int) ((unsigned char) *window)) != 0)
remote_window=XWindowByID(display,root_window,(Window)
strtol((char *) window,(char **) NULL,0));
if (remote_window == (Window) NULL)
visual_info=XBestVisualInfo(display,map_info,&resource_info);
if (visual_info == (XVisualInfo *) NULL)
{
- ThrowXWindowException(XServerError,"UnableToGetVisual",
- image->filename);
+ ThrowXWindowException(XServerError,"UnableToGetVisual",image->filename);
return(MagickFalse);
}
map_info->colormap=(Colormap) NULL;
property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
if (property == (Atom) NULL)
{
- ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
+ ThrowXWindowException(XServerError,"UnableToCreateProperty",
"_XSETROOT_ID");
return;
}
pixmap=XCreatePixmap(display,window,1,1,1);
if (pixmap == (Pixmap) NULL)
{
- ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
+ ThrowXWindowException(XServerError,"UnableToCreateBitmap","");
return;
}
(void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
GrabModeAsync,root_window,target_cursor,CurrentTime);
if (status != GrabSuccess)
{
- ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
+ ThrowXWindowException(XServerError,"UnableToGrabMouse","");
return((Window) NULL);
}
/*