2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Write Postscript Level II Format %
20 % Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/color.h"
47 #include "magick/color-private.h"
48 #include "magick/compress.h"
49 #include "magick/constitute.h"
50 #include "magick/draw.h"
51 #include "magick/exception.h"
52 #include "magick/exception-private.h"
53 #include "magick/geometry.h"
54 #include "magick/image.h"
55 #include "magick/image-private.h"
56 #include "magick/list.h"
57 #include "magick/magick.h"
58 #include "magick/memory_.h"
59 #include "magick/monitor.h"
60 #include "magick/monitor-private.h"
61 #include "magick/monitor-private.h"
62 #include "magick/resource_.h"
63 #include "magick/property.h"
64 #include "magick/quantum-private.h"
65 #include "magick/static.h"
66 #include "magick/string_.h"
67 #include "magick/module.h"
68 #include "magick/utility.h"
69 #if defined(MAGICKCORE_TIFF_DELEGATE)
70 #define CCITTParam "-1"
72 #define CCITTParam "0"
78 static MagickBooleanType
79 WritePS2Image(const ImageInfo *,Image *);
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % R e g i s t e r P S 2 I m a g e %
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 % RegisterPS2Image() adds properties for the PS2 image format to
93 % the list of supported formats. The properties include the image format
94 % tag, a method to read and/or write the format, whether the format
95 % supports the saving of more than one frame to the same file or blob,
96 % whether the format supports native in-memory I/O, and a brief
97 % description of the format.
99 % The format of the RegisterPS2Image method is:
101 % unsigned long RegisterPS2Image(void)
104 ModuleExport unsigned long RegisterPS2Image(void)
109 entry=SetMagickInfo("EPS2");
110 entry->encoder=(EncodeImageHandler *) WritePS2Image;
111 entry->adjoin=MagickFalse;
112 entry->seekable_stream=MagickTrue;
113 entry->description=ConstantString("Level II Encapsulated PostScript");
114 entry->module=ConstantString("PS2");
115 (void) RegisterMagickInfo(entry);
116 entry=SetMagickInfo("PS2");
117 entry->encoder=(EncodeImageHandler *) WritePS2Image;
118 entry->seekable_stream=MagickTrue;
119 entry->description=ConstantString("Level II PostScript");
120 entry->module=ConstantString("PS2");
121 (void) RegisterMagickInfo(entry);
122 return(MagickImageCoderSignature);
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % U n r e g i s t e r P S 2 I m a g e %
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 % UnregisterPS2Image() removes format registrations made by the
137 % PS2 module from the list of supported formats.
139 % The format of the UnregisterPS2Image method is:
141 % UnregisterPS2Image(void)
144 ModuleExport void UnregisterPS2Image(void)
146 (void) UnregisterMagickInfo("EPS2");
147 (void) UnregisterMagickInfo("PS2");
151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % W r i t e P S 2 I m a g e %
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 % WritePS2Image translates an image to encapsulated Postscript
162 % Level II for printing. If the supplied geometry is null, the image is
163 % centered on the Postscript page. Otherwise, the image is positioned as
164 % specified by the geometry.
166 % The format of the WritePS2Image method is:
168 % MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image)
170 % A description of each parameter follows:
172 % o image_info: the image info.
174 % o image: the image.
177 static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image)
184 "%% Display a color image. The image is displayed in color on",
185 "%% Postscript viewers or printers that support color, otherwise",
186 "%% it is displayed as grayscale.",
191 " %% Display a DirectClass image.",
195 " /DeviceRGB setcolorspace",
200 " /BitsPerComponent 8",
201 " /Decode [0 1 0 1 0 1]",
202 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
204 " { /DataSource pixel_stream /%s filter }",
205 " { /DataSource pixel_stream /%s filter } ifelse",
209 " /DeviceCMYK setcolorspace",
214 " /BitsPerComponent 8",
215 " /Decode [1 0 1 0 1 0 1 0]",
216 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
218 " { /DataSource pixel_stream /%s filter }",
219 " { /DataSource pixel_stream /%s filter } ifelse",
227 " %% Display a PseudoClass image.",
230 " %% colors: number of colors in the colormap.",
232 " currentfile buffer readline pop",
233 " token pop /colors exch def pop",
237 " %% Image is grayscale.",
239 " currentfile buffer readline pop",
240 " token pop /bits exch def pop",
241 " /DeviceGray setcolorspace",
246 " /BitsPerComponent bits",
248 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
250 " { /DataSource pixel_stream /%s filter }",
252 " /DataSource pixel_stream /%s filter",
257 " >> /CCITTFaxDecode filter",
264 " %% colormap: red, green, blue color packets.",
266 " /colormap colors 3 mul string def",
267 " currentfile colormap readhexstring pop pop",
268 " currentfile buffer readline pop",
269 " [ /Indexed /DeviceRGB colors 1 sub colormap ] setcolorspace",
274 " /BitsPerComponent 8",
276 " /ImageMatrix [columns 0 0 rows neg 0 rows]",
278 " { /DataSource pixel_stream /%s filter }",
279 " { /DataSource pixel_stream /%s filter } ifelse",
287 " %% Display a DirectClass or PseudoClass image.",
290 " %% x & y translation.",
292 " %% label pointsize.",
294 " %% image columns & rows.",
295 " %% class: 0-DirectClass or 1-PseudoClass.",
296 " %% colorspace: 0-RGB or 1-CMYK.",
297 " %% compression: 0-RLECompression or 1-NoCompression.",
298 " %% hex color packets.",
301 " /buffer 512 string def",
302 " /pixel_stream currentfile def",
304 " currentfile buffer readline pop",
305 " token pop /x exch def",
306 " token pop /y exch def pop",
308 " currentfile buffer readline pop",
309 " token pop /x exch def",
310 " token pop /y exch def pop",
311 " currentfile buffer readline pop",
312 " token pop /pointsize exch def pop",
313 " /Helvetica findfont pointsize scalefont setfont",
319 " currentfile buffer readline pop",
320 " token pop /columns exch def",
321 " token pop /rows exch def pop",
322 " currentfile buffer readline pop",
323 " token pop /class exch def pop",
324 " currentfile buffer readline pop",
325 " token pop /colorspace exch def pop",
326 " currentfile buffer readline pop",
327 " token pop /compression exch def pop",
328 " class 0 gt { PseudoClassImage } { DirectClassImage } ifelse",
333 buffer[MaxTextExtent],
335 page_geometry[MaxTextExtent],
383 register const IndexPacket
386 register const PixelPacket
412 Open output image file.
414 assert(image_info != (const ImageInfo *) NULL);
415 assert(image_info->signature == MagickSignature);
416 assert(image != (Image *) NULL);
417 assert(image->signature == MagickSignature);
418 if (image->debug != MagickFalse)
419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
420 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
421 if (status == MagickFalse)
423 compression=image->compression;
424 if (image_info->compression != UndefinedCompression)
425 compression=image_info->compression;
428 #if !defined(MAGICKCORE_JPEG_DELEGATE)
429 case JPEGCompression:
431 compression=RLECompression;
432 (void) ThrowMagickException(&image->exception,GetMagickModule(),
433 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)",
441 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
447 Scale relative to dots-per-inch.
449 delta.x=DefaultResolution;
450 delta.y=DefaultResolution;
451 resolution.x=image->x_resolution;
452 resolution.y=image->y_resolution;
453 if ((resolution.x == 0.0) || (resolution.y == 0.0))
455 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
456 resolution.x=geometry_info.rho;
457 resolution.y=geometry_info.sigma;
458 if ((flags & SigmaValue) == 0)
459 resolution.y=resolution.x;
461 if (image_info->density != (char *) NULL)
463 flags=ParseGeometry(image_info->density,&geometry_info);
464 resolution.x=geometry_info.rho;
465 resolution.y=geometry_info.sigma;
466 if ((flags & SigmaValue) == 0)
467 resolution.y=resolution.x;
469 if (image->units == PixelsPerCentimeterResolution)
474 SetGeometry(image,&geometry);
475 (void) FormatMagickString(page_geometry,MaxTextExtent,"%lux%lu",
476 image->columns,image->rows);
477 if (image_info->page != (char *) NULL)
478 (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent);
480 if ((image->page.width != 0) && (image->page.height != 0))
481 (void) FormatMagickString(page_geometry,MaxTextExtent,"%lux%lu%+ld%+ld",
482 image->page.width,image->page.height,image->page.x,image->page.y);
484 if ((image->gravity != UndefinedGravity) &&
485 (LocaleCompare(image_info->magick,"PS") == 0))
486 (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent);
487 (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent);
488 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
489 &geometry.width,&geometry.height);
490 scale.x=(double) (geometry.width*delta.x)/resolution.x;
491 geometry.width=(unsigned long) (scale.x+0.5);
492 scale.y=(double) (geometry.height*delta.y)/resolution.y;
493 geometry.height=(unsigned long) (scale.y+0.5);
494 (void) ParseAbsoluteGeometry(page_geometry,&media_info);
495 (void) ParseGravityGeometry(image,page_geometry,&page_info,
497 if (image->gravity != UndefinedGravity)
499 geometry.x=(-page_info.x);
500 geometry.y=(long) (media_info.height+page_info.y-image->rows);
503 if (image_info->pointsize != 0.0)
504 pointsize=image_info->pointsize;
506 value=GetImageProperty(image,"label");
507 if (value != (const char *) NULL)
508 text_size=(unsigned long) (MultilineCensus(value)*pointsize+12);
512 Output Postscript header.
514 if (LocaleCompare(image_info->magick,"PS2") == 0)
515 (void) CopyMagickString(buffer,"%!PS-Adobe-3.0\n",MaxTextExtent);
517 (void) CopyMagickString(buffer,"%!PS-Adobe-3.0 EPSF-3.0\n",
519 (void) WriteBlobString(image,buffer);
520 (void) WriteBlobString(image,"%%Creator: (ImageMagick)\n");
521 (void) FormatMagickString(buffer,MaxTextExtent,"%%%%Title: (%s)\n",
523 (void) WriteBlobString(image,buffer);
524 timer=time((time_t *) NULL);
525 (void) FormatMagickTime(timer,MaxTextExtent,date);
526 (void) FormatMagickString(buffer,MaxTextExtent,
527 "%%%%CreationDate: (%s)\n",date);
528 (void) WriteBlobString(image,buffer);
529 bounds.x1=(double) geometry.x;
530 bounds.y1=(double) geometry.y;
531 bounds.x2=(double) geometry.x+geometry.width;
532 bounds.y2=(double) geometry.y+geometry.height+text_size;
533 if ((image_info->adjoin != MagickFalse) &&
534 (GetNextImageInList(image) != (Image *) NULL))
535 (void) CopyMagickString(buffer,"%%BoundingBox: (atend)\n",
539 (void) FormatMagickString(buffer,MaxTextExtent,
540 "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) (bounds.x1+0.5),
541 (long) (bounds.y1+0.5),
542 (long) (bounds.x2+0.5),(long) (bounds.y2+0.5));
543 (void) WriteBlobString(image,buffer);
544 (void) FormatMagickString(buffer,MaxTextExtent,
545 "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1,
546 bounds.x2,bounds.y2);
548 (void) WriteBlobString(image,buffer);
549 value=GetImageProperty(image,"label");
550 if (value != (const char *) NULL)
551 (void) WriteBlobString(image,
552 "%%DocumentNeededResources: font Helvetica\n");
553 (void) WriteBlobString(image,"%%LanguageLevel: 2\n");
554 if (LocaleCompare(image_info->magick,"PS2") != 0)
555 (void) WriteBlobString(image,"%%Pages: 1\n");
558 (void) WriteBlobString(image,"%%Orientation: Portrait\n");
559 (void) WriteBlobString(image,"%%PageOrder: Ascend\n");
560 if (image_info->adjoin == MagickFalse)
561 (void) CopyMagickString(buffer,"%%Pages: 1\n",MaxTextExtent);
563 (void) FormatMagickString(buffer,MaxTextExtent,"%%%%Pages: %lu\n",
564 (unsigned long) GetImageListLength(image));
565 (void) WriteBlobString(image,buffer);
567 (void) WriteBlobString(image,"%%EndComments\n");
568 (void) WriteBlobString(image,"\n%%BeginDefaults\n");
569 (void) WriteBlobString(image,"%%EndDefaults\n\n");
571 Output Postscript commands.
573 for (q=PostscriptProlog; *q; q++)
579 (void) FormatMagickString(buffer,MaxTextExtent,*q,
583 case JPEGCompression:
585 (void) FormatMagickString(buffer,MaxTextExtent,*q,"DCTDecode");
590 (void) FormatMagickString(buffer,MaxTextExtent,*q,"LZWDecode");
594 case Group4Compression:
596 (void) FormatMagickString(buffer,MaxTextExtent,*q,
602 (void) FormatMagickString(buffer,MaxTextExtent,*q,
607 (void) WriteBlobString(image,buffer);
608 (void) WriteBlobByte(image,'\n');
610 value=GetImageProperty(image,"label");
611 if (value != (const char *) NULL)
612 for (j=(long) MultilineCensus(value)-1; j >= 0; j--)
614 (void) WriteBlobString(image," /label 512 string def\n");
615 (void) WriteBlobString(image," currentfile label readline pop\n");
616 (void) FormatMagickString(buffer,MaxTextExtent,
617 " 0 y %g add moveto label show pop\n",j*pointsize+12);
618 (void) WriteBlobString(image,buffer);
620 for (q=PostscriptEpilog; *q; q++)
622 (void) FormatMagickString(buffer,MaxTextExtent,"%s\n",*q);
623 (void) WriteBlobString(image,buffer);
625 if (LocaleCompare(image_info->magick,"PS2") == 0)
626 (void) WriteBlobString(image," showpage\n");
627 (void) WriteBlobString(image,"} bind def\n");
628 (void) WriteBlobString(image,"%%EndProlog\n");
630 (void) FormatMagickString(buffer,MaxTextExtent,"%%%%Page: 1 %lu\n",page++);
631 (void) WriteBlobString(image,buffer);
632 (void) FormatMagickString(buffer,MaxTextExtent,
633 "%%%%PageBoundingBox: %ld %ld %ld %ld\n",geometry.x,geometry.y,
634 geometry.x+(long) geometry.width,geometry.y+(long)
635 (geometry.height+text_size));
636 (void) WriteBlobString(image,buffer);
637 if ((double) geometry.x < bounds.x1)
638 bounds.x1=(double) geometry.x;
639 if ((double) geometry.y < bounds.y1)
640 bounds.y1=(double) geometry.y;
641 if ((double) (geometry.x+geometry.width-1) > bounds.x2)
642 bounds.x2=(double) geometry.x+geometry.width-1;
643 if ((double) (geometry.y+(geometry.height+text_size)-1) > bounds.y2)
644 bounds.y2=(double) geometry.y+(geometry.height+text_size)-1;
645 value=GetImageProperty(image,"label");
646 if (value != (const char *) NULL)
647 (void) WriteBlobString(image,"%%PageResources: font Times-Roman\n");
648 if (LocaleCompare(image_info->magick,"PS2") != 0)
649 (void) WriteBlobString(image,"userdict begin\n");
650 start=TellBlob(image);
651 (void) FormatMagickString(buffer,MaxTextExtent,
652 "%%%%BeginData:%13ld %s Bytes\n",0L,
653 compression == NoCompression ? "ASCII" : "Binary");
654 (void) WriteBlobString(image,buffer);
655 stop=TellBlob(image);
656 (void) WriteBlobString(image,"DisplayImage\n");
660 (void) FormatMagickString(buffer,MaxTextExtent,"%ld %ld\n%g %g\n%f\n",
661 geometry.x,geometry.y,scale.x,scale.y,pointsize);
662 (void) WriteBlobString(image,buffer);
663 labels=(char **) NULL;
664 value=GetImageProperty(image,"label");
665 if (value != (const char *) NULL)
666 labels=StringToList(value);
667 if (labels != (char **) NULL)
669 for (i=0; labels[i] != (char *) NULL; i++)
671 (void) FormatMagickString(buffer,MaxTextExtent,"%s \n",
673 (void) WriteBlobString(image,buffer);
674 labels[i]=DestroyString(labels[i]);
676 labels=(char **) RelinquishMagickMemory(labels);
678 number_pixels=(MagickSizeType) image->columns*image->rows;
679 if (number_pixels != (MagickSizeType) ((size_t) number_pixels))
680 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
681 if ((compression == FaxCompression) || (compression == Group4Compression) ||
682 ((image_info->type != TrueColorType) &&
683 (IsGrayImage(image,&image->exception) != MagickFalse)))
685 (void) FormatMagickString(buffer,MaxTextExtent,"%lu %lu\n1\n%d\n",
686 image->columns,image->rows,(int)
687 (image->colorspace == CMYKColorspace));
688 (void) WriteBlobString(image,buffer);
689 (void) FormatMagickString(buffer,MaxTextExtent,"%d\n",
690 (int) ((compression != FaxCompression) &&
691 (compression != Group4Compression)));
692 (void) WriteBlobString(image,buffer);
693 (void) WriteBlobString(image,"0\n");
694 (void) FormatMagickString(buffer,MaxTextExtent,"%d\n",
695 (compression == FaxCompression) ||
696 (compression == Group4Compression) ? 1 : 8);
697 (void) WriteBlobString(image,buffer);
701 case Group4Compression:
703 if (LocaleCompare(CCITTParam,"0") == 0)
705 (void) HuffmanEncodeImage(image_info,image,image);
708 #if defined(MAGICKCORE_TIFF_DELEGATE)
709 (void) Huffman2DEncodeImage(image_info,image,image);
713 case JPEGCompression:
715 status=InjectImageBlob(image_info,image,image,"jpeg",
717 if (status == MagickFalse)
718 ThrowWriterException(CoderError,image->exception.reason);
724 register unsigned char
728 Allocate pixel array.
730 length=(size_t) number_pixels;
731 pixels=(unsigned char *) AcquireQuantumMemory(length,
733 if (pixels == (unsigned char *) NULL)
734 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
736 Dump Runlength encoded pixels.
739 for (y=0; y < (long) image->rows; y++)
741 p=GetVirtualPixels(image,0,y,image->columns,1,
743 if (p == (const PixelPacket *) NULL)
745 for (x=0; x < (long) image->columns; x++)
747 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
750 progress=SetImageProgress(image,SaveImageTag,y,image->rows);
751 if (progress == MagickFalse)
754 length=(size_t) (q-pixels);
755 if (compression == LZWCompression)
756 status=LZWEncodeImage(image,length,pixels);
758 status=PackbitsEncodeImage(image,length,pixels);
759 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
760 if (status == MagickFalse)
762 (void) CloseBlob(image);
770 Dump uncompressed PseudoColor packets.
772 Ascii85Initialize(image);
773 for (y=0; y < (long) image->rows; y++)
775 p=GetVirtualPixels(image,0,y,image->columns,1,
777 if (p == (const PixelPacket *) NULL)
779 for (x=0; x < (long) image->columns; x++)
782 ScaleQuantumToChar(PixelIntensityToQuantum(p)));
785 progress=SetImageProgress(image,SaveImageTag,y,image->rows);
786 if (progress == MagickFalse)
795 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
796 (compression == JPEGCompression) || (image->matte != MagickFalse))
798 (void) FormatMagickString(buffer,MaxTextExtent,"%lu %lu\n0\n%d\n",
799 image->columns,image->rows,(int)
800 (image->colorspace == CMYKColorspace));
801 (void) WriteBlobString(image,buffer);
802 (void) FormatMagickString(buffer,MaxTextExtent,"%d\n",
803 (int) (compression == NoCompression));
804 (void) WriteBlobString(image,buffer);
807 case JPEGCompression:
809 status=InjectImageBlob(image_info,image,image,"jpeg",
811 if (status == MagickFalse)
812 ThrowWriterException(CoderError,image->exception.reason);
818 register unsigned char
822 Allocate pixel array.
824 length=(size_t) number_pixels;
825 pixels=(unsigned char *) AcquireQuantumMemory(length,
827 if (pixels == (unsigned char *) NULL)
828 ThrowWriterException(ResourceLimitError,
829 "MemoryAllocationFailed");
831 Dump Packbit encoded pixels.
834 for (y=0; y < (long) image->rows; y++)
836 p=GetVirtualPixels(image,0,y,image->columns,1,
838 if (p == (const PixelPacket *) NULL)
840 indexes=GetVirtualIndexQueue(image);
841 for (x=0; x < (long) image->columns; x++)
843 if ((image->matte != MagickFalse) &&
844 (p->opacity == (Quantum) TransparentOpacity))
846 *q++=ScaleQuantumToChar((Quantum) QuantumRange);
847 *q++=ScaleQuantumToChar((Quantum) QuantumRange);
848 *q++=ScaleQuantumToChar((Quantum) QuantumRange);
851 if (image->colorspace != CMYKColorspace)
853 *q++=ScaleQuantumToChar(p->red);
854 *q++=ScaleQuantumToChar(p->green);
855 *q++=ScaleQuantumToChar(p->blue);
859 *q++=ScaleQuantumToChar(p->red);
860 *q++=ScaleQuantumToChar(p->green);
861 *q++=ScaleQuantumToChar(p->blue);
862 *q++=ScaleQuantumToChar(indexes[x]);
866 progress=SetImageProgress(image,SaveImageTag,y,image->rows);
867 if (progress == MagickFalse)
870 length=(size_t) (q-pixels);
871 if (compression == LZWCompression)
872 status=LZWEncodeImage(image,length,pixels);
874 status=PackbitsEncodeImage(image,length,pixels);
875 if (status == MagickFalse)
877 (void) CloseBlob(image);
880 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
886 Dump uncompressed DirectColor packets.
888 Ascii85Initialize(image);
889 for (y=0; y < (long) image->rows; y++)
891 p=GetVirtualPixels(image,0,y,image->columns,1,
893 if (p == (const PixelPacket *) NULL)
895 indexes=GetVirtualIndexQueue(image);
896 for (x=0; x < (long) image->columns; x++)
898 if ((image->matte != MagickFalse) &&
899 (p->opacity == (Quantum) TransparentOpacity))
901 Ascii85Encode(image,ScaleQuantumToChar((Quantum)
903 Ascii85Encode(image,ScaleQuantumToChar((Quantum)
905 Ascii85Encode(image,ScaleQuantumToChar((Quantum)
909 if (image->colorspace != CMYKColorspace)
911 Ascii85Encode(image,ScaleQuantumToChar(p->red));
912 Ascii85Encode(image,ScaleQuantumToChar(p->green));
913 Ascii85Encode(image,ScaleQuantumToChar(p->blue));
917 Ascii85Encode(image,ScaleQuantumToChar(p->red));
918 Ascii85Encode(image,ScaleQuantumToChar(p->green));
919 Ascii85Encode(image,ScaleQuantumToChar(p->blue));
920 Ascii85Encode(image,ScaleQuantumToChar(indexes[x]));
924 progress=SetImageProgress(image,SaveImageTag,y,image->rows);
925 if (progress == MagickFalse)
936 Dump number of colors and colormap.
938 (void) FormatMagickString(buffer,MaxTextExtent,"%lu %lu\n1\n%d\n",
939 image->columns,image->rows,(int)
940 (image->colorspace == CMYKColorspace));
941 (void) WriteBlobString(image,buffer);
942 (void) FormatMagickString(buffer,MaxTextExtent,"%d\n",
943 (int) (compression == NoCompression));
944 (void) WriteBlobString(image,buffer);
945 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",image->colors);
946 (void) WriteBlobString(image,buffer);
947 for (i=0; i < (long) image->colors; i++)
949 (void) FormatMagickString(buffer,MaxTextExtent,"%02X%02X%02X\n",
950 ScaleQuantumToChar(image->colormap[i].red),
951 ScaleQuantumToChar(image->colormap[i].green),
952 ScaleQuantumToChar(image->colormap[i].blue));
953 (void) WriteBlobString(image,buffer);
960 register unsigned char
964 Allocate pixel array.
966 length=(size_t) number_pixels;
967 pixels=(unsigned char *) AcquireQuantumMemory(length,
969 if (pixels == (unsigned char *) NULL)
970 ThrowWriterException(ResourceLimitError,
971 "MemoryAllocationFailed");
973 Dump Runlength encoded pixels.
976 for (y=0; y < (long) image->rows; y++)
978 p=GetVirtualPixels(image,0,y,image->columns,1,
980 if (p == (const PixelPacket *) NULL)
982 indexes=GetVirtualIndexQueue(image);
983 for (x=0; x < (long) image->columns; x++)
984 *q++=(unsigned char) indexes[x];
985 progress=SetImageProgress(image,SaveImageTag,y,image->rows);
986 if (progress == MagickFalse)
989 length=(size_t) (q-pixels);
990 if (compression == LZWCompression)
991 status=LZWEncodeImage(image,length,pixels);
993 status=PackbitsEncodeImage(image,length,pixels);
994 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
995 if (status == MagickFalse)
997 (void) CloseBlob(image);
1005 Dump uncompressed PseudoColor packets.
1007 Ascii85Initialize(image);
1008 for (y=0; y < (long) image->rows; y++)
1010 p=GetVirtualPixels(image,0,y,image->columns,1,
1012 if (p == (const PixelPacket *) NULL)
1014 indexes=GetVirtualIndexQueue(image);
1015 for (x=0; x < (long) image->columns; x++)
1016 Ascii85Encode(image,(unsigned char) indexes[x]);
1017 progress=SetImageProgress(image,SaveImageTag,y,image->rows);
1018 if (progress == MagickFalse)
1021 Ascii85Flush(image);
1026 (void) WriteBlobByte(image,'\n');
1027 length=(size_t) (TellBlob(image)-stop);
1028 stop=TellBlob(image);
1029 offset=SeekBlob(image,start,SEEK_SET);
1031 ThrowWriterException(CorruptImageError,"ImproperImageHeader");
1032 (void) FormatMagickString(buffer,MaxTextExtent,
1033 "%%%%BeginData:%13ld %s Bytes\n",(long) length,
1034 compression == NoCompression ? "ASCII" : "Binary");
1035 (void) WriteBlobString(image,buffer);
1036 offset=SeekBlob(image,stop,SEEK_SET);
1037 (void) WriteBlobString(image,"%%EndData\n");
1038 if (LocaleCompare(image_info->magick,"PS2") != 0)
1039 (void) WriteBlobString(image,"end\n");
1040 (void) WriteBlobString(image,"%%PageTrailer\n");
1041 if (GetNextImageInList(image) == (Image *) NULL)
1043 image=SyncNextImageInList(image);
1044 status=SetImageProgress(image,SaveImagesTag,scene++,
1045 GetImageListLength(image));
1046 if (status == MagickFalse)
1048 } while (image_info->adjoin != MagickFalse);
1049 (void) WriteBlobString(image,"%%Trailer\n");
1052 (void) FormatMagickString(buffer,MaxTextExtent,
1053 "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) (bounds.x1+0.5),
1054 (long) (bounds.y1+0.5),(long) (bounds.x2+0.5),(long) (bounds.y2+0.5));
1055 (void) WriteBlobString(image,buffer);
1056 (void) FormatMagickString(buffer,MaxTextExtent,
1057 "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1,bounds.x2,
1059 (void) WriteBlobString(image,buffer);
1061 (void) WriteBlobString(image,"%%EOF\n");
1062 (void) CloseBlob(image);