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/color.h"
00046
#include "magick/constitute.h"
00047
#include "magick/draw.h"
00048
#include "magick/error.h"
00049
#include "magick/error_private.h"
00050
#include "magick/delegate.h"
00051
#include "magick/geometry.h"
00052
#include "magick/image.h"
00053
#include "magick/image_private.h"
00054
#include "magick/list.h"
00055
#include "magick/magick.h"
00056
#include "magick/memory_.h"
00057
#include "magick/monitor.h"
00058
#include "magick/quantize.h"
00059
#include "magick/resource_.h"
00060
#include "magick/static.h"
00061
#include "magick/string_.h"
00062
#include "magick/transform.h"
00063
#include "magick/utility.h"
00064
00065
00066
00067
00068 typedef struct _EPTInfo
00069 {
00070
unsigned long
00071 magick;
00072
00073
MagickOffsetType
00074 postscript_offset,
00075
tiff_offset;
00076
00077 size_t
00078 postscript_length,
00079
tiff_length;
00080
00081
unsigned char
00082 *
postscript,
00083 *
tiff;
00084 }
EPTInfo;
00085
00086
00087
00088
00089
static MagickBooleanType
00090
WriteEPTImage(
const ImageInfo *,
Image *);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 static MagickBooleanType IsEPT(
const unsigned char *magick,
const size_t length)
00120 {
00121
if (length < 4)
00122
return(
MagickFalse);
00123
if (memcmp(magick,
"\305\320\323\306",4) == 0)
00124
return(
MagickTrue);
00125
return(
MagickFalse);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 static Image *
ReadEPTImage(
const ImageInfo *image_info,
ExceptionInfo *
exception)
00157 {
00158
EPTInfo
00159 ept_info;
00160
00161
Image
00162 *image;
00163
00164
ImageInfo
00165 *read_info;
00166
00167
MagickBooleanType
00168 status;
00169
00170
00171
00172
00173
assert(image_info != (
const ImageInfo *) NULL);
00174
assert(image_info->
signature ==
MagickSignature);
00175
if (image_info->
debug !=
MagickFalse)
00176 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image_info->
filename);
00177
assert(exception != (
ExceptionInfo *) NULL);
00178
assert(exception->
signature ==
MagickSignature);
00179 image=
AllocateImage(image_info);
00180 status=
OpenBlob(image_info,image,
ReadBinaryBlobMode,exception);
00181
if (status ==
MagickFalse)
00182 {
00183
DestroyImageList(image);
00184
return((
Image *) NULL);
00185 }
00186 ept_info.
magick=
ReadBlobLSBLong(image);
00187
if (ept_info.
magick != 0xc6d3d0c5ul)
00188
ThrowReaderException(
CorruptImageError,
"ImproperImageHeader");
00189 ept_info.
postscript_offset=(
MagickOffsetType)
ReadBlobLSBLong(image);
00190 ept_info.
postscript_length=
ReadBlobLSBLong(image);
00191 (
void)
ReadBlobLSBLong(image);
00192 (
void)
ReadBlobLSBLong(image);
00193 ept_info.
tiff_offset=(
MagickOffsetType)
ReadBlobLSBLong(image);
00194 ept_info.
tiff_length=
ReadBlobLSBLong(image);
00195 (
void)
ReadBlobLSBShort(image);
00196 ept_info.
postscript=(
unsigned char *)
00197
AcquireMagickMemory(ept_info.
postscript_length);
00198 ept_info.
tiff=(
unsigned char *)
AcquireMagickMemory(ept_info.
tiff_length);
00199
if ((ept_info.
postscript == (
unsigned char *) NULL) ||
00200 (ept_info.
tiff == (
unsigned char *) NULL))
00201
ThrowReaderException(
ResourceLimitError,
"MemoryAllocationFailed");
00202 (
void)
SeekBlob(image,ept_info.
tiff_offset,SEEK_SET);
00203 (
void)
ReadBlob(image,ept_info.
tiff_length,ept_info.
tiff);
00204 (
void)
SeekBlob(image,ept_info.
postscript_offset,SEEK_SET);
00205 (
void)
ReadBlob(image,ept_info.
postscript_length,ept_info.
postscript);
00206
CloseBlob(image);
00207 image=
DestroyImage(image);
00208 read_info=
CloneImageInfo(image_info);
00209 (
void)
CopyMagickString(read_info->
magick,
"EPS",
MaxTextExtent);
00210 image=
BlobToImage(read_info,ept_info.
postscript,ept_info.
postscript_length,
00211 exception);
00212
if (image == (
Image *) NULL)
00213 {
00214 (
void)
CopyMagickString(read_info->
magick,
"TIFF",
MaxTextExtent);
00215 image=
BlobToImage(read_info,ept_info.
tiff,ept_info.
tiff_length,exception);
00216 }
00217 read_info=
DestroyImageInfo(read_info);
00218
if (image != (
Image *) NULL)
00219 (
void)
CopyMagickString(image->
filename,image_info->
filename,
MaxTextExtent);
00220 ept_info.
tiff=(
unsigned char *)
RelinquishMagickMemory(ept_info.
tiff);
00221 ept_info.
postscript=(
unsigned char *)
00222
RelinquishMagickMemory(ept_info.
postscript);
00223
return(image);
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 ModuleExport void RegisterEPTImage(
void)
00250 {
00251
MagickInfo
00252 *entry;
00253
00254 entry=
SetMagickInfo(
"EPT");
00255 entry->
decoder=(
DecoderHandler *)
ReadEPTImage;
00256 entry->
encoder=(
EncoderHandler *)
WriteEPTImage;
00257 entry->
magick=(
MagickHandler *)
IsEPT;
00258 entry->
adjoin=
MagickFalse;
00259 entry->
blob_support=
MagickFalse;
00260 entry->
description=
AcquireString(
"Encapsulated PostScript with TIFF preview");
00261 entry->
module=
AcquireString(
"EPT");
00262 (
void)
RegisterMagickInfo(entry);
00263 entry=
SetMagickInfo(
"EPT2");
00264 entry->
decoder=(
DecoderHandler *)
ReadEPTImage;
00265 entry->
encoder=(
EncoderHandler *)
WriteEPTImage;
00266 entry->
magick=(
MagickHandler *)
IsEPT;
00267 entry->
adjoin=
MagickFalse;
00268 entry->
blob_support=
MagickFalse;
00269 entry->
description=
00270
AcquireString(
"Encapsulated PostScript Level II with TIFF preview");
00271 entry->
module=
AcquireString(
"EPT");
00272 (
void)
RegisterMagickInfo(entry);
00273 entry=
SetMagickInfo(
"EPT3");
00274 entry->
decoder=(
DecoderHandler *)
ReadEPTImage;
00275 entry->
encoder=(
EncoderHandler *)
WriteEPTImage;
00276 entry->
magick=(
MagickHandler *)
IsEPT;
00277 entry->
blob_support=
MagickFalse;
00278 entry->
description=
00279
AcquireString(
"Encapsulated PostScript Level III with TIFF preview");
00280 entry->
module=
AcquireString(
"EPT");
00281 (
void)
RegisterMagickInfo(entry);
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 ModuleExport void UnregisterEPTImage(
void)
00304 {
00305 (
void)
UnregisterMagickInfo(
"EPT");
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 static MagickBooleanType WriteEPTImage(
const ImageInfo *image_info,
Image *image)
00335 {
00336
EPTInfo
00337 ept_info;
00338
00339
Image
00340 *write_image;
00341
00342
ImageInfo
00343 *write_info;
00344
00345
MagickBooleanType
00346 status;
00347
00348
00349
00350
00351
assert(image_info != (
const ImageInfo *) NULL);
00352
assert(image_info->
signature ==
MagickSignature);
00353
assert(image != (
Image *) NULL);
00354
assert(image->
signature ==
MagickSignature);
00355
if (image->
debug !=
MagickFalse)
00356 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image->
filename);
00357 status=
OpenBlob(image_info,image,
WriteBinaryBlobMode,&image->
exception);
00358
if (status ==
MagickFalse)
00359
return(status);
00360 write_image=
CloneImage(image,0,0,
MagickTrue,&image->
exception);
00361
if (write_image == (
Image *) NULL)
00362
return(
MagickFalse);
00363 write_info=
CloneImageInfo(image_info);
00364
DestroyBlob(write_image);
00365 write_image->
blob=
CloneBlobInfo((
BlobInfo *) NULL);
00366 (
void)
CopyMagickString(write_image->
magick,
"EPS",
MaxTextExtent);
00367
if (
LocaleCompare(image_info->
magick,
"EPT2") == 0)
00368 (
void)
CopyMagickString(write_image->
magick,
"EPS2",
MaxTextExtent);
00369
if (
LocaleCompare(image_info->
magick,
"EPT3") == 0)
00370 (
void)
CopyMagickString(write_image->
magick,
"EPS3",
MaxTextExtent);
00371 (
void)
ResetMagickMemory(&ept_info,0,
sizeof(ept_info));
00372 ept_info.magick=0xc6d3d0c5ul;
00373 ept_info.postscript=(
unsigned char *)
ImageToBlob(write_info,write_image,
00374 &ept_info.postscript_length,&image->
exception);
00375
if (ept_info.postscript == (
void *) NULL)
00376 {
00377 write_image=
DestroyImage(write_image);
00378 write_info=
DestroyImageInfo(write_info);
00379
return(
MagickFalse);
00380 }
00381
DestroyBlob(write_image);
00382 write_image->
blob=
CloneBlobInfo((
BlobInfo *) NULL);
00383 (
void)
CopyMagickString(write_image->
magick,
"TIFF",
MaxTextExtent);
00384 (
void)
TransformImage(&write_image,(
char *) NULL,
"512x512>");
00385
if ((write_image->
storage_class ==
DirectClass) ||
00386 (write_image->
colors > 256))
00387 {
00388
QuantizeInfo
00389 quantize_info;
00390
00391
00392
00393
00394
GetQuantizeInfo(&quantize_info);
00395 quantize_info.
dither=
00396
IsPaletteImage(write_image,&image->
exception) ==
MagickFalse;
00397 (
void)
QuantizeImage(&quantize_info,write_image);
00398 }
00399 write_image->
compression=
NoCompression;
00400 ept_info.tiff=(
unsigned char *)
ImageToBlob(write_info,write_image,
00401 &ept_info.tiff_length,&image->
exception);
00402 write_image=
DestroyImage(write_image);
00403 write_info=
DestroyImageInfo(write_info);
00404
if (ept_info.tiff == (
void *) NULL)
00405 {
00406 ept_info.postscript=(
unsigned char *)
00407
RelinquishMagickMemory(ept_info.postscript);
00408
return(
MagickFalse);
00409 }
00410
00411
00412
00413 (
void)
WriteBlobLSBLong(image,ept_info.
magick);
00414 (
void)
WriteBlobLSBLong(image,30);
00415 (
void)
WriteBlobLSBLong(image,ept_info.postscript_length);
00416 (
void)
WriteBlobLSBLong(image,0);
00417 (
void)
WriteBlobLSBLong(image,0);
00418 (
void)
WriteBlobLSBLong(image,ept_info.postscript_length+30);
00419 (
void)
WriteBlobLSBLong(image,ept_info.tiff_length);
00420 (
void)
WriteBlobLSBShort(image,0xffff);
00421 (
void)
WriteBlob(image,ept_info.postscript_length,ept_info.postscript);
00422 (
void)
WriteBlob(image,ept_info.tiff_length,ept_info.tiff);
00423
00424
00425
00426 ept_info.postscript=(
unsigned char *)
00427
RelinquishMagickMemory(ept_info.postscript);
00428 ept_info.tiff=(
unsigned char *)
RelinquishMagickMemory(ept_info.tiff);
00429
CloseBlob(image);
00430
return(
MagickTrue);
00431 }