blob: d6066595ce7d343d036156d0046087b73df489db [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% PPPP SSSSS 33333 %
7% P P SS 33 %
8% PPPP SSS 333 %
9% P SS 33 %
10% P SSSSS 33333 %
11% %
12% %
13% Write Postscript Level III Format %
14% %
15% Software Design %
16% John Cristy %
17% Lars Ruben Skyum %
18% July 1992 %
19% %
20% %
cristy45ef08f2012-12-07 13:13:34 +000021% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000022% dedicated to making software imaging solutions freely available. %
23% %
24% You may not use this file except in compliance with the License. You may %
25% obtain a copy of the License at %
26% %
27% http://www.imagemagick.org/script/license.php %
28% %
29% Unless required by applicable law or agreed to in writing, software %
30% distributed under the License is distributed on an "AS IS" BASIS, %
31% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32% See the License for the specific language governing permissions and %
33% limitations under the License. %
34% %
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/attribute.h"
45#include "MagickCore/blob.h"
46#include "MagickCore/blob-private.h"
47#include "MagickCore/cache.h"
cristy500d6b92012-03-05 19:12:49 +000048#include "MagickCore/channel.h"
cristy4c08aed2011-07-01 19:47:50 +000049#include "MagickCore/color.h"
50#include "MagickCore/color-private.h"
51#include "MagickCore/compress.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/draw.h"
54#include "MagickCore/exception.h"
55#include "MagickCore/exception-private.h"
56#include "MagickCore/geometry.h"
57#include "MagickCore/image.h"
58#include "MagickCore/image-private.h"
59#include "MagickCore/list.h"
60#include "MagickCore/magick.h"
61#include "MagickCore/memory_.h"
62#include "MagickCore/monitor.h"
63#include "MagickCore/monitor-private.h"
64#include "MagickCore/option.h"
65#include "MagickCore/pixel-accessor.h"
66#include "MagickCore/property.h"
67#include "MagickCore/quantum-private.h"
68#include "MagickCore/resource_.h"
69#include "MagickCore/static.h"
70#include "MagickCore/string_.h"
71#include "MagickCore/module.h"
72#include "MagickCore/token.h"
73#include "MagickCore/utility.h"
74#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000075
76/*
77 Define declarations.
78*/
79#define PS3_NoCompression "0"
80#define PS3_FaxCompression "1"
81#define PS3_JPEGCompression "2"
82#define PS3_LZWCompression "3"
83#define PS3_RLECompression "4"
84#define PS3_ZipCompression "5"
85
86#define PS3_RGBColorspace "0"
87#define PS3_CMYKColorspace "1"
88
89#define PS3_DirectClass "0"
90#define PS3_PseudoClass "1"
cristy80975862009-09-25 14:34:31 +000091
92#if defined(MAGICKCORE_TIFF_DELEGATE)
cristy80975862009-09-25 14:34:31 +000093#define CCITTParam "-1"
94#else
95#define CCITTParam "0"
96#endif
cristy3ed852e2009-09-05 21:47:34 +000097
98/*
99 Forward declarations.
100*/
101static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +0000102 WritePS3Image(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000103
104/*
105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106% %
107% %
108% %
109% R e g i s t e r P S 3 I m a g e %
110% %
111% %
112% %
113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114%
115% RegisterPS3Image() adds properties for the PS3 image format to the list of
116% supported formats. The properties include the image format tag, a method to
117% read and/or write the format, whether the format supports the saving of more
118% than one frame to the same file or blob, whether the format supports native
119% in-memory I/O, and a brief description of the format.
120%
121% The format of the RegisterPS3Image method is:
122%
cristybb503372010-05-27 20:51:26 +0000123% size_t RegisterPS3Image(void)
cristy3ed852e2009-09-05 21:47:34 +0000124%
125*/
cristybb503372010-05-27 20:51:26 +0000126ModuleExport size_t RegisterPS3Image(void)
cristy3ed852e2009-09-05 21:47:34 +0000127{
128 MagickInfo
129 *entry;
130
131 entry=SetMagickInfo("EPS3");
132 entry->encoder=(EncodeImageHandler *) WritePS3Image;
133 entry->description=ConstantString("Level III Encapsulated PostScript");
134 entry->module=ConstantString("PS3");
cristyffaf9782011-04-13 19:50:51 +0000135 entry->seekable_stream=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +0000136 (void) RegisterMagickInfo(entry);
137 entry=SetMagickInfo("PS3");
138 entry->encoder=(EncodeImageHandler *) WritePS3Image;
139 entry->description=ConstantString("Level III PostScript");
140 entry->module=ConstantString("PS3");
cristyffaf9782011-04-13 19:50:51 +0000141 entry->seekable_stream=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +0000142 (void) RegisterMagickInfo(entry);
143 return(MagickImageCoderSignature);
144}
145
146/*
147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148% %
149% %
150% %
151% U n r e g i s t e r P S 3 I m a g e %
152% %
153% %
154% %
155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156%
157% UnregisterPS3Image() removes format registrations made by the PS3 module
158% from the list of supported formats.
159%
160% The format of the UnregisterPS3Image method is:
161%
162% UnregisterPS3Image(void)
163%
164*/
165ModuleExport void UnregisterPS3Image(void)
166{
167 (void) UnregisterMagickInfo("EPS3");
168 (void) UnregisterMagickInfo("PS3");
169}
170
171/*
172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173% %
174% %
175% %
176% W r i t e P S 3 I m a g e %
177% %
178% %
179% %
180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181%
182% WritePS3Image() translates an image to encapsulated Postscript Level III
183% for printing. If the supplied geometry is null, the image is centered on
184% the Postscript page. Otherwise, the image is positioned as specified by the
185% geometry.
186%
187% The format of the WritePS3Image method is:
188%
cristy1e178e72011-08-28 19:44:34 +0000189% MagickBooleanType WritePS3Image(const ImageInfo *image_info,
190% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000191%
192% A description of each parameter follows:
193%
194% o image_info: Specifies a pointer to a ImageInfo structure.
195%
196% o image: the image.
197%
cristy1e178e72011-08-28 19:44:34 +0000198% o exception: return any errors or warnings in this structure.
199%
cristy3ed852e2009-09-05 21:47:34 +0000200*/
201
cristy47b838c2009-09-19 16:09:30 +0000202static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info,
cristy018f07f2011-09-04 21:15:19 +0000203 Image *image,Image *inject_image,ExceptionInfo *exception)
cristy47b838c2009-09-19 16:09:30 +0000204{
cristy47b838c2009-09-19 16:09:30 +0000205 Image
cristy80975862009-09-25 14:34:31 +0000206 *group4_image;
cristy47b838c2009-09-19 16:09:30 +0000207
208 ImageInfo
209 *write_info;
210
cristy47b838c2009-09-19 16:09:30 +0000211 MagickBooleanType
212 status;
213
cristy80975862009-09-25 14:34:31 +0000214 size_t
215 length;
cristy47b838c2009-09-19 16:09:30 +0000216
217 unsigned char
cristy80975862009-09-25 14:34:31 +0000218 *group4;
cristy47b838c2009-09-19 16:09:30 +0000219
cristy42751fe2009-10-05 00:15:50 +0000220 status=MagickTrue;
cristy47b838c2009-09-19 16:09:30 +0000221 write_info=CloneImageInfo(image_info);
cristy80975862009-09-25 14:34:31 +0000222 (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent);
223 (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent);
cristy018f07f2011-09-04 21:15:19 +0000224 group4_image=CloneImage(inject_image,0,0,MagickTrue,exception);
cristy80975862009-09-25 14:34:31 +0000225 if (group4_image == (Image *) NULL)
226 return(MagickFalse);
227 group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length,
cristy018f07f2011-09-04 21:15:19 +0000228 exception);
cristy80975862009-09-25 14:34:31 +0000229 group4_image=DestroyImage(group4_image);
230 if (group4 == (unsigned char *) NULL)
231 return(MagickFalse);
cristy47b838c2009-09-19 16:09:30 +0000232 write_info=DestroyImageInfo(write_info);
cristy80975862009-09-25 14:34:31 +0000233 if (WriteBlob(image,length,group4) != (ssize_t) length)
234 status=MagickFalse;
235 group4=(unsigned char *) RelinquishMagickMemory(group4);
236 return(status);
cristy47b838c2009-09-19 16:09:30 +0000237}
cristy80975862009-09-25 14:34:31 +0000238
cristy3ed852e2009-09-05 21:47:34 +0000239static MagickBooleanType SerializeImage(const ImageInfo *image_info,
cristy018f07f2011-09-04 21:15:19 +0000240 Image *image,unsigned char **pixels,size_t *length,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000241{
cristy3ed852e2009-09-05 21:47:34 +0000242 MagickBooleanType
243 status;
244
cristy4c08aed2011-07-01 19:47:50 +0000245 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000246 *p;
247
cristybb503372010-05-27 20:51:26 +0000248 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000249 x;
250
251 register unsigned char
252 *q;
253
cristy802d3642011-04-27 02:02:41 +0000254 ssize_t
255 y;
256
cristy3ed852e2009-09-05 21:47:34 +0000257 assert(image != (Image *) NULL);
258 assert(image->signature == MagickSignature);
259 if (image->debug != MagickFalse)
260 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
261 status=MagickTrue;
cristy802d3642011-04-27 02:02:41 +0000262 *length=(image->colorspace == CMYKColorspace ? 4 : 3)*(size_t)
263 image->columns*image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000264 *pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels));
265 if (*pixels == (unsigned char *) NULL)
266 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
267 q=(*pixels);
cristybb503372010-05-27 20:51:26 +0000268 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000269 {
cristyc82a27b2011-10-21 01:07:16 +0000270 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000271 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000272 break;
cristy3ed852e2009-09-05 21:47:34 +0000273 if (image->colorspace != CMYKColorspace)
cristybb503372010-05-27 20:51:26 +0000274 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000275 {
cristy4c08aed2011-07-01 19:47:50 +0000276 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
277 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
278 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000279 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000280 }
281 else
cristybb503372010-05-27 20:51:26 +0000282 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000283 {
cristy4c08aed2011-07-01 19:47:50 +0000284 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
285 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
286 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
287 *q++=ScaleQuantumToChar(GetPixelBlack(image,p));
cristyed231572011-07-14 02:18:59 +0000288 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000289 }
290 if (image->previous == (Image *) NULL)
291 {
cristycee97112010-05-28 00:44:52 +0000292 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy802d3642011-04-27 02:02:41 +0000293 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000294 if (status == MagickFalse)
295 break;
296 }
297 }
298 if (status == MagickFalse)
299 *pixels=(unsigned char *) RelinquishMagickMemory(*pixels);
300 return(status);
301}
302
303static MagickBooleanType SerializeImageChannel(const ImageInfo *image_info,
cristy018f07f2011-09-04 21:15:19 +0000304 Image *image,unsigned char **pixels,size_t *length,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000305{
cristy3ed852e2009-09-05 21:47:34 +0000306 MagickBooleanType
307 status;
308
cristy4c08aed2011-07-01 19:47:50 +0000309 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000310 *p;
311
cristybb503372010-05-27 20:51:26 +0000312 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000313 x;
314
315 register unsigned char
316 *q;
317
cristybb503372010-05-27 20:51:26 +0000318 size_t
cristy3ed852e2009-09-05 21:47:34 +0000319 pack,
320 padded_columns;
321
cristy802d3642011-04-27 02:02:41 +0000322 ssize_t
323 y;
324
325 unsigned char
326 code,
327 bit;
328
cristy3ed852e2009-09-05 21:47:34 +0000329 assert(image != (Image *) NULL);
330 assert(image->signature == MagickSignature);
331 if (image->debug != MagickFalse)
332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
333 status=MagickTrue;
cristyc82a27b2011-10-21 01:07:16 +0000334 pack=IsImageMonochrome(image,exception) == MagickFalse ? 1UL : 8UL;
cristy3ed852e2009-09-05 21:47:34 +0000335 padded_columns=((image->columns+pack-1)/pack)*pack;
336 *length=(size_t) padded_columns*image->rows/pack;
337 *pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels));
338 if (*pixels == (unsigned char *) NULL)
339 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
340 q=(*pixels);
cristybb503372010-05-27 20:51:26 +0000341 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000342 {
cristy018f07f2011-09-04 21:15:19 +0000343 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000344 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000345 break;
346 if (pack == 1)
cristybb503372010-05-27 20:51:26 +0000347 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000348 {
cristy4c08aed2011-07-01 19:47:50 +0000349 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000350 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000351 }
352 else
353 {
354 code='\0';
cristybb503372010-05-27 20:51:26 +0000355 for (x=0; x < (ssize_t) padded_columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000356 {
357 bit=(unsigned char) 0x00;
cristybb503372010-05-27 20:51:26 +0000358 if (x < (ssize_t) image->columns)
cristy4c08aed2011-07-01 19:47:50 +0000359 bit=(unsigned char) (GetPixelIntensity(image,p) == (Quantum)
360 TransparentAlpha ? 0x01 : 0x00);
cristy3ed852e2009-09-05 21:47:34 +0000361 code=(code << 1)+bit;
362 if (((x+1) % pack) == 0)
363 {
364 *q++=code;
365 code='\0';
366 }
cristyed231572011-07-14 02:18:59 +0000367 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000368 }
369 }
cristycee97112010-05-28 00:44:52 +0000370 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy802d3642011-04-27 02:02:41 +0000371 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000372 if (status == MagickFalse)
373 break;
374 }
375 if (status == MagickFalse)
376 *pixels=(unsigned char *) RelinquishMagickMemory(*pixels);
377 return(status);
378}
379
380static MagickBooleanType SerializeImageIndexes(const ImageInfo *image_info,
cristy018f07f2011-09-04 21:15:19 +0000381 Image *image,unsigned char **pixels,size_t *length,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000382{
cristy3ed852e2009-09-05 21:47:34 +0000383 MagickBooleanType
384 status;
385
cristy4c08aed2011-07-01 19:47:50 +0000386 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000387 *p;
388
cristybb503372010-05-27 20:51:26 +0000389 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000390 x;
391
392 register unsigned char
393 *q;
394
cristy802d3642011-04-27 02:02:41 +0000395 ssize_t
396 y;
397
cristy3ed852e2009-09-05 21:47:34 +0000398 assert(image != (Image *) NULL);
399 assert(image->signature == MagickSignature);
400 if (image->debug != MagickFalse)
401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
402 status=MagickTrue;
403 *length=(size_t) image->columns*image->rows;
404 *pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels));
405 if (*pixels == (unsigned char *) NULL)
406 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
407 q=(*pixels);
cristybb503372010-05-27 20:51:26 +0000408 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000409 {
cristy018f07f2011-09-04 21:15:19 +0000410 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000411 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000412 break;
cristybb503372010-05-27 20:51:26 +0000413 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +0000414 {
415 *q++=(unsigned char) GetPixelIndex(image,p);
cristyed231572011-07-14 02:18:59 +0000416 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000417 }
cristy3ed852e2009-09-05 21:47:34 +0000418 if (image->previous == (Image *) NULL)
419 {
cristycee97112010-05-28 00:44:52 +0000420 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy802d3642011-04-27 02:02:41 +0000421 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000422 if (status == MagickFalse)
423 break;
424 }
425 }
426 if (status == MagickFalse)
427 *pixels=(unsigned char *) RelinquishMagickMemory(*pixels);
428 return(status);
429}
430
431static MagickBooleanType WritePS3MaskImage(const ImageInfo *image_info,
cristy018f07f2011-09-04 21:15:19 +0000432 Image *image,const CompressionType compression,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000433{
434 char
435 buffer[MaxTextExtent];
436
437 Image
438 *mask_image;
439
440 MagickBooleanType
441 status;
442
443 MagickOffsetType
444 offset,
445 start,
446 stop;
447
cristybb503372010-05-27 20:51:26 +0000448 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000449 i;
450
451 size_t
452 length;
453
454 unsigned char
455 *pixels;
456
457 assert(image_info != (ImageInfo *) NULL);
458 assert(image_info->signature == MagickSignature);
459 assert(image != (Image *) NULL);
460 assert(image->signature == MagickSignature);
461 if (image->debug != MagickFalse)
462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy8a46d822012-08-28 23:32:39 +0000463 assert(image->alpha_trait == BlendPixelTrait);
cristy3ed852e2009-09-05 21:47:34 +0000464 status=MagickTrue;
465 /*
466 Note BeginData DSC comment for update later.
467 */
468 start=TellBlob(image);
cristyb51dff52011-05-19 16:55:47 +0000469 (void) FormatLocaleString(buffer,MaxTextExtent,
cristy802d3642011-04-27 02:02:41 +0000470 "%%%%BeginData:%13ld %s Bytes\n",0L,compression == NoCompression ?
471 "ASCII" : "BINARY");
cristy3ed852e2009-09-05 21:47:34 +0000472 (void) WriteBlobString(image,buffer);
473 stop=TellBlob(image);
474 /*
475 Only lossless compressions for the mask.
476 */
477 switch (compression)
478 {
479 case NoCompression:
480 default:
481 {
cristyb51dff52011-05-19 16:55:47 +0000482 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +0000483 "currentfile %.20g %.20g "PS3_NoCompression" ByteStreamDecodeFilter\n",
484 (double) image->columns,(double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000485 break;
486 }
487 case FaxCompression:
488 case Group4Compression:
489 {
cristyb51dff52011-05-19 16:55:47 +0000490 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +0000491 "currentfile %.20g %.20g "PS3_FaxCompression" ByteStreamDecodeFilter\n",
492 (double) image->columns,(double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000493 break;
494 }
495 case LZWCompression:
496 {
cristyb51dff52011-05-19 16:55:47 +0000497 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +0000498 "currentfile %.20g %.20g "PS3_LZWCompression" ByteStreamDecodeFilter\n",
499 (double) image->columns,(double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000500 break;
501 }
502 case RLECompression:
503 {
cristyb51dff52011-05-19 16:55:47 +0000504 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +0000505 "currentfile %.20g %.20g "PS3_RLECompression" ByteStreamDecodeFilter\n",
506 (double) image->columns,(double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000507 break;
508 }
509 case ZipCompression:
510 {
cristyb51dff52011-05-19 16:55:47 +0000511 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +0000512 "currentfile %.20g %.20g "PS3_ZipCompression" ByteStreamDecodeFilter\n",
513 (double) image->columns,(double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000514 break;
515 }
516 }
517 (void) WriteBlobString(image,buffer);
518 (void) WriteBlobString(image,"/ReusableStreamDecode filter\n");
cristydbeca022012-01-11 17:07:34 +0000519 mask_image=SeparateImage(image,AlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +0000520 if (mask_image == (Image *) NULL)
cristyc82a27b2011-10-21 01:07:16 +0000521 ThrowWriterException(CoderError,exception->reason);
cristy018f07f2011-09-04 21:15:19 +0000522 (void) SetImageType(mask_image,BilevelType,exception);
523 (void) SetImageType(mask_image,PaletteType,exception);
cristy8a46d822012-08-28 23:32:39 +0000524 mask_image->alpha_trait=UndefinedPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +0000525 pixels=(unsigned char *) NULL;
526 length=0;
527 switch (compression)
528 {
529 case NoCompression:
530 default:
531 {
cristy018f07f2011-09-04 21:15:19 +0000532 status=SerializeImageChannel(image_info,mask_image,&pixels,&length,
533 exception);
cristy3ed852e2009-09-05 21:47:34 +0000534 if (status == MagickFalse)
535 break;
536 Ascii85Initialize(image);
cristybb503372010-05-27 20:51:26 +0000537 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +0000538 Ascii85Encode(image,pixels[i]);
539 Ascii85Flush(image);
540 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
541 break;
542 }
543 case FaxCompression:
544 case Group4Compression:
545 {
546 if ((compression == FaxCompression) ||
547 (LocaleCompare(CCITTParam,"0") == 0))
cristy018f07f2011-09-04 21:15:19 +0000548 status=HuffmanEncodeImage(image_info,image,mask_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000549 else
cristy018f07f2011-09-04 21:15:19 +0000550 status=Huffman2DEncodeImage(image_info,image,mask_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000551 break;
552 }
553 case LZWCompression:
554 {
cristy018f07f2011-09-04 21:15:19 +0000555 status=SerializeImageChannel(image_info,mask_image,&pixels,&length,
556 exception);
cristy3ed852e2009-09-05 21:47:34 +0000557 if (status == MagickFalse)
558 break;
cristy018f07f2011-09-04 21:15:19 +0000559 status=LZWEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000560 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
561 break;
562 }
563 case RLECompression:
564 {
cristy018f07f2011-09-04 21:15:19 +0000565 status=SerializeImageChannel(image_info,mask_image,&pixels,&length,
566 exception);
cristy3ed852e2009-09-05 21:47:34 +0000567 if (status == MagickFalse)
568 break;
cristy018f07f2011-09-04 21:15:19 +0000569 status=PackbitsEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000570 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
571 break;
572 }
573 case ZipCompression:
574 {
cristy018f07f2011-09-04 21:15:19 +0000575 status=SerializeImageChannel(image_info,mask_image,&pixels,&length,
576 exception);
cristy3ed852e2009-09-05 21:47:34 +0000577 if (status == MagickFalse)
578 break;
cristy018f07f2011-09-04 21:15:19 +0000579 status=ZLIBEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000580 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
581 break;
582 }
583 }
584 mask_image=DestroyImage(mask_image);
585 (void) WriteBlobByte(image,'\n');
586 length=(size_t) (TellBlob(image)-stop);
587 stop=TellBlob(image);
588 offset=SeekBlob(image,start,SEEK_SET);
589 if (offset < 0)
590 ThrowWriterException(CorruptImageError,"ImproperImageHeader");
cristyb51dff52011-05-19 16:55:47 +0000591 (void) FormatLocaleString(buffer,MaxTextExtent,
cristyf2faecf2010-05-28 19:19:36 +0000592 "%%%%BeginData:%13ld %s Bytes\n",(long) length,
cristy3ed852e2009-09-05 21:47:34 +0000593 compression == NoCompression ? "ASCII" : "BINARY");
594 (void) WriteBlobString(image,buffer);
595 offset=SeekBlob(image,stop,SEEK_SET);
596 if (offset < 0)
597 ThrowWriterException(CorruptImageError,"ImproperImageHeader");
598 (void) WriteBlobString(image,"%%EndData\n");
599 (void) WriteBlobString(image, "/mask_stream exch def\n");
600 return(status);
601}
602
cristy1e178e72011-08-28 19:44:34 +0000603static MagickBooleanType WritePS3Image(const ImageInfo *image_info,Image *image,
604 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000605{
606 static const char
607 *PostscriptProlog[]=
608 {
609 "/ByteStreamDecodeFilter",
610 "{",
611 " /z exch def",
612 " /r exch def",
613 " /c exch def",
614 " z "PS3_NoCompression" eq { /ASCII85Decode filter } if",
615 " z "PS3_FaxCompression" eq",
616 " {",
617 " <<",
618 " /K "CCITTParam,
619 " /Columns c",
620 " /Rows r",
621 " >>",
622 " /CCITTFaxDecode filter",
623 " } if",
624 " z "PS3_JPEGCompression" eq { /DCTDecode filter } if",
625 " z "PS3_LZWCompression" eq { /LZWDecode filter } if",
626 " z "PS3_RLECompression" eq { /RunLengthDecode filter } if",
627 " z "PS3_ZipCompression" eq { /FlateDecode filter } if",
628 "} bind def",
629 "",
630 "/DirectClassImageDict",
631 "{",
632 " colorspace "PS3_RGBColorspace" eq",
633 " {",
634 " /DeviceRGB setcolorspace",
635 " <<",
636 " /ImageType 1",
637 " /Width columns",
638 " /Height rows",
639 " /BitsPerComponent 8",
640 " /DataSource pixel_stream",
641 " /MultipleDataSources false",
642 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
643 " /Decode [0 1 0 1 0 1]",
644 " >>",
645 " }",
646 " {",
647 " /DeviceCMYK setcolorspace",
648 " <<",
649 " /ImageType 1",
650 " /Width columns",
651 " /Height rows",
652 " /BitsPerComponent 8",
653 " /DataSource pixel_stream",
654 " /MultipleDataSources false",
655 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
656 " /Decode",
657 " compression "PS3_JPEGCompression" eq",
658 " { [1 0 1 0 1 0 1 0] }",
659 " { [0 1 0 1 0 1 0 1] }",
660 " ifelse",
661 " >>",
662 " }",
663 " ifelse",
664 "} bind def",
665 "",
666 "/PseudoClassImageDict",
667 "{",
668 " % Colors in colormap image.",
669 " currentfile buffer readline pop",
670 " token pop /colors exch def pop",
671 " colors 0 eq",
672 " {",
673 " % Depth of grayscale image.",
674 " currentfile buffer readline pop",
675 " token pop /bits exch def pop",
676 " /DeviceGray setcolorspace",
677 " <<",
678 " /ImageType 1",
679 " /Width columns",
680 " /Height rows",
681 " /BitsPerComponent bits",
682 " /Decode [0 1]",
683 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
684 " /DataSource pixel_stream",
685 " >>",
686 " }",
687 " {",
688 " % RGB colormap.",
689 " /colormap colors 3 mul string def",
690 " compression "PS3_NoCompression" eq",
691 " { currentfile /ASCII85Decode filter colormap readstring pop pop }",
692 " { currentfile colormap readstring pop pop }",
693 " ifelse",
694 " [ /Indexed /DeviceRGB colors 1 sub colormap ] setcolorspace",
695 " <<",
696 " /ImageType 1",
697 " /Width columns",
698 " /Height rows",
699 " /BitsPerComponent 8",
700 " /Decode [0 255]",
701 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
702 " /DataSource pixel_stream",
703 " >>",
704 " }",
705 " ifelse",
706 "} bind def",
707 "",
708 "/NonMaskedImageDict",
709 "{",
710 " class "PS3_PseudoClass" eq",
711 " { PseudoClassImageDict }",
712 " { DirectClassImageDict }",
713 " ifelse",
714 "} bind def",
715 "",
716 "/MaskedImageDict",
717 "{",
718 " <<",
719 " /ImageType 3",
720 " /InterleaveType 3",
721 " /DataDict NonMaskedImageDict",
722 " /MaskDict",
723 " <<",
724 " /ImageType 1",
725 " /Width columns",
726 " /Height rows",
727 " /BitsPerComponent 1",
728 " /DataSource mask_stream",
729 " /MultipleDataSources false",
730 " /ImageMatrix [ columns 0 0 rows neg 0 rows]",
731 " /Decode [ 0 1 ]",
732 " >>",
733 " >>",
734 "} bind def",
735 "",
736 "/ClipImage",
737 "{} def",
738 "",
739 "/DisplayImage",
740 "{",
cristy2cde86a2012-07-28 23:19:42 +0000741 " gsave",
cristy3ed852e2009-09-05 21:47:34 +0000742 " /buffer 512 string def",
743 " % Translation.",
744 " currentfile buffer readline pop",
745 " token pop /x exch def",
746 " token pop /y exch def pop",
747 " x y translate",
748 " % Image size and font size.",
749 " currentfile buffer readline pop",
750 " token pop /x exch def",
751 " token pop /y exch def pop",
752 " currentfile buffer readline pop",
753 " token pop /pointsize exch def pop",
754 (char *) NULL
755 },
756 *PostscriptEpilog[]=
757 {
758 " x y scale",
759 " % Clipping path.",
760 " currentfile buffer readline pop",
761 " token pop /clipped exch def pop",
762 " % Showpage.",
763 " currentfile buffer readline pop",
764 " token pop /sp exch def pop",
765 " % Image pixel size.",
766 " currentfile buffer readline pop",
767 " token pop /columns exch def",
768 " token pop /rows exch def pop",
769 " % Colorspace (RGB/CMYK).",
770 " currentfile buffer readline pop",
771 " token pop /colorspace exch def pop",
772 " % Transparency.",
773 " currentfile buffer readline pop",
774 " token pop /alpha exch def pop",
775 " % Stencil mask?",
776 " currentfile buffer readline pop",
777 " token pop /stencil exch def pop",
778 " % Image class (direct/pseudo).",
779 " currentfile buffer readline pop",
780 " token pop /class exch def pop",
781 " % Compression type.",
782 " currentfile buffer readline pop",
783 " token pop /compression exch def pop",
784 " % Clip and render.",
785 " /pixel_stream currentfile columns rows compression ByteStreamDecodeFilter def",
786 " clipped { ClipImage } if",
787 " alpha stencil not and",
788 " { MaskedImageDict mask_stream resetfile }",
789 " { NonMaskedImageDict }",
790 " ifelse",
791 " stencil { 0 setgray imagemask } { image } ifelse",
cristy2cde86a2012-07-28 23:19:42 +0000792 " grestore",
cristy3ed852e2009-09-05 21:47:34 +0000793 " sp { showpage } if",
794 "} bind def",
795 (char *) NULL
796 };
797
798 char
799 buffer[MaxTextExtent],
800 date[MaxTextExtent],
801 **labels,
802 page_geometry[MaxTextExtent];
803
804 CompressionType
805 compression;
806
807 const char
808 *option,
809 **q,
810 *value;
811
812 double
813 pointsize;
814
815 GeometryInfo
816 geometry_info;
817
cristy3ed852e2009-09-05 21:47:34 +0000818 MagickBooleanType
819 status;
820
821 MagickOffsetType
822 offset,
823 scene,
824 start,
825 stop;
826
827 MagickStatusType
828 flags;
829
830 PointInfo
831 delta,
832 resolution,
833 scale;
834
835 RectangleInfo
836 geometry,
837 media_info,
838 page_info;
839
cristybb503372010-05-27 20:51:26 +0000840 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000841 i;
842
843 SegmentInfo
844 bounds;
845
846 size_t
cristy802d3642011-04-27 02:02:41 +0000847 length,
848 page,
849 pixel,
850 text_size;
851
852 ssize_t
853 j;
cristy3ed852e2009-09-05 21:47:34 +0000854
855 time_t
856 timer;
857
858 unsigned char
859 *pixels;
860
cristy3ed852e2009-09-05 21:47:34 +0000861 /*
862 Open output image file.
863 */
864 assert(image_info != (const ImageInfo *) NULL);
865 assert(image_info->signature == MagickSignature);
866 assert(image != (Image *) NULL);
867 assert(image->signature == MagickSignature);
868 if (image->debug != MagickFalse)
869 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000870 assert(exception != (ExceptionInfo *) NULL);
871 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000872 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000873 if (status == MagickFalse)
874 return(MagickFalse);
875 compression=image->compression;
876 if (image_info->compression != UndefinedCompression)
877 compression=image_info->compression;
878 switch (compression)
879 {
880 case FaxCompression:
881 case Group4Compression:
882 {
cristy1e178e72011-08-28 19:44:34 +0000883 if ((IsImageMonochrome(image,exception) == MagickFalse) ||
cristy8a46d822012-08-28 23:32:39 +0000884 (image->alpha_trait == BlendPixelTrait))
cristy3ed852e2009-09-05 21:47:34 +0000885 compression=RLECompression;
886 break;
887 }
888#if !defined(MAGICKCORE_JPEG_DELEGATE)
889 case JPEGCompression:
890 {
891 compression=RLECompression;
cristy1e178e72011-08-28 19:44:34 +0000892 (void) ThrowMagickException(exception,GetMagickModule(),
cristy3ed852e2009-09-05 21:47:34 +0000893 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)",
894 image->filename);
895 break;
896 }
897#endif
898#if !defined(MAGICKCORE_ZLIB_DELEGATE)
899 case ZipCompression:
900 {
901 compression=RLECompression;
cristy1e178e72011-08-28 19:44:34 +0000902 (void) ThrowMagickException(exception,GetMagickModule(),
cristy3ed852e2009-09-05 21:47:34 +0000903 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (ZLIB)",
904 image->filename);
905 break;
906 }
907#endif
908 default:
909 break;
910 }
911 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
912 page=0;
913 scene=0;
914 do
915 {
916 /*
917 Scale relative to dots-per-inch.
918 */
919 delta.x=DefaultResolution;
920 delta.y=DefaultResolution;
cristy2a11bef2011-10-28 18:33:11 +0000921 resolution.x=image->resolution.x;
922 resolution.y=image->resolution.y;
cristy3ed852e2009-09-05 21:47:34 +0000923 if ((resolution.x == 0.0) || (resolution.y == 0.0))
924 {
925 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
926 resolution.x=geometry_info.rho;
927 resolution.y=geometry_info.sigma;
928 if ((flags & SigmaValue) == 0)
929 resolution.y=resolution.x;
930 }
931 if (image_info->density != (char *) NULL)
932 {
933 flags=ParseGeometry(image_info->density,&geometry_info);
934 resolution.x=geometry_info.rho;
935 resolution.y=geometry_info.sigma;
936 if ((flags & SigmaValue) == 0)
937 resolution.y=resolution.x;
938 }
939 if (image->units == PixelsPerCentimeterResolution)
940 {
cristybb503372010-05-27 20:51:26 +0000941 resolution.x=(size_t) (100.0*2.54*resolution.x+0.5)/100.0;
942 resolution.y=(size_t) (100.0*2.54*resolution.y+0.5)/100.0;
cristy3ed852e2009-09-05 21:47:34 +0000943 }
944 SetGeometry(image,&geometry);
cristyb51dff52011-05-19 16:55:47 +0000945 (void) FormatLocaleString(page_geometry,MaxTextExtent,"%.20gx%.20g",
cristye8c25f92010-06-03 00:53:06 +0000946 (double) image->columns,(double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000947 if (image_info->page != (char *) NULL)
948 (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent);
949 else
950 if ((image->page.width != 0) && (image->page.height != 0))
cristyb51dff52011-05-19 16:55:47 +0000951 (void) FormatLocaleString(page_geometry,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +0000952 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
953 image->page.height,(double) image->page.x,(double) image->page.y);
cristy3ed852e2009-09-05 21:47:34 +0000954 else
955 if ((image->gravity != UndefinedGravity) &&
956 (LocaleCompare(image_info->magick,"PS") == 0))
957 (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent);
958 (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent);
959 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
960 &geometry.width,&geometry.height);
961 scale.x=(double) (geometry.width*delta.x)/resolution.x;
cristybb503372010-05-27 20:51:26 +0000962 geometry.width=(size_t) floor(scale.x+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000963 scale.y=(double) (geometry.height*delta.y)/resolution.y;
cristybb503372010-05-27 20:51:26 +0000964 geometry.height=(size_t) floor(scale.y+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000965 (void) ParseAbsoluteGeometry(page_geometry,&media_info);
cristy1e178e72011-08-28 19:44:34 +0000966 (void) ParseGravityGeometry(image,page_geometry,&page_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000967 if (image->gravity != UndefinedGravity)
968 {
969 geometry.x=(-page_info.x);
cristybb503372010-05-27 20:51:26 +0000970 geometry.y=(ssize_t) (media_info.height+page_info.y-image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000971 }
972 pointsize=12.0;
973 if (image_info->pointsize != 0.0)
974 pointsize=image_info->pointsize;
975 text_size=0;
cristyd15e6592011-10-15 00:13:06 +0000976 value=GetImageProperty(image,"label",exception);
cristy3ed852e2009-09-05 21:47:34 +0000977 if (value != (const char *) NULL)
cristybb503372010-05-27 20:51:26 +0000978 text_size=(size_t) (MultilineCensus(value)*pointsize+12);
cristy3ed852e2009-09-05 21:47:34 +0000979 page++;
980 if (page == 1)
981 {
982 /*
983 Postscript header on the first page.
984 */
985 if (LocaleCompare(image_info->magick,"PS3") == 0)
986 (void) CopyMagickString(buffer,"%!PS-Adobe-3.0\n",MaxTextExtent);
987 else
988 (void) CopyMagickString(buffer,"%!PS-Adobe-3.0 EPSF-3.0\n",
989 MaxTextExtent);
990 (void) WriteBlobString(image,buffer);
cristyb51dff52011-05-19 16:55:47 +0000991 (void) FormatLocaleString(buffer,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +0000992 "%%%%Creator: ImageMagick %s\n",MagickLibVersionText);
993 (void) WriteBlobString(image,buffer);
cristyb51dff52011-05-19 16:55:47 +0000994 (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Title: %s\n",
cristy3ed852e2009-09-05 21:47:34 +0000995 image->filename);
996 (void) WriteBlobString(image,buffer);
997 timer=time((time_t *) NULL);
998 (void) FormatMagickTime(timer,MaxTextExtent,date);
cristyb51dff52011-05-19 16:55:47 +0000999 (void) FormatLocaleString(buffer,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001000 "%%%%CreationDate: %s\n",date);
1001 (void) WriteBlobString(image,buffer);
1002 bounds.x1=(double) geometry.x;
1003 bounds.y1=(double) geometry.y;
1004 bounds.x2=(double) geometry.x+scale.x;
1005 bounds.y2=(double) geometry.y+scale.y+text_size;
1006 if ((image_info->adjoin != MagickFalse) &&
1007 (GetNextImageInList(image) != (Image *) NULL))
1008 {
1009 (void) WriteBlobString(image,"%%BoundingBox: (atend)\n");
1010 (void) WriteBlobString(image,"%%HiResBoundingBox: (atend)\n");
1011 }
1012 else
1013 {
cristyb51dff52011-05-19 16:55:47 +00001014 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye4cc1a12012-09-03 23:04:46 +00001015 "%%%%BoundingBox: %g %g %g %g\n",ceil(bounds.x1-0.5),
cristy8071c472012-09-24 12:41:06 +00001016 ceil(bounds.y1-0.5),floor(bounds.x2+0.5),floor(bounds.y2+0.5));
cristy3ed852e2009-09-05 21:47:34 +00001017 (void) WriteBlobString(image,buffer);
cristyb51dff52011-05-19 16:55:47 +00001018 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001019 "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,
cristy8cd5b312010-01-07 01:10:24 +00001020 bounds.y1,bounds.x2,bounds.y2);
cristy3ed852e2009-09-05 21:47:34 +00001021 (void) WriteBlobString(image,buffer);
1022 if (image->colorspace == CMYKColorspace)
1023 (void) WriteBlobString(image,
1024 "%%DocumentProcessColors: Cyan Magenta Yellow Black\n");
1025 else
cristy1e178e72011-08-28 19:44:34 +00001026 if (IsImageGray(image,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001027 (void) WriteBlobString(image,
1028 "%%DocumentProcessColors: Black\n");
1029 }
1030 /*
1031 Font resources
1032 */
cristyd15e6592011-10-15 00:13:06 +00001033 value=GetImageProperty(image,"label",exception);
cristy3ed852e2009-09-05 21:47:34 +00001034 if (value != (const char *) NULL)
1035 (void) WriteBlobString(image,
1036 "%%DocumentNeededResources: font Helvetica\n");
1037 (void) WriteBlobString(image,"%%LanguageLevel: 3\n");
1038 /*
1039 Pages, orientation and order.
1040 */
1041 if (LocaleCompare(image_info->magick,"PS3") != 0)
1042 (void) WriteBlobString(image,"%%Pages: 1\n");
1043 else
1044 {
1045 (void) WriteBlobString(image,"%%Orientation: Portrait\n");
1046 (void) WriteBlobString(image,"%%PageOrder: Ascend\n");
1047 if (image_info->adjoin == MagickFalse)
1048 (void) CopyMagickString(buffer,"%%Pages: 1\n",MaxTextExtent);
1049 else
cristyb51dff52011-05-19 16:55:47 +00001050 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +00001051 "%%%%Pages: %.20g\n",(double) GetImageListLength(image));
cristy3ed852e2009-09-05 21:47:34 +00001052 (void) WriteBlobString(image,buffer);
1053 }
1054 (void) WriteBlobString(image,"%%EndComments\n");
1055 /*
1056 The static postscript procedures prolog.
1057 */
1058 (void)WriteBlobString(image,"%%BeginProlog\n");
1059 for (q=PostscriptProlog; *q; q++)
1060 {
1061 (void) WriteBlobString(image,*q);
1062 (void) WriteBlobByte(image,'\n');
1063 }
1064 /*
1065 One label line for each line in label string.
1066 */
cristyd15e6592011-10-15 00:13:06 +00001067 value=GetImageProperty(image,"label",exception);
cristy3ed852e2009-09-05 21:47:34 +00001068 if (value != (const char *) NULL)
1069 {
1070 (void) WriteBlobString(image,"\n %% Labels.\n /Helvetica "
1071 " findfont pointsize scalefont setfont\n");
cristybb503372010-05-27 20:51:26 +00001072 for (i=(ssize_t) MultilineCensus(value)-1; i >= 0; i--)
cristy3ed852e2009-09-05 21:47:34 +00001073 {
1074 (void) WriteBlobString(image,
1075 " currentfile buffer readline pop token pop\n");
cristyb51dff52011-05-19 16:55:47 +00001076 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001077 " 0 y %g add moveto show pop\n",i*pointsize+12);
cristy3ed852e2009-09-05 21:47:34 +00001078 (void) WriteBlobString(image,buffer);
1079 }
1080 }
1081 /*
1082 The static postscript procedures epilog.
1083 */
1084 for (q=PostscriptEpilog; *q; q++)
1085 {
1086 (void) WriteBlobString(image,*q);
1087 (void) WriteBlobByte(image,'\n');
1088 }
1089 (void)WriteBlobString(image,"%%EndProlog\n");
1090 }
cristyb51dff52011-05-19 16:55:47 +00001091 (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Page: 1 %.20g\n",
cristye8c25f92010-06-03 00:53:06 +00001092 (double) page);
cristy3ed852e2009-09-05 21:47:34 +00001093 (void) WriteBlobString(image,buffer);
1094 /*
1095 Page bounding box.
1096 */
cristyb51dff52011-05-19 16:55:47 +00001097 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +00001098 "%%%%PageBoundingBox: %.20g %.20g %.20g %.20g\n",(double) geometry.x,
1099 (double) geometry.y,geometry.x+(double) geometry.width,geometry.y+
1100 (double) (geometry.height+text_size));
cristy3ed852e2009-09-05 21:47:34 +00001101 (void) WriteBlobString(image,buffer);
1102 /*
1103 Page process colors if not RGB.
1104 */
1105 if (image->colorspace == CMYKColorspace)
1106 (void) WriteBlobString(image,
1107 "%%PageProcessColors: Cyan Magenta Yellow Black\n");
1108 else
cristy1e178e72011-08-28 19:44:34 +00001109 if (IsImageGray(image,exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001110 (void) WriteBlobString(image,"%%PageProcessColors: Black\n");
1111 /*
1112 Adjust document bounding box to bound page bounding box.
1113 */
1114 if ((double) geometry.x < bounds.x1)
1115 bounds.x1=(double) geometry.x;
1116 if ((double) geometry.y < bounds.y1)
1117 bounds.y1=(double) geometry.y;
1118 if ((double) (geometry.x+scale.x) > bounds.x2)
1119 bounds.x2=(double) geometry.x+scale.x;
1120 if ((double) (geometry.y+scale.y+text_size) > bounds.y2)
1121 bounds.y2=(double) geometry.y+scale.y+text_size;
1122 /*
1123 Page font resource if there's a label.
1124 */
cristyd15e6592011-10-15 00:13:06 +00001125 value=GetImageProperty(image,"label",exception);
cristy3ed852e2009-09-05 21:47:34 +00001126 if (value != (const char *) NULL)
1127 (void) WriteBlobString(image,"%%PageResources: font Helvetica\n");
1128 /*
1129 PS clipping path from Photoshop clipping path.
1130 */
cristy183a5c72012-01-30 01:40:35 +00001131 if ((image->mask != MagickFalse) ||
cristy10a6c612012-01-29 21:41:05 +00001132 (LocaleNCompare("8BIM:",image->magick_filename,5) != 0))
cristy3ed852e2009-09-05 21:47:34 +00001133 (void) WriteBlobString(image,"/ClipImage {} def\n");
1134 else
1135 {
1136 const char
1137 *value;
1138
cristy10a6c612012-01-29 21:41:05 +00001139 value=GetImageProperty(image,image->magick_filename,exception);
cristy3ed852e2009-09-05 21:47:34 +00001140 if (value == (const char *) NULL)
1141 return(MagickFalse);
1142 (void) WriteBlobString(image,value);
1143 (void) WriteBlobByte(image,'\n');
1144 }
1145 /*
1146 Push a dictionary for our own def's if this an EPS.
1147 */
1148 if (LocaleCompare(image_info->magick,"PS3") != 0)
1149 (void) WriteBlobString(image,"userdict begin\n");
1150 /*
1151 Image mask.
1152 */
cristy8a46d822012-08-28 23:32:39 +00001153 if ((image->alpha_trait == BlendPixelTrait) &&
cristy018f07f2011-09-04 21:15:19 +00001154 (WritePS3MaskImage(image_info,image,compression,exception) == MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +00001155 {
1156 (void) CloseBlob(image);
1157 return(MagickFalse);
1158 }
1159 /*
1160 Remember position of BeginData comment so we can update it.
1161 */
1162 start=TellBlob(image);
cristyb51dff52011-05-19 16:55:47 +00001163 (void) FormatLocaleString(buffer,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001164 "%%%%BeginData:%13ld %s Bytes\n",0L,
1165 compression == NoCompression ? "ASCII" : "BINARY");
1166 (void) WriteBlobString(image,buffer);
1167 stop=TellBlob(image);
1168 (void) WriteBlobString(image,"DisplayImage\n");
1169 /*
1170 Translate, scale, and font point size.
1171 */
cristyb51dff52011-05-19 16:55:47 +00001172 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n%g %g\n%g\n",
cristye8c25f92010-06-03 00:53:06 +00001173 (double) geometry.x,(double) geometry.y,scale.x,scale.y,pointsize);
cristy3ed852e2009-09-05 21:47:34 +00001174 (void) WriteBlobString(image,buffer);
1175 /*
1176 Output labels.
1177 */
1178 labels=(char **) NULL;
cristyd15e6592011-10-15 00:13:06 +00001179 value=GetImageProperty(image,"label",exception);
cristy3ed852e2009-09-05 21:47:34 +00001180 if (value != (const char *) NULL)
1181 labels=StringToList(value);
1182 if (labels != (char **) NULL)
1183 {
1184 for (i=0; labels[i] != (char *) NULL; i++)
1185 {
1186 if (compression != NoCompression)
1187 {
1188 for (j=0; labels[i][j] != '\0'; j++)
1189 (void) WriteBlobByte(image,(unsigned char) labels[i][j]);
1190 (void) WriteBlobByte(image,'\n');
1191 }
1192 else
1193 {
1194 (void) WriteBlobString(image,"<~");
1195 Ascii85Initialize(image);
1196 for (j=0; labels[i][j] != '\0'; j++)
1197 Ascii85Encode(image,(unsigned char) labels[i][j]);
1198 Ascii85Flush(image);
1199 }
1200 labels[i]=DestroyString(labels[i]);
1201 }
1202 labels=(char **) RelinquishMagickMemory(labels);
1203 }
1204 /*
1205 Photoshop clipping path active?
1206 */
cristy183a5c72012-01-30 01:40:35 +00001207 if ((image->mask != MagickFalse) &&
cristy10a6c612012-01-29 21:41:05 +00001208 (LocaleNCompare("8BIM:",image->magick_filename,5) == 0))
cristy3ed852e2009-09-05 21:47:34 +00001209 (void) WriteBlobString(image,"true\n");
1210 else
1211 (void) WriteBlobString(image,"false\n");
1212 /*
1213 Showpage for non-EPS.
1214 */
1215 (void) WriteBlobString(image, LocaleCompare(image_info->magick,"PS3") == 0 ?
1216 "true\n" : "false\n");
1217 /*
1218 Image columns, rows, and color space.
1219 */
cristyb51dff52011-05-19 16:55:47 +00001220 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n%s\n",
cristy802d3642011-04-27 02:02:41 +00001221 (double) image->columns,(double) image->rows,image->colorspace ==
1222 CMYKColorspace ? PS3_CMYKColorspace : PS3_RGBColorspace);
cristy3ed852e2009-09-05 21:47:34 +00001223 (void) WriteBlobString(image,buffer);
1224 /*
1225 Masked image?
1226 */
cristy8a46d822012-08-28 23:32:39 +00001227 (void) WriteBlobString(image,image->alpha_trait == BlendPixelTrait ?
cristy3ed852e2009-09-05 21:47:34 +00001228 "true\n" : "false\n");
1229 /*
1230 Render with imagemask operator?
1231 */
1232 option=GetImageOption(image_info,"ps3:imagemask");
1233 (void) WriteBlobString(image,((option != (const char *) NULL) &&
cristy1e178e72011-08-28 19:44:34 +00001234 (IsImageMonochrome(image,exception) != MagickFalse)) ?
cristy3ed852e2009-09-05 21:47:34 +00001235 "true\n" : "false\n");
1236 /*
1237 Output pixel data.
1238 */
1239 pixels=(unsigned char *) NULL;
1240 length=0;
1241 if ((image_info->type != TrueColorType) &&
1242 (image_info->type != TrueColorMatteType) &&
1243 (image_info->type != ColorSeparationType) &&
1244 (image_info->type != ColorSeparationMatteType) &&
1245 (image->colorspace != CMYKColorspace) &&
cristy1e178e72011-08-28 19:44:34 +00001246 ((IsImageGray(image,exception) != MagickFalse) ||
1247 (IsImageMonochrome(image,exception) != MagickFalse)))
cristy3ed852e2009-09-05 21:47:34 +00001248 {
1249 /*
1250 Gray images.
1251 */
1252 (void) WriteBlobString(image,PS3_PseudoClass"\n");
1253 switch (compression)
1254 {
1255 case NoCompression:
1256 default:
1257 {
1258 (void) WriteBlobString(image,PS3_NoCompression"\n");
1259 break;
1260 }
1261 case FaxCompression:
1262 case Group4Compression:
1263 {
1264 (void) WriteBlobString(image,PS3_FaxCompression"\n");
1265 break;
1266 }
1267 case JPEGCompression:
1268 {
1269 (void) WriteBlobString(image,PS3_JPEGCompression"\n");
1270 break;
1271 }
1272 case LZWCompression:
1273 {
1274 (void) WriteBlobString(image,PS3_LZWCompression"\n");
1275 break;
1276 }
1277 case RLECompression:
1278 {
1279 (void) WriteBlobString(image,PS3_RLECompression"\n");
1280 break;
1281 }
1282 case ZipCompression:
1283 {
1284 (void) WriteBlobString(image,PS3_ZipCompression"\n");
1285 break;
1286 }
1287 }
1288 /*
1289 Number of colors -- 0 for single component non-color mapped data.
1290 */
1291 (void) WriteBlobString(image,"0\n");
1292 /*
1293 1 bit or 8 bit components?
1294 */
cristyb51dff52011-05-19 16:55:47 +00001295 (void) FormatLocaleString(buffer,MaxTextExtent,"%d\n",
cristy1e178e72011-08-28 19:44:34 +00001296 IsImageMonochrome(image,exception) != MagickFalse ? 1 : 8);
cristy3ed852e2009-09-05 21:47:34 +00001297 (void) WriteBlobString(image,buffer);
1298 /*
1299 Image data.
1300 */
1301 if (compression == JPEGCompression)
cristy1e178e72011-08-28 19:44:34 +00001302 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
cristy3ed852e2009-09-05 21:47:34 +00001303 else
1304 if ((compression == FaxCompression) ||
1305 (compression == Group4Compression))
1306 {
1307 if (LocaleCompare(CCITTParam,"0") == 0)
cristy018f07f2011-09-04 21:15:19 +00001308 status=HuffmanEncodeImage(image_info,image,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001309 else
cristy018f07f2011-09-04 21:15:19 +00001310 status=Huffman2DEncodeImage(image_info,image,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001311 }
1312 else
1313 {
cristy018f07f2011-09-04 21:15:19 +00001314 status=SerializeImageChannel(image_info,image,&pixels,&length,
1315 exception);
cristy3ed852e2009-09-05 21:47:34 +00001316 if (status == MagickFalse)
1317 {
1318 (void) CloseBlob(image);
1319 return(MagickFalse);
1320 }
1321 switch (compression)
1322 {
1323 case NoCompression:
1324 default:
1325 {
1326 Ascii85Initialize(image);
cristybb503372010-05-27 20:51:26 +00001327 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001328 Ascii85Encode(image,pixels[i]);
1329 Ascii85Flush(image);
1330 status=MagickTrue;
1331 break;
1332 }
1333 case LZWCompression:
1334 {
cristy018f07f2011-09-04 21:15:19 +00001335 status=LZWEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001336 break;
1337 }
1338 case RLECompression:
1339 {
cristy018f07f2011-09-04 21:15:19 +00001340 status=PackbitsEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001341 break;
1342 }
1343 case ZipCompression:
1344 {
cristy018f07f2011-09-04 21:15:19 +00001345 status=ZLIBEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001346 break;
1347 }
1348 }
1349 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1350 }
1351 }
1352 else
1353 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1354 (compression == JPEGCompression))
1355 {
1356 /*
1357 Truecolor image.
1358 */
1359 (void) WriteBlobString(image,PS3_DirectClass"\n");
1360 switch (compression)
1361 {
1362 case NoCompression:
1363 default:
1364 {
1365 (void) WriteBlobString(image,PS3_NoCompression"\n");
1366 break;
1367 }
1368 case RLECompression:
1369 {
1370 (void) WriteBlobString(image,PS3_RLECompression"\n");
1371 break;
1372 }
1373 case JPEGCompression:
1374 {
1375 (void) WriteBlobString(image,PS3_JPEGCompression"\n");
1376 break;
1377 }
1378 case LZWCompression:
1379 {
1380 (void) WriteBlobString(image,PS3_LZWCompression"\n");
1381 break;
1382 }
1383 case ZipCompression:
1384 {
1385 (void) WriteBlobString(image,PS3_ZipCompression"\n");
1386 break;
1387 }
1388 }
1389 /*
1390 Image data.
1391 */
1392 if (compression == JPEGCompression)
cristy1e178e72011-08-28 19:44:34 +00001393 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
cristy3ed852e2009-09-05 21:47:34 +00001394 else
1395 {
1396 /*
1397 Stream based compressions.
1398 */
cristy018f07f2011-09-04 21:15:19 +00001399 status=SerializeImage(image_info,image,&pixels,&length,exception);
cristy3ed852e2009-09-05 21:47:34 +00001400 if (status == MagickFalse)
1401 {
1402 (void) CloseBlob(image);
1403 return(MagickFalse);
1404 }
1405 switch (compression)
1406 {
1407 case NoCompression:
1408 default:
1409 {
1410 Ascii85Initialize(image);
cristybb503372010-05-27 20:51:26 +00001411 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001412 Ascii85Encode(image,pixels[i]);
1413 Ascii85Flush(image);
1414 status=MagickTrue;
1415 break;
1416 }
1417 case RLECompression:
1418 {
cristy018f07f2011-09-04 21:15:19 +00001419 status=PackbitsEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001420 break;
1421 }
1422 case LZWCompression:
1423 {
cristy018f07f2011-09-04 21:15:19 +00001424 status=LZWEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001425 break;
1426 }
1427 case ZipCompression:
1428 {
cristy018f07f2011-09-04 21:15:19 +00001429 status=ZLIBEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001430 break;
1431 }
1432 }
1433 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1434 }
1435 }
1436 else
1437 {
1438 /*
1439 Colormapped images.
1440 */
1441 (void) WriteBlobString(image,PS3_PseudoClass"\n");
1442 switch (compression)
1443 {
1444 case NoCompression:
1445 default:
1446 {
1447 (void) WriteBlobString(image,PS3_NoCompression"\n");
1448 break;
1449 }
1450 case JPEGCompression:
1451 {
1452 (void) WriteBlobString(image,PS3_JPEGCompression"\n");
1453 break;
1454 }
1455 case RLECompression:
1456 {
1457 (void) WriteBlobString(image,PS3_RLECompression"\n");
1458 break;
1459 }
1460 case LZWCompression:
1461 {
1462 (void) WriteBlobString(image,PS3_LZWCompression"\n");
1463 break;
1464 }
1465 case ZipCompression:
1466 {
1467 (void) WriteBlobString(image,PS3_ZipCompression"\n");
1468 break;
1469 }
1470 }
1471 /*
1472 Number of colors in color map.
1473 */
cristyb51dff52011-05-19 16:55:47 +00001474 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",
cristye8c25f92010-06-03 00:53:06 +00001475 (double) image->colors);
cristy3ed852e2009-09-05 21:47:34 +00001476 (void) WriteBlobString(image,buffer);
1477 /*
1478 Color map - uncompressed.
1479 */
1480 if ((compression != NoCompression) &&
1481 (compression != UndefinedCompression))
1482 {
cristybb503372010-05-27 20:51:26 +00001483 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00001484 {
1485 pixel=ScaleQuantumToChar(image->colormap[i].red);
1486 (void) WriteBlobByte(image,(unsigned char) pixel);
1487 pixel=ScaleQuantumToChar(image->colormap[i].green);
1488 (void) WriteBlobByte(image,(unsigned char) pixel);
1489 pixel=ScaleQuantumToChar(image->colormap[i].blue);
1490 (void) WriteBlobByte(image,(unsigned char) pixel);
1491 }
1492 }
1493 else
1494 {
1495 Ascii85Initialize(image);
cristybb503372010-05-27 20:51:26 +00001496 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00001497 {
1498 pixel=ScaleQuantumToChar(image->colormap[i].red);
1499 Ascii85Encode(image,(unsigned char) pixel);
1500 pixel=ScaleQuantumToChar(image->colormap[i].green);
1501 Ascii85Encode(image,(unsigned char) pixel);
1502 pixel=ScaleQuantumToChar(image->colormap[i].blue);
1503 Ascii85Encode(image,(unsigned char) pixel);
1504 }
1505 Ascii85Flush(image);
1506 }
cristy018f07f2011-09-04 21:15:19 +00001507 status=SerializeImageIndexes(image_info,image,&pixels,&length,
1508 exception);
cristy3ed852e2009-09-05 21:47:34 +00001509 if (status == MagickFalse)
1510 {
1511 (void) CloseBlob(image);
1512 return(MagickFalse);
1513 }
1514 switch (compression)
1515 {
1516 case NoCompression:
1517 default:
1518 {
1519 Ascii85Initialize(image);
cristybb503372010-05-27 20:51:26 +00001520 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001521 Ascii85Encode(image,pixels[i]);
1522 Ascii85Flush(image);
1523 status=MagickTrue;
1524 break;
1525 }
1526 case JPEGCompression:
1527 {
cristy1e178e72011-08-28 19:44:34 +00001528 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
cristy3ed852e2009-09-05 21:47:34 +00001529 break;
1530 }
1531 case RLECompression:
1532 {
cristy018f07f2011-09-04 21:15:19 +00001533 status=PackbitsEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001534 break;
1535 }
1536 case LZWCompression:
1537 {
cristy018f07f2011-09-04 21:15:19 +00001538 status=LZWEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001539 break;
1540 }
1541 case ZipCompression:
1542 {
cristy018f07f2011-09-04 21:15:19 +00001543 status=ZLIBEncodeImage(image,length,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001544 break;
1545 }
1546 }
1547 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1548 }
1549 (void) WriteBlobByte(image,'\n');
1550 if (status == MagickFalse)
1551 {
1552 (void) CloseBlob(image);
1553 return(MagickFalse);
1554 }
1555 /*
1556 Update BeginData now that we know the data size.
1557 */
1558 length=(size_t) (TellBlob(image)-stop);
1559 stop=TellBlob(image);
1560 offset=SeekBlob(image,start,SEEK_SET);
1561 if (offset < 0)
1562 ThrowWriterException(CorruptImageError,"ImproperImageHeader");
cristyb51dff52011-05-19 16:55:47 +00001563 (void) FormatLocaleString(buffer,MaxTextExtent,
cristyf2faecf2010-05-28 19:19:36 +00001564 "%%%%BeginData:%13ld %s Bytes\n",(long) length,
cristy3ed852e2009-09-05 21:47:34 +00001565 compression == NoCompression ? "ASCII" : "BINARY");
1566 (void) WriteBlobString(image,buffer);
1567 offset=SeekBlob(image,stop,SEEK_SET);
1568 (void) WriteBlobString(image,"%%EndData\n");
1569 /*
1570 End private dictionary if this an EPS.
1571 */
1572 if (LocaleCompare(image_info->magick,"PS3") != 0)
1573 (void) WriteBlobString(image,"end\n");
1574 (void) WriteBlobString(image,"%%PageTrailer\n");
1575 if (GetNextImageInList(image) == (Image *) NULL)
1576 break;
1577 image=SyncNextImageInList(image);
1578 status=SetImageProgress(image,SaveImagesTag,scene++,
1579 GetImageListLength(image));
1580 if (status == MagickFalse)
1581 break;
1582 } while (image_info->adjoin != MagickFalse);
1583 (void) WriteBlobString(image,"%%Trailer\n");
1584 if (page > 1)
1585 {
cristyb51dff52011-05-19 16:55:47 +00001586 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye4cc1a12012-09-03 23:04:46 +00001587 "%%%%BoundingBox: %g %g %g %g\n",ceil(bounds.x1-0.5),
cristy8071c472012-09-24 12:41:06 +00001588 ceil(bounds.y1-0.5),floor(bounds.x2+0.5),floor(bounds.y2+0.5));
cristy3ed852e2009-09-05 21:47:34 +00001589 (void) WriteBlobString(image,buffer);
cristyb51dff52011-05-19 16:55:47 +00001590 (void) FormatLocaleString(buffer,MaxTextExtent,
cristye4cc1a12012-09-03 23:04:46 +00001591 "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1,bounds.x2,
1592 bounds.y2);
cristy3ed852e2009-09-05 21:47:34 +00001593 (void) WriteBlobString(image,buffer);
1594 }
1595 (void) WriteBlobString(image,"%%EOF\n");
1596 (void) CloseBlob(image);
1597 return(MagickTrue);
1598}