00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
#include "magick/studio.h"
00043
#include "magick/blob.h"
00044
#include "magick/blob_private.h"
00045
#include "magick/client.h"
00046
#include "magick/error.h"
00047
#include "magick/error_private.h"
00048
#include "magick/image.h"
00049
#include "magick/image_private.h"
00050
#include "magick/list.h"
00051
#include "magick/magick.h"
00052
#include "magick/memory_.h"
00053
#include "magick/monitor.h"
00054
#include "magick/static.h"
00055
#include "magick/string_.h"
00056
#include "magick/utility.h"
00057
#include "magick/xwindow.h"
00058
#if defined(HasDPS)
00059
#include <DPS/dpsXclient.h>
00060
#include <DPS/dpsXpreview.h>
00061
#endif
00062
00063
#if defined(HasDPS)
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
static Image *ReadDPSImage(
const ImageInfo *image_info,
ExceptionInfo *
exception)
00092 {
00093 Display
00094 *display;
00095
00096
float
00097 pixels_per_point;
00098
00099
Image
00100 *image;
00101
00102
int
00103 sans,
00104 status;
00105
00106
long
00107 x,
00108 y;
00109
00110 Pixmap
00111 pixmap;
00112
00113
register IndexPacket
00114 *indexes;
00115
00116
register long
00117 i;
00118
00119
register PixelPacket
00120 *q;
00121
00122
register unsigned long
00123 pixel;
00124
00125 Screen
00126 *screen;
00127
00128 XColor
00129 *colors;
00130
00131 XImage
00132 *dps_image;
00133
00134 XRectangle
00135 page,
00136 bits_per_pixel;
00137
00138 XResourceInfo
00139 resource_info;
00140
00141 XrmDatabase
00142 resource_database;
00143
00144 XStandardColormap
00145 *map_info;
00146
00147 XVisualInfo
00148 *visual_info;
00149
00150
00151
00152
00153
assert(image_info != (
const ImageInfo *) NULL);
00154
assert(image_info->
signature == MagickSignature);
00155
if (image_info->
debug !=
MagickFalse)
00156 (
void)
LogMagickEvent(TraceEvent,
GetMagickModule(),image_info->
filename);
00157
assert(exception != (
ExceptionInfo *) NULL);
00158
assert(exception->
signature == MagickSignature);
00159 display=
XOpenDisplay(image_info->
server_name);
00160
if (display == (Display *) NULL)
00161
return((
Image *) NULL);
00162
00163
00164
00165 (
void)
XSetErrorHandler(XError);
00166
00167
00168
00169 image=
AllocateImage(image_info);
00170 status=
OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
00171
if (status ==
MagickFalse)
00172
return((
Image *) NULL);
00173
00174
00175
00176 resource_database=XGetResourceDatabase(display,
GetClientName());
00177 XGetResourceInfo(resource_database,
GetClientName(),&resource_info);
00178
00179
00180
00181 map_info=
XAllocStandardColormap();
00182 visual_info=(XVisualInfo *) NULL;
00183
if (map_info == (XStandardColormap *) NULL)
00184
ThrowReaderException(ResourceLimitError,
"UnableToCreateStandardColormap")
00185 else
00186 {
00187
00188
00189
00190 (
void)
CloneString(&resource_info.visual_type,
"default");
00191 visual_info=XBestVisualInfo(display,map_info,&resource_info);
00192 map_info->colormap=(Colormap) NULL;
00193 }
00194
if ((map_info == (XStandardColormap *) NULL) ||
00195 (visual_info == (XVisualInfo *) NULL))
00196 {
00197 image=
DestroyImage(image);
00198 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00199 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00200
return((
Image *) NULL);
00201 }
00202
00203
00204
00205 screen=ScreenOfDisplay(display,visual_info->screen);
00206 pixels_per_point=XDPSPixelsPerPoint(screen);
00207
if ((image->
x_resolution != 0.0) && (image->
y_resolution != 0.0))
00208 pixels_per_point=
Min(image->
x_resolution,image->
y_resolution)/72.0;
00209 status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
00210
GetBlobFileHandle(image),visual_info->depth,pixels_per_point,&pixmap,
00211 &bits_per_pixel,&page);
00212
if ((status == dps_status_failure) || (status == dps_status_no_extension))
00213 {
00214 image=
DestroyImage(image);
00215 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00216 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00217
return((
Image *) NULL);
00218 }
00219
00220
00221
00222 status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
00223
GetBlobFileHandle(image),bits_per_pixel.height,visual_info->depth,&page,
00224 -page.x,-page.y,pixels_per_point,MagickTrue,MagickFalse,MagickTrue,&sans);
00225
if (status != dps_status_success)
00226 {
00227 image=
DestroyImage(image);
00228 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00229 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00230
return((
Image *) NULL);
00231 }
00232
00233
00234
00235 dps_image=
XGetImage(display,pixmap,0,0,bits_per_pixel.width,
00236 bits_per_pixel.height,AllPlanes,ZPixmap);
00237 (
void)
XFreePixmap(display,pixmap);
00238
if (dps_image == (XImage *) NULL)
00239 {
00240 image=
DestroyImage(image);
00241 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00242 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00243
return((
Image *) NULL);
00244 }
00245
00246
00247
00248 colors=(XColor *)
00249
AcquireMagickMemory(visual_info->colormap_size*
sizeof(XColor));
00250
if (colors == (XColor *) NULL)
00251 {
00252 image=
DestroyImage(image);
00253 XDestroyImage(dps_image);
00254 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00255 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00256
return((
Image *) NULL);
00257 }
00258
if ((visual_info->storage_class != DirectColor) &&
00259 (visual_info->storage_class != TrueColor))
00260
for (i=0; i < visual_info->colormap_size; i++)
00261 {
00262 colors[i].pixel=i;
00263 colors[i].pad=0;
00264 }
00265
else
00266 {
00267
unsigned long
00268 blue,
00269 blue_bit,
00270 green,
00271 green_bit,
00272 red,
00273 red_bit;
00274
00275
00276
00277
00278 red=0;
00279 green=0;
00280 blue=0;
00281 red_bit=visual_info->red_mask & (~(visual_info->red_mask)+1);
00282 green_bit=visual_info->green_mask & (~(visual_info->green_mask)+1);
00283 blue_bit=visual_info->blue_mask & (~(visual_info->blue_mask)+1);
00284
for (i=0; i < visual_info->colormap_size; i++)
00285 {
00286 colors[i].pixel=red | green | blue;
00287 colors[i].pad=0;
00288 red+=red_bit;
00289
if (red > visual_info->red_mask)
00290 red=0;
00291 green+=green_bit;
00292
if (green > visual_info->green_mask)
00293 green=0;
00294 blue+=blue_bit;
00295
if (blue > visual_info->blue_mask)
00296 blue=0;
00297 }
00298 }
00299 (
void)
XQueryColors(display,
XDefaultColormap(display,visual_info->screen),
00300 colors,visual_info->colormap_size);
00301
00302
00303
00304
if ((visual_info->storage_class != TrueColor) &&
00305 (visual_info->storage_class != DirectColor))
00306 image->
storage_class=
PseudoClass;
00307 image->
columns=dps_image->width;
00308 image->
rows=dps_image->height;
00309
if (image_info->
ping !=
MagickFalse)
00310 {
00311
CloseBlob(image);
00312
return(
GetFirstImageInList(image));
00313 }
00314
switch (image->
storage_class)
00315 {
00316
case DirectClass:
00317
default:
00318 {
00319
register unsigned long
00320 color,
00321 index;
00322
00323
unsigned long
00324 blue_mask,
00325 blue_shift,
00326 green_mask,
00327 green_shift,
00328 red_mask,
00329 red_shift;
00330
00331
00332
00333
00334 red_mask=visual_info->red_mask;
00335 red_shift=0;
00336
while ((red_mask & 0x01) == 0)
00337 {
00338 red_mask>>=1;
00339 red_shift++;
00340 }
00341 green_mask=visual_info->green_mask;
00342 green_shift=0;
00343
while ((green_mask & 0x01) == 0)
00344 {
00345 green_mask>>=1;
00346 green_shift++;
00347 }
00348 blue_mask=visual_info->blue_mask;
00349 blue_shift=0;
00350
while ((blue_mask & 0x01) == 0)
00351 {
00352 blue_mask>>=1;
00353 blue_shift++;
00354 }
00355
00356
00357
00358
if ((visual_info->colormap_size > 0) &&
00359 (visual_info->storage_class == DirectColor))
00360
for (y=0; y < (
long) image->
rows; y++)
00361 {
00362 q=
SetImagePixels(image,0,y,image->
columns,1);
00363
if (q == (
PixelPacket *) NULL)
00364
break;
00365
for (x=0; x < (
long) image->
columns; x++)
00366 {
00367 pixel=XGetPixel(dps_image,x,y);
00368 index=(pixel >> red_shift) & red_mask;
00369 q->
red=
ScaleShortToQuantum(colors[index].red);
00370 index=(pixel >> green_shift) & green_mask;
00371 q->
green=
ScaleShortToQuantum(colors[index].green);
00372 index=(pixel >> blue_shift) & blue_mask;
00373 q->
blue=
ScaleShortToQuantum(colors[index].blue);
00374 q++;
00375 }
00376
if (
SyncImagePixels(image) ==
MagickFalse)
00377
break;
00378
if ((image->
progress_monitor != (
MagickProgressMonitor) NULL) &&
00379 (
QuantumTick(y,image->
rows) !=
MagickFalse))
00380 {
00381 status=image->
progress_monitor(LoadImageTag,y,image->
rows,
00382 image->
client_data);
00383
if (status ==
MagickFalse)
00384
break;
00385 }
00386 }
00387
else
00388
for (y=0; y < (
long) image->
rows; y++)
00389 {
00390 q=
SetImagePixels(image,0,y,image->
columns,1);
00391
if (q == (
PixelPacket *) NULL)
00392
break;
00393
for (x=0; x < (
long) image->
columns; x++)
00394 {
00395 pixel=XGetPixel(dps_image,x,y);
00396 color=(pixel >> red_shift) & red_mask;
00397 q->
red=
ScaleShortToQuantum((color*65535L)/red_mask);
00398 color=(pixel >> green_shift) & green_mask;
00399 q->
green=
ScaleShortToQuantum((color*65535L)/green_mask);
00400 color=(pixel >> blue_shift) & blue_mask;
00401 q->
blue=
ScaleShortToQuantum((color*65535L)/blue_mask);
00402 q++;
00403 }
00404
if (
SyncImagePixels(image) ==
MagickFalse)
00405
break;
00406
if ((image->
progress_monitor != (
MagickProgressMonitor) NULL) &&
00407 (
QuantumTick(y,image->
rows) !=
MagickFalse))
00408 {
00409 status=image->
progress_monitor(LoadImageTag,y,image->
rows,
00410 image->
client_data);
00411
if (status ==
MagickFalse)
00412
break;
00413 }
00414 }
00415
break;
00416 }
00417
case PseudoClass:
00418 {
00419
00420
00421
00422
if (
AllocateImageColormap(image,visual_info->colormap_size) ==
MagickFalse)
00423 {
00424 image=
DestroyImage(image);
00425 colors=(XColor *)
RelinquishMagickMemory(colors);
00426 XDestroyImage(dps_image);
00427 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00428 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00429
return((
Image *) NULL);
00430 }
00431
for (i=0; i < (
long) image->
colors; i++)
00432 {
00433 image->
colormap[colors[i].pixel].
red=
ScaleShortToQuantum(colors[i].red);
00434 image->
colormap[colors[i].pixel].
green=
00435
ScaleShortToQuantum(colors[i].green);
00436 image->
colormap[colors[i].pixel].
blue=
00437
ScaleShortToQuantum(colors[i].blue);
00438 }
00439
00440
00441
00442
for (y=0; y < (
long) image->
rows; y++)
00443 {
00444 q=
SetImagePixels(image,0,y,image->
columns,1);
00445
if (q == (
PixelPacket *) NULL)
00446
break;
00447 indexes=
GetIndexes(image);
00448
for (x=0; x < (
long) image->
columns; x++)
00449 indexes[x]=(
unsigned short) XGetPixel(dps_image,x,y);
00450
if (
SyncImagePixels(image) ==
MagickFalse)
00451
break;
00452
if ((image->
progress_monitor != (
MagickProgressMonitor) NULL) &&
00453 (
QuantumTick(y,image->
rows) !=
MagickFalse))
00454 {
00455 status=image->
progress_monitor(LoadImageTag,y,image->
rows,
00456 image->
client_data);
00457
if (status ==
MagickFalse)
00458
break;
00459 }
00460 }
00461
break;
00462 }
00463 }
00464 colors=(XColor *)
RelinquishMagickMemory(colors);
00465 XDestroyImage(dps_image);
00466
if (image->
storage_class ==
PseudoClass)
00467 (
void)
SyncImage(image);
00468
00469
00470
00471 status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
00472
GetBlobFileHandle(image),1,pixels_per_point,&pixmap,&bits_per_pixel,&page);
00473
if ((status != dps_status_failure) && (status != dps_status_no_extension))
00474 {
00475 status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
00476
GetBlobFileHandle(image),bits_per_pixel.height,1,&page,-page.x,
00477 -page.y,pixels_per_point,MagickTrue,MagickTrue,MagickTrue,&sans);
00478
if (status == dps_status_success)
00479 {
00480 XImage
00481 *matte_image;
00482
00483
00484
00485
00486 matte_image=
XGetImage(display,pixmap,0,0,bits_per_pixel.width,
00487 bits_per_pixel.height,AllPlanes,ZPixmap);
00488 (
void)
XFreePixmap(display,pixmap);
00489
if (matte_image != (XImage *) NULL)
00490 {
00491 image->
storage_class=
DirectClass;
00492 image->
matte=
MagickTrue;
00493
for (y=0; y < (
long) image->
rows; y++)
00494 {
00495 q=
SetImagePixels(image,0,y,image->
columns,1);
00496
if (q == (
PixelPacket *) NULL)
00497
break;
00498
for (x=0; x < (
long) image->
columns; x++)
00499 {
00500 q->
opacity=
OpaqueOpacity;
00501
if (XGetPixel(matte_image,x,y) == 0)
00502 q->
opacity=
TransparentOpacity;
00503 q++;
00504 }
00505
if (
SyncImagePixels(image) ==
MagickFalse)
00506
break;
00507 }
00508 XDestroyImage(matte_image);
00509 }
00510 }
00511 }
00512
00513
00514
00515 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
00516 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
00517
CloseBlob(image);
00518
return(
GetFirstImageInList(image));
00519 }
00520
#endif
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 ModuleExport void RegisterDPSImage(
void)
00546 {
00547
MagickInfo
00548 *entry;
00549
00550 entry=
SetMagickInfo(
"DPS");
00551
#if defined(HasDPS)
00552
entry->
decoder=(
DecoderHandler *) ReadDPSImage;
00553
#endif
00554
entry->
blob_support=
MagickFalse;
00555 entry->
description=
AcquireString(
"Display Postscript Interpreter");
00556 entry->
module=
AcquireString(
"DPS");
00557 (
void)
RegisterMagickInfo(entry);
00558 }
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579 ModuleExport void UnregisterDPSImage(
void)
00580 {
00581 (
void)
UnregisterMagickInfo(
"DPS");
00582 }