This source file includes following definitions.
- ReadDPSImage
- RegisterDPSImage
- UnregisterDPSImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/client.h"
#include "magick/colormap.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
#include "magick/xwindow-private.h"
#if defined(MAGICKCORE_DPS_DELEGATE)
#include <DPS/dpsXclient.h>
#include <DPS/dpsXpreview.h>
#endif
#if defined(MAGICKCORE_DPS_DELEGATE)
static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
const char
*client_name;
Display
*display;
float
pixels_per_point;
Image
*image;
int
sans,
status;
Pixmap
pixmap;
register IndexPacket
*indexes;
register ssize_t
i;
register PixelPacket
*q;
register size_t
pixel;
Screen
*screen;
ssize_t
x,
y;
XColor
*colors;
XImage
*dps_image;
XRectangle
page,
bits_per_pixel;
XResourceInfo
resource_info;
XrmDatabase
resource_database;
XStandardColormap
*map_info;
XVisualInfo
*visual_info;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
display=XOpenDisplay(image_info->server_name);
if (display == (Display *) NULL)
return((Image *) NULL);
(void) XSetErrorHandler(XError);
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
return((Image *) NULL);
client_name=GetClientName();
resource_database=XGetResourceDatabase(display,client_name);
XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
map_info=XAllocStandardColormap();
visual_info=(XVisualInfo *) NULL;
if (map_info == (XStandardColormap *) NULL)
ThrowReaderException(ResourceLimitError,"UnableToCreateStandardColormap")
else
{
(void) CloneString(&resource_info.visual_type,"default");
visual_info=XBestVisualInfo(display,map_info,&resource_info);
map_info->colormap=(Colormap) NULL;
}
if ((map_info == (XStandardColormap *) NULL) ||
(visual_info == (XVisualInfo *) NULL))
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
screen=ScreenOfDisplay(display,visual_info->screen);
pixels_per_point=XDPSPixelsPerPoint(screen);
if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
pixels_per_point=MagickMin(image->x_resolution,image->y_resolution)/
DefaultResolution;
status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
GetBlobFileHandle(image),visual_info->depth,pixels_per_point,&pixmap,
&bits_per_pixel,&page);
if ((status == dps_status_failure) || (status == dps_status_no_extension))
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
GetBlobFileHandle(image),(int) bits_per_pixel.height,visual_info->depth,
&page,-page.x,-page.y,pixels_per_point,MagickTrue,MagickFalse,MagickTrue,
&sans);
if (status != dps_status_success)
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
dps_image=XGetImage(display,pixmap,0,0,bits_per_pixel.width,
bits_per_pixel.height,AllPlanes,ZPixmap);
(void) XFreePixmap(display,pixmap);
if (dps_image == (XImage *) NULL)
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
colors=(XColor *) AcquireQuantumMemory(visual_info->colormap_size,
sizeof(*colors));
if (colors == (XColor *) NULL)
{
image=DestroyImage(image);
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
if ((visual_info->klass != DirectColor) && (visual_info->klass != TrueColor))
for (i=0; i < visual_info->colormap_size; i++)
{
colors[i].pixel=(size_t) i;
colors[i].pad=0;
}
else
{
size_t
blue,
blue_bit,
green,
green_bit,
red,
red_bit;
red=0;
green=0;
blue=0;
red_bit=visual_info->red_mask & (~(visual_info->red_mask)+1);
green_bit=visual_info->green_mask & (~(visual_info->green_mask)+1);
blue_bit=visual_info->blue_mask & (~(visual_info->blue_mask)+1);
for (i=0; i < visual_info->colormap_size; i++)
{
colors[i].pixel=red | green | blue;
colors[i].pad=0;
red+=red_bit;
if (red > visual_info->red_mask)
red=0;
green+=green_bit;
if (green > visual_info->green_mask)
green=0;
blue+=blue_bit;
if (blue > visual_info->blue_mask)
blue=0;
}
}
(void) XQueryColors(display,XDefaultColormap(display,visual_info->screen),
colors,visual_info->colormap_size);
if ((visual_info->klass != TrueColor) && (visual_info->klass != DirectColor))
image->storage_class=PseudoClass;
image->columns=(size_t) dps_image->width;
image->rows=(size_t) dps_image->height;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
switch (image->storage_class)
{
case DirectClass:
default:
{
register size_t
color,
index;
size_t
blue_mask,
blue_shift,
green_mask,
green_shift,
red_mask,
red_shift;
red_mask=visual_info->red_mask;
red_shift=0;
while ((red_mask != 0) && ((red_mask & 0x01) == 0))
{
red_mask>>=1;
red_shift++;
}
green_mask=visual_info->green_mask;
green_shift=0;
while ((green_mask != 0) && ((green_mask & 0x01) == 0))
{
green_mask>>=1;
green_shift++;
}
blue_mask=visual_info->blue_mask;
blue_shift=0;
while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
{
blue_mask>>=1;
blue_shift++;
}
if ((visual_info->colormap_size > 0) &&
(visual_info->klass == DirectColor))
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
pixel=XGetPixel(dps_image,x,y);
index=(pixel >> red_shift) & red_mask;
SetPixelRed(q,ScaleShortToQuantum(colors[index].red));
index=(pixel >> green_shift) & green_mask;
SetPixelGreen(q,ScaleShortToQuantum(colors[index].green));
index=(pixel >> blue_shift) & blue_mask;
SetPixelBlue(q,ScaleShortToQuantum(colors[index].blue));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
else
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
pixel=XGetPixel(dps_image,x,y);
color=(pixel >> red_shift) & red_mask;
color=(color*65535L)/red_mask;
SetPixelRed(q,ScaleShortToQuantum((unsigned short) color));
color=(pixel >> green_shift) & green_mask;
color=(color*65535L)/green_mask;
SetPixelGreen(q,ScaleShortToQuantum((unsigned short)
color));
color=(pixel >> blue_shift) & blue_mask;
color=(color*65535L)/blue_mask;
SetPixelBlue(q,ScaleShortToQuantum((unsigned short)
color));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
break;
}
case PseudoClass:
{
if (AcquireImageColormap(image,(size_t) visual_info->colormap_size) == MagickFalse)
{
image=DestroyImage(image);
colors=(XColor *) RelinquishMagickMemory(colors);
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[colors[i].pixel].red=ScaleShortToQuantum(colors[i].red);
image->colormap[colors[i].pixel].green=
ScaleShortToQuantum(colors[i].green);
image->colormap[colors[i].pixel].blue=
ScaleShortToQuantum(colors[i].blue);
}
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
SetPixelIndex(indexes+x,(unsigned short)
XGetPixel(dps_image,x,y));
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
break;
}
}
colors=(XColor *) RelinquishMagickMemory(colors);
XDestroyImage(dps_image);
if (image->storage_class == PseudoClass)
(void) SyncImage(image);
status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
GetBlobFileHandle(image),1,pixels_per_point,&pixmap,&bits_per_pixel,&page);
if ((status != dps_status_failure) && (status != dps_status_no_extension))
{
status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
GetBlobFileHandle(image),(int) bits_per_pixel.height,1,&page,-page.x,
-page.y,pixels_per_point,MagickTrue,MagickTrue,MagickTrue,&sans);
if (status == dps_status_success)
{
XImage
*matte_image;
matte_image=XGetImage(display,pixmap,0,0,bits_per_pixel.width,
bits_per_pixel.height,AllPlanes,ZPixmap);
(void) XFreePixmap(display,pixmap);
if (matte_image != (XImage *) NULL)
{
image->storage_class=DirectClass;
image->matte=MagickTrue;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelOpacity(q,OpaqueOpacity);
if (XGetPixel(matte_image,x,y) == 0)
SetPixelOpacity(q,TransparentOpacity);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
XDestroyImage(matte_image);
}
}
}
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
#endif
ModuleExport size_t RegisterDPSImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("DPS");
#if defined(MAGICKCORE_DPS_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadDPSImage;
#endif
entry->blob_support=MagickFalse;
entry->description=ConstantString("Display Postscript Interpreter");
entry->module=ConstantString("DPS");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterDPSImage(void)
{
(void) UnregisterMagickInfo("DPS");
}