2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Portable Document Format %
20 % Copyright 1999-2013 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 "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colorspace.h"
50 #include "MagickCore/colorspace-private.h"
51 #include "MagickCore/compress.h"
52 #include "MagickCore/constitute.h"
53 #include "MagickCore/delegate.h"
54 #include "MagickCore/delegate-private.h"
55 #include "MagickCore/draw.h"
56 #include "MagickCore/exception.h"
57 #include "MagickCore/exception-private.h"
58 #include "MagickCore/geometry.h"
59 #include "MagickCore/image.h"
60 #include "MagickCore/image-private.h"
61 #include "MagickCore/list.h"
62 #include "MagickCore/magick.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/monitor.h"
65 #include "MagickCore/monitor-private.h"
66 #include "MagickCore/option.h"
67 #include "MagickCore/pixel-accessor.h"
68 #include "MagickCore/profile.h"
69 #include "MagickCore/property.h"
70 #include "MagickCore/quantum-private.h"
71 #include "MagickCore/resource_.h"
72 #include "MagickCore/resize.h"
73 #include "MagickCore/signature.h"
74 #include "MagickCore/static.h"
75 #include "MagickCore/string_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/token.h"
78 #include "MagickCore/transform.h"
79 #include "MagickCore/utility.h"
80 #include "MagickCore/module.h"
85 #if defined(MAGICKCORE_TIFF_DELEGATE)
86 #define CCITTParam "-1"
88 #define CCITTParam "0"
94 static MagickBooleanType
95 WritePDFImage(const ImageInfo *,Image *,ExceptionInfo *);
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % IsPDF() returns MagickTrue if the image format type, identified by the
109 % magick string, is PDF.
111 % The format of the IsPDF method is:
113 % MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
115 % A description of each parameter follows:
117 % o magick: compare image format pattern against these bytes.
119 % o offset: Specifies the offset of the magick string.
122 static MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
126 if (LocaleNCompare((const char *) magick,"%PDF-",5) == 0)
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 % R e a d P D F I m a g e %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % ReadPDFImage() reads a Portable Document Format image file and
143 % returns it. It allocates the memory necessary for the new Image structure
144 % and returns a pointer to the new image.
146 % The format of the ReadPDFImage method is:
148 % Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
150 % A description of each parameter follows:
152 % o image_info: the image info.
154 % o exception: return any errors or warnings in this structure.
158 static MagickBooleanType IsPDFRendered(const char *path)
166 if ((path == (const char *) NULL) || (*path == '\0'))
168 status=GetPathAttributes(path,&attributes);
169 if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
170 (attributes.st_size > 0))
175 static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
177 #define CMYKProcessColor "CMYKProcessColor"
178 #define CropBox "CropBox"
179 #define DefaultCMYK "DefaultCMYK"
180 #define DeviceCMYK "DeviceCMYK"
181 #define MediaBox "MediaBox"
182 #define RenderPostscriptText "Rendering Postscript... "
183 #define PDFRotate "Rotate"
184 #define SpotColor "Separation"
185 #define TrimBox "TrimBox"
186 #define PDFVersion "PDF-"
189 command[MaxTextExtent],
190 density[MaxTextExtent],
191 filename[MaxTextExtent],
192 geometry[MaxTextExtent],
193 options[MaxTextExtent],
194 input_filename[MaxTextExtent],
195 postscript_filename[MaxTextExtent];
254 assert(image_info != (const ImageInfo *) NULL);
255 assert(image_info->signature == MagickSignature);
256 if (image_info->debug != MagickFalse)
257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
258 image_info->filename);
259 assert(exception != (ExceptionInfo *) NULL);
260 assert(exception->signature == MagickSignature);
264 image=AcquireImage(image_info,exception);
265 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
266 if (status == MagickFalse)
268 image=DestroyImageList(image);
269 return((Image *) NULL);
271 status=AcquireUniqueSymbolicLink(image_info->filename,input_filename);
272 if (status == MagickFalse)
274 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
275 image_info->filename);
276 image=DestroyImageList(image);
277 return((Image *) NULL);
280 Set the page density.
282 delta.x=DefaultResolution;
283 delta.y=DefaultResolution;
284 if ((image->resolution.x == 0.0) || (image->resolution.y == 0.0))
286 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
287 image->resolution.x=geometry_info.rho;
288 image->resolution.y=geometry_info.sigma;
289 if ((flags & SigmaValue) == 0)
290 image->resolution.y=image->resolution.x;
292 if (image_info->density != (char *) NULL)
294 flags=ParseGeometry(image_info->density,&geometry_info);
295 image->resolution.x=geometry_info.rho;
296 image->resolution.y=geometry_info.sigma;
297 if ((flags & SigmaValue) == 0)
298 image->resolution.y=image->resolution.x;
300 (void) ParseAbsoluteGeometry(PSPageGeometry,&page);
301 if (image_info->page != (char *) NULL)
302 (void) ParseAbsoluteGeometry(image_info->page,&page);
303 page.width=(size_t) ceil((double) (page.width*image->resolution.x/delta.x)-
305 page.height=(size_t) ceil((double) (page.height*image->resolution.y/delta.y)-
308 Determine page geometry from the PDF media box.
310 cmyk=image_info->colorspace == CMYKColorspace ? MagickTrue : MagickFalse;
311 cropbox=IsStringTrue(GetImageOption(image_info,"pdf:use-cropbox"));
312 trimbox=IsStringTrue(GetImageOption(image_info,"pdf:use-trimbox"));
315 (void) ResetMagickMemory(&bounding_box,0,sizeof(bounding_box));
316 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
317 (void) ResetMagickMemory(&hires_bounds,0,sizeof(hires_bounds));
318 (void) ResetMagickMemory(command,0,sizeof(command));
321 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
329 if ((c != (int) '/') && (c != (int) '%') &&
330 ((size_t) (p-command) < (MaxTextExtent-1)))
334 if (LocaleNCompare(PDFRotate,command,strlen(PDFRotate)) == 0)
335 count=(ssize_t) sscanf(command,"Rotate %lf",&angle);
337 Is this a CMYK document?
339 if (LocaleNCompare(DefaultCMYK,command,strlen(DefaultCMYK)) == 0)
341 if (LocaleNCompare(DeviceCMYK,command,strlen(DeviceCMYK)) == 0)
343 if (LocaleNCompare(CMYKProcessColor,command,strlen(CMYKProcessColor)) == 0)
345 if (LocaleNCompare(SpotColor,command,strlen(SpotColor)) == 0)
349 property[MaxTextExtent],
358 (void) FormatLocaleString(property,MaxTextExtent,"pdf:SpotColor-%.20g",
359 (double) spotcolor++);
361 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
363 if ((isspace(c) != 0) || (c == '/') || ((i+1) == MaxTextExtent))
368 value=AcquireString(name);
369 (void) SubstituteString(&value,"#20"," ");
370 (void) SetImageProperty(image,property,value,exception);
371 value=DestroyString(value);
374 if (LocaleNCompare(PDFVersion,command,strlen(PDFVersion)) == 0)
375 (void) SetImageProperty(image,"pdf:Version",command,exception);
376 if (image_info->page != (char *) NULL)
379 if (cropbox != MagickFalse)
381 if (LocaleNCompare(CropBox,command,strlen(CropBox)) == 0)
384 Note region defined by crop box.
386 count=(ssize_t) sscanf(command,"CropBox [%lf %lf %lf %lf",
387 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
389 count=(ssize_t) sscanf(command,"CropBox[%lf %lf %lf %lf",
390 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
394 if (trimbox != MagickFalse)
396 if (LocaleNCompare(TrimBox,command,strlen(TrimBox)) == 0)
399 Note region defined by trim box.
401 count=(ssize_t) sscanf(command,"TrimBox [%lf %lf %lf %lf",
402 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
404 count=(ssize_t) sscanf(command,"TrimBox[%lf %lf %lf %lf",
405 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
409 if (LocaleNCompare(MediaBox,command,strlen(MediaBox)) == 0)
412 Note region defined by media box.
414 count=(ssize_t) sscanf(command,"MediaBox [%lf %lf %lf %lf",
415 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
417 count=(ssize_t) sscanf(command,"MediaBox[%lf %lf %lf %lf",
418 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
422 if ((fabs(bounds.x2-bounds.x1) <= fabs(hires_bounds.x2-hires_bounds.x1)) ||
423 (fabs(bounds.y2-bounds.y1) <= fabs(hires_bounds.y2-hires_bounds.y1)))
427 if ((fabs(hires_bounds.x2-hires_bounds.x1) >= MagickEpsilon) &&
428 (fabs(hires_bounds.y2-hires_bounds.y1) >= MagickEpsilon))
431 Set PDF render geometry.
433 (void) FormatLocaleString(geometry,MaxTextExtent,"%gx%g%+.15g%+.15g",
434 hires_bounds.x2-bounds.x1,hires_bounds.y2-hires_bounds.y1,
435 hires_bounds.x1,hires_bounds.y1);
436 (void) SetImageProperty(image,"pdf:HiResBoundingBox",geometry,exception);
437 page.width=(size_t) ceil((double) ((hires_bounds.x2-hires_bounds.x1)*
438 image->resolution.x/delta.x)-0.5);
439 page.height=(size_t) ceil((double) ((hires_bounds.y2-hires_bounds.y1)*
440 image->resolution.y/delta.y)-0.5);
442 (void) CloseBlob(image);
443 if ((fabs(angle) == 90.0) || (fabs(angle) == 270.0))
449 page.width=page.height;
452 if (IssRGBCompatibleColorspace(image_info->colorspace) != MagickFalse)
455 Create Ghostscript control file.
457 file=AcquireUniqueFileResource(postscript_filename);
460 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
461 image_info->filename);
462 image=DestroyImage(image);
463 return((Image *) NULL);
465 count=write(file," ",1);
468 Render Postscript with the Ghostscript delegate.
470 if ((image_info->ping != MagickFalse) ||
471 (image_info->monochrome != MagickFalse))
472 delegate_info=GetDelegateInfo("ps:mono",(char *) NULL,exception);
474 if (cmyk != MagickFalse)
475 delegate_info=GetDelegateInfo("ps:cmyk",(char *) NULL,exception);
477 delegate_info=GetDelegateInfo("ps:alpha",(char *) NULL,exception);
478 if (delegate_info == (const DelegateInfo *) NULL)
480 (void) RelinquishUniqueFileResource(postscript_filename);
481 image=DestroyImage(image);
482 return((Image *) NULL);
485 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",image->resolution.x,
486 image->resolution.y);
487 if (image_info->page != (char *) NULL)
488 (void) FormatLocaleString(options,MaxTextExtent,"-g%.20gx%.20g ",(double)
489 page.width,(double) page.height);
490 if (cmyk != MagickFalse)
491 (void) ConcatenateMagickString(options,"-dUseCIEColor ",MaxTextExtent);
492 if (cropbox != MagickFalse)
493 (void) ConcatenateMagickString(options,"-dUseCropBox ",MaxTextExtent);
494 if (trimbox != MagickFalse)
495 (void) ConcatenateMagickString(options,"-dUseTrimBox ",MaxTextExtent);
496 read_info=CloneImageInfo(image_info);
497 *read_info->magick='\0';
498 if (read_info->number_scenes != 0)
501 pages[MaxTextExtent];
503 (void) FormatLocaleString(pages,MaxTextExtent,"-dFirstPage=%.20g "
504 "-dLastPage=%.20g",(double) read_info->scene+1,(double)
505 (read_info->scene+read_info->number_scenes));
506 (void) ConcatenateMagickString(options,pages,MaxTextExtent);
507 read_info->number_scenes=0;
508 if (read_info->scenes != (char *) NULL)
509 *read_info->scenes='\0';
511 option=GetImageOption(read_info,"authenticate");
512 if (option != (const char *) NULL)
513 (void) FormatLocaleString(options+strlen(options),MaxTextExtent,
514 " -sPCLPassword=%s",option);
515 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
516 (void) AcquireUniqueFilename(filename);
517 (void) ConcatenateMagickString(filename,"%d",MaxTextExtent);
518 (void) FormatLocaleString(command,MaxTextExtent,
519 GetDelegateCommands(delegate_info),
520 read_info->antialias != MagickFalse ? 4 : 1,
521 read_info->antialias != MagickFalse ? 4 : 1,density,options,filename,
522 postscript_filename,input_filename);
523 status=InvokePostscriptDelegate(read_info->verbose,command,exception);
524 (void) RelinquishUniqueFileResource(postscript_filename);
525 (void) RelinquishUniqueFileResource(input_filename);
526 pdf_image=(Image *) NULL;
527 if (status == MagickFalse)
530 (void) InterpretImageFilename(image_info,image,filename,(int) i,
531 read_info->filename,exception);
532 if (IsPDFRendered(read_info->filename) == MagickFalse)
534 (void) RelinquishUniqueFileResource(read_info->filename);
539 (void) InterpretImageFilename(image_info,image,filename,(int) i,
540 read_info->filename,exception);
541 if (IsPDFRendered(read_info->filename) == MagickFalse)
543 read_info->blob=NULL;
545 next=ReadImage(read_info,exception);
546 (void) RelinquishUniqueFileResource(read_info->filename);
547 if (next == (Image *) NULL)
549 AppendImageToList(&pdf_image,next);
551 read_info=DestroyImageInfo(read_info);
552 if (pdf_image == (Image *) NULL)
554 ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
555 image_info->filename);
556 image=DestroyImage(image);
557 return((Image *) NULL);
559 if (LocaleCompare(pdf_image->magick,"BMP") == 0)
564 cmyk_image=ConsolidateCMYKImages(pdf_image,exception);
565 if (cmyk_image != (Image *) NULL)
567 pdf_image=DestroyImageList(pdf_image);
568 pdf_image=cmyk_image;
571 if (image_info->number_scenes != 0)
580 Add place holder images to meet the subimage specification requirement.
582 for (i=0; i < (ssize_t) image_info->scene; i++)
584 clone_image=CloneImage(pdf_image,1,1,MagickTrue,exception);
585 if (clone_image != (Image *) NULL)
586 PrependImageToList(&pdf_image,clone_image);
591 (void) CopyMagickString(pdf_image->filename,filename,MaxTextExtent);
592 pdf_image->page=page;
593 (void) CloneImageProfiles(pdf_image,image);
594 (void) CloneImageProperties(pdf_image,image);
595 next=SyncNextImageInList(pdf_image);
596 if (next != (Image *) NULL)
598 } while (next != (Image *) NULL);
599 image=DestroyImage(image);
601 for (next=GetFirstImageInList(pdf_image); next != (Image *) NULL; )
604 next=GetNextImageInList(next);
606 return(GetFirstImageInList(pdf_image));
610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614 % R e g i s t e r P D F I m a g e %
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620 % RegisterPDFImage() adds properties for the PDF image format to
621 % the list of supported formats. The properties include the image format
622 % tag, a method to read and/or write the format, whether the format
623 % supports the saving of more than one frame to the same file or blob,
624 % whether the format supports native in-memory I/O, and a brief
625 % description of the format.
627 % The format of the RegisterPDFImage method is:
629 % size_t RegisterPDFImage(void)
632 ModuleExport size_t RegisterPDFImage(void)
637 entry=SetMagickInfo("AI");
638 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
639 entry->encoder=(EncodeImageHandler *) WritePDFImage;
640 entry->adjoin=MagickFalse;
641 entry->blob_support=MagickFalse;
642 entry->seekable_stream=MagickTrue;
643 entry->description=ConstantString("Adobe Illustrator CS2");
644 entry->module=ConstantString("PDF");
645 (void) RegisterMagickInfo(entry);
646 entry=SetMagickInfo("EPDF");
647 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
648 entry->encoder=(EncodeImageHandler *) WritePDFImage;
649 entry->adjoin=MagickFalse;
650 entry->blob_support=MagickFalse;
651 entry->seekable_stream=MagickTrue;
652 entry->description=ConstantString("Encapsulated Portable Document Format");
653 entry->module=ConstantString("PDF");
654 (void) RegisterMagickInfo(entry);
655 entry=SetMagickInfo("PDF");
656 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
657 entry->encoder=(EncodeImageHandler *) WritePDFImage;
658 entry->magick=(IsImageFormatHandler *) IsPDF;
659 entry->blob_support=MagickFalse;
660 entry->seekable_stream=MagickTrue;
661 entry->description=ConstantString("Portable Document Format");
662 entry->module=ConstantString("PDF");
663 (void) RegisterMagickInfo(entry);
664 entry=SetMagickInfo("PDFA");
665 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
666 entry->encoder=(EncodeImageHandler *) WritePDFImage;
667 entry->magick=(IsImageFormatHandler *) IsPDF;
668 entry->blob_support=MagickFalse;
669 entry->seekable_stream=MagickTrue;
670 entry->description=ConstantString("Portable Document Archive Format");
671 entry->module=ConstantString("PDF");
672 (void) RegisterMagickInfo(entry);
673 return(MagickImageCoderSignature);
677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681 % U n r e g i s t e r P D F I m a g e %
685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
687 % UnregisterPDFImage() removes format registrations made by the
688 % PDF module from the list of supported formats.
690 % The format of the UnregisterPDFImage method is:
692 % UnregisterPDFImage(void)
695 ModuleExport void UnregisterPDFImage(void)
697 (void) UnregisterMagickInfo("AI");
698 (void) UnregisterMagickInfo("EPDF");
699 (void) UnregisterMagickInfo("PDF");
700 (void) UnregisterMagickInfo("PDFA");
704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708 % W r i t e P D F I m a g e %
712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
714 % WritePDFImage() writes an image in the Portable Document image
717 % The format of the WritePDFImage method is:
719 % MagickBooleanType WritePDFImage(const ImageInfo *image_info,
720 % Image *image,ExceptionInfo *exception)
722 % A description of each parameter follows.
724 % o image_info: the image info.
726 % o image: The image.
728 % o exception: return any errors or warnings in this structure.
732 static inline size_t MagickMax(const size_t x,const size_t y)
739 static inline size_t MagickMin(const size_t x,const size_t y)
746 static char *EscapeParenthesis(const char *text)
758 buffer[MaxTextExtent];
762 for (i=0; i < (ssize_t) MagickMin(strlen(text),(MaxTextExtent-escapes-1)); i++)
764 if ((text[i] == '(') || (text[i] == ')'))
775 static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info,
776 Image *image,Image *inject_image,ExceptionInfo *exception)
794 write_info=CloneImageInfo(image_info);
795 (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent);
796 (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent);
797 group4_image=CloneImage(inject_image,0,0,MagickTrue,exception);
798 if (group4_image == (Image *) NULL)
800 group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length,
802 group4_image=DestroyImage(group4_image);
803 if (group4 == (unsigned char *) NULL)
805 write_info=DestroyImageInfo(write_info);
806 if (WriteBlob(image,length,group4) != (ssize_t) length)
808 group4=(unsigned char *) RelinquishMagickMemory(group4);
812 static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image,
813 ExceptionInfo *exception)
815 #define CFormat "/Filter [ /%s ]\n"
816 #define ObjectsPerImage 14
821 "<?xpacket begin=\"%s\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
822 "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c316 44.253921, Sun Oct 01 2006 17:08:23\">\n"
823 " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
824 " <rdf:Description rdf:about=\"\"\n"
825 " xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">\n"
826 " <xap:ModifyDate>%s</xap:ModifyDate>\n"
827 " <xap:CreateDate>%s</xap:CreateDate>\n"
828 " <xap:MetadataDate>%s</xap:MetadataDate>\n"
829 " <xap:CreatorTool>%s</xap:CreatorTool>\n"
830 " </rdf:Description>\n"
831 " <rdf:Description rdf:about=\"\"\n"
832 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
833 " <dc:format>application/pdf</dc:format>\n"
836 " <rdf:li xml:lang=\"x-default\">%s</rdf:li>\n"
839 " </rdf:Description>\n"
840 " <rdf:Description rdf:about=\"\"\n"
841 " xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\">\n"
842 " <xapMM:DocumentID>uuid:6ec119d7-7982-4f56-808d-dfe64f5b35cf</xapMM:DocumentID>\n"
843 " <xapMM:InstanceID>uuid:a79b99b4-6235-447f-9f6c-ec18ef7555cb</xapMM:InstanceID>\n"
844 " </rdf:Description>\n"
845 " <rdf:Description rdf:about=\"\"\n"
846 " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">\n"
847 " <pdf:Producer>%s</pdf:Producer>\n"
848 " </rdf:Description>\n"
849 " <rdf:Description rdf:about=\"\"\n"
850 " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n"
851 " <pdfaid:part>2</pdfaid:part>\n"
852 " <pdfaid:conformance>B</pdfaid:conformance>\n"
853 " </rdf:Description>\n"
856 "<?xpacket end=\"w\"?>\n"
858 XMPProfileMagick[4]= { (char) 0xef, (char) 0xbb, (char) 0xbf, (char) 0x00 };
861 basename[MaxTextExtent],
862 buffer[MaxTextExtent],
865 page_geometry[MaxTextExtent];
907 register const Quantum
910 register unsigned char
940 Open output image file.
942 assert(image_info != (const ImageInfo *) NULL);
943 assert(image_info->signature == MagickSignature);
944 assert(image != (Image *) NULL);
945 assert(image->signature == MagickSignature);
946 if (image->debug != MagickFalse)
947 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
948 assert(exception != (ExceptionInfo *) NULL);
949 assert(exception->signature == MagickSignature);
950 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
951 if (status == MagickFalse)
954 Allocate X ref memory.
956 xref=(MagickOffsetType *) AcquireQuantumMemory(2048UL,sizeof(*xref));
957 if (xref == (MagickOffsetType *) NULL)
958 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
959 (void) ResetMagickMemory(xref,0,2048UL*sizeof(*xref));
965 if (image_info->compression == JPEG2000Compression)
966 version=(size_t) MagickMax(version,5);
967 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
968 if (next->alpha_trait == BlendPixelTrait)
969 version=(size_t) MagickMax(version,4);
970 if (LocaleCompare(image_info->magick,"PDFA") == 0)
971 version=(size_t) MagickMax(version,6);
972 (void) FormatLocaleString(buffer,MaxTextExtent,"%%PDF-1.%.20g \n",(double)
974 (void) WriteBlobString(image,buffer);
975 if (LocaleCompare(image_info->magick,"PDFA") == 0)
976 (void) WriteBlobString(image,"%âãÏÓ\n");
978 Write Catalog object.
980 xref[object++]=TellBlob(image);
982 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
984 (void) WriteBlobString(image,buffer);
985 (void) WriteBlobString(image,"<<\n");
986 if (LocaleCompare(image_info->magick,"PDFA") != 0)
987 (void) FormatLocaleString(buffer,MaxTextExtent,"/Pages %.20g 0 R\n",(double)
991 (void) FormatLocaleString(buffer,MaxTextExtent,"/Metadata %.20g 0 R\n",
993 (void) WriteBlobString(image,buffer);
994 (void) FormatLocaleString(buffer,MaxTextExtent,"/Pages %.20g 0 R\n",
997 (void) WriteBlobString(image,buffer);
998 (void) WriteBlobString(image,"/Type /Catalog\n");
999 (void) WriteBlobString(image,">>\n");
1000 (void) WriteBlobString(image,"endobj\n");
1001 GetPathComponent(image->filename,BasePath,basename);
1002 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1005 create_date[MaxTextExtent],
1006 modify_date[MaxTextExtent],
1007 timestamp[MaxTextExtent],
1008 xmp_profile[MaxTextExtent];
1016 xref[object++]=TellBlob(image);
1017 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1019 (void) WriteBlobString(image,buffer);
1020 (void) WriteBlobString(image,"<<\n");
1021 (void) WriteBlobString(image,"/Subtype /XML\n");
1023 value=GetImageProperty(image,"date:modify",exception);
1024 if (value != (const char *) NULL)
1025 (void) CopyMagickString(modify_date,value,MaxTextExtent);
1027 value=GetImageProperty(image,"date:create",exception);
1028 if (value != (const char *) NULL)
1029 (void) CopyMagickString(create_date,value,MaxTextExtent);
1030 (void) FormatMagickTime(time((time_t *) NULL),MaxTextExtent,timestamp);
1031 i=FormatLocaleString(xmp_profile,MaxTextExtent,XMPProfile,
1032 XMPProfileMagick,modify_date,create_date,timestamp,
1033 GetMagickVersion(&version),EscapeParenthesis(basename),
1034 GetMagickVersion(&version));
1035 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g\n",(double)
1037 (void) WriteBlobString(image,buffer);
1038 (void) WriteBlobString(image,"/Type /Metadata\n");
1039 (void) WriteBlobString(image,">>\nstream\n");
1040 (void) WriteBlobString(image,xmp_profile);
1041 (void) WriteBlobString(image,"\nendstream\n");
1042 (void) WriteBlobString(image,"endobj\n");
1047 xref[object++]=TellBlob(image);
1049 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1051 (void) WriteBlobString(image,buffer);
1052 (void) WriteBlobString(image,"<<\n");
1053 (void) WriteBlobString(image,"/Type /Pages\n");
1054 (void) FormatLocaleString(buffer,MaxTextExtent,"/Kids [ %.20g 0 R ",(double)
1056 (void) WriteBlobString(image,buffer);
1057 count=(ssize_t) (pages_id+ObjectsPerImage+1);
1058 if (image_info->adjoin != MagickFalse)
1064 Predict page object id's.
1067 for ( ; GetNextImageInList(kid_image) != (Image *) NULL; count+=ObjectsPerImage)
1069 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 R ",(double)
1071 (void) WriteBlobString(image,buffer);
1072 kid_image=GetNextImageInList(kid_image);
1074 xref=(MagickOffsetType *) ResizeQuantumMemory(xref,(size_t) count+2048UL,
1076 if (xref == (MagickOffsetType *) NULL)
1077 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1079 (void) WriteBlobString(image,"]\n");
1080 (void) FormatLocaleString(buffer,MaxTextExtent,"/Count %.20g\n",(double)
1081 ((count-pages_id)/ObjectsPerImage));
1082 (void) WriteBlobString(image,buffer);
1083 (void) WriteBlobString(image,">>\n");
1084 (void) WriteBlobString(image,"endobj\n");
1088 compression=image->compression;
1089 if (image_info->compression != UndefinedCompression)
1090 compression=image_info->compression;
1091 switch (compression)
1093 case FaxCompression:
1094 case Group4Compression:
1096 if ((IsImageMonochrome(image,exception) == MagickFalse) ||
1097 (image->alpha_trait == BlendPixelTrait))
1098 compression=RLECompression;
1101 #if !defined(MAGICKCORE_JPEG_DELEGATE)
1102 case JPEGCompression:
1104 compression=RLECompression;
1105 (void) ThrowMagickException(exception,GetMagickModule(),
1106 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)",
1111 #if !defined(MAGICKCORE_JP2_DELEGATE)
1112 case JPEG2000Compression:
1114 compression=RLECompression;
1115 (void) ThrowMagickException(exception,GetMagickModule(),
1116 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JP2)",
1121 #if !defined(MAGICKCORE_ZLIB_DELEGATE)
1122 case ZipCompression:
1124 compression=RLECompression;
1125 (void) ThrowMagickException(exception,GetMagickModule(),
1126 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (ZLIB)",
1131 case LZWCompression:
1133 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1134 compression=RLECompression; /* LZW compression is forbidden */
1139 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1140 compression=RLECompression; /* ASCII 85 compression is forbidden */
1146 if (compression == JPEG2000Compression)
1148 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
1149 (void) TransformImageColorspace(image,sRGBColorspace,exception);
1152 Scale relative to dots-per-inch.
1154 delta.x=DefaultResolution;
1155 delta.y=DefaultResolution;
1156 resolution.x=image->resolution.x;
1157 resolution.y=image->resolution.y;
1158 if ((resolution.x == 0.0) || (resolution.y == 0.0))
1160 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
1161 resolution.x=geometry_info.rho;
1162 resolution.y=geometry_info.sigma;
1163 if ((flags & SigmaValue) == 0)
1164 resolution.y=resolution.x;
1166 if (image_info->density != (char *) NULL)
1168 flags=ParseGeometry(image_info->density,&geometry_info);
1169 resolution.x=geometry_info.rho;
1170 resolution.y=geometry_info.sigma;
1171 if ((flags & SigmaValue) == 0)
1172 resolution.y=resolution.x;
1174 if (image->units == PixelsPerCentimeterResolution)
1176 resolution.x=(double) ((size_t) (100.0*2.54*resolution.x+0.5)/100.0);
1177 resolution.y=(double) ((size_t) (100.0*2.54*resolution.y+0.5)/100.0);
1179 SetGeometry(image,&geometry);
1180 (void) FormatLocaleString(page_geometry,MaxTextExtent,"%.20gx%.20g",(double)
1181 image->columns,(double) image->rows);
1182 if (image_info->page != (char *) NULL)
1183 (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent);
1185 if ((image->page.width != 0) && (image->page.height != 0))
1186 (void) FormatLocaleString(page_geometry,MaxTextExtent,
1187 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
1188 image->page.height,(double) image->page.x,(double) image->page.y);
1190 if ((image->gravity != UndefinedGravity) &&
1191 (LocaleCompare(image_info->magick,"PDF") == 0))
1192 (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent);
1193 (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent);
1194 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
1195 &geometry.width,&geometry.height);
1196 scale.x=(double) (geometry.width*delta.x)/resolution.x;
1197 geometry.width=(size_t) floor(scale.x+0.5);
1198 scale.y=(double) (geometry.height*delta.y)/resolution.y;
1199 geometry.height=(size_t) floor(scale.y+0.5);
1200 (void) ParseAbsoluteGeometry(page_geometry,&media_info);
1201 (void) ParseGravityGeometry(image,page_geometry,&page_info,exception);
1202 if (image->gravity != UndefinedGravity)
1204 geometry.x=(-page_info.x);
1205 geometry.y=(ssize_t) (media_info.height+page_info.y-image->rows);
1208 if (image_info->pointsize != 0.0)
1209 pointsize=image_info->pointsize;
1211 value=GetImageProperty(image,"label",exception);
1212 if (value != (const char *) NULL)
1213 text_size=(size_t) (MultilineCensus(value)*pointsize+12);
1218 xref[object++]=TellBlob(image);
1219 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1221 (void) WriteBlobString(image,buffer);
1222 (void) WriteBlobString(image,"<<\n");
1223 (void) WriteBlobString(image,"/Type /Page\n");
1224 (void) FormatLocaleString(buffer,MaxTextExtent,"/Parent %.20g 0 R\n",
1226 (void) WriteBlobString(image,buffer);
1227 (void) WriteBlobString(image,"/Resources <<\n");
1228 labels=(char **) NULL;
1229 value=GetImageProperty(image,"label",exception);
1230 if (value != (const char *) NULL)
1231 labels=StringToList(value);
1232 if (labels != (char **) NULL)
1234 (void) FormatLocaleString(buffer,MaxTextExtent,
1235 "/Font << /F%.20g %.20g 0 R >>\n",(double) image->scene,(double)
1237 (void) WriteBlobString(image,buffer);
1239 (void) FormatLocaleString(buffer,MaxTextExtent,
1240 "/XObject << /Im%.20g %.20g 0 R >>\n",(double) image->scene,(double)
1242 (void) WriteBlobString(image,buffer);
1243 (void) FormatLocaleString(buffer,MaxTextExtent,"/ProcSet %.20g 0 R >>\n",
1245 (void) WriteBlobString(image,buffer);
1246 (void) FormatLocaleString(buffer,MaxTextExtent,
1247 "/MediaBox [0 0 %g %g]\n",72.0*media_info.width/resolution.x,
1248 72.0*media_info.height/resolution.y);
1249 (void) WriteBlobString(image,buffer);
1250 (void) FormatLocaleString(buffer,MaxTextExtent,
1251 "/CropBox [0 0 %g %g]\n",72.0*media_info.width/resolution.x,
1252 72.0*media_info.height/resolution.y);
1253 (void) WriteBlobString(image,buffer);
1254 (void) FormatLocaleString(buffer,MaxTextExtent,"/Contents %.20g 0 R\n",
1256 (void) WriteBlobString(image,buffer);
1257 (void) FormatLocaleString(buffer,MaxTextExtent,"/Thumb %.20g 0 R\n",(double)
1259 (void) WriteBlobString(image,buffer);
1260 (void) WriteBlobString(image,">>\n");
1261 (void) WriteBlobString(image,"endobj\n");
1263 Write Contents object.
1265 xref[object++]=TellBlob(image);
1266 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1268 (void) WriteBlobString(image,buffer);
1269 (void) WriteBlobString(image,"<<\n");
1270 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1272 (void) WriteBlobString(image,buffer);
1273 (void) WriteBlobString(image,">>\n");
1274 (void) WriteBlobString(image,"stream\n");
1275 offset=TellBlob(image);
1276 (void) WriteBlobString(image,"q\n");
1277 if (labels != (char **) NULL)
1278 for (i=0; labels[i] != (char *) NULL; i++)
1280 (void) WriteBlobString(image,"BT\n");
1281 (void) FormatLocaleString(buffer,MaxTextExtent,"/F%.20g %g Tf\n",
1282 (double) image->scene,pointsize);
1283 (void) WriteBlobString(image,buffer);
1284 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g Td\n",
1285 (double) geometry.x,(double) (geometry.y+geometry.height+i*pointsize+
1287 (void) WriteBlobString(image,buffer);
1288 (void) FormatLocaleString(buffer,MaxTextExtent,"(%s) Tj\n",labels[i]);
1289 (void) WriteBlobString(image,buffer);
1290 (void) WriteBlobString(image,"ET\n");
1291 labels[i]=DestroyString(labels[i]);
1293 (void) FormatLocaleString(buffer,MaxTextExtent,"%g 0 0 %g %.20g %.20g cm\n",
1294 scale.x,scale.y,(double) geometry.x,(double) geometry.y);
1295 (void) WriteBlobString(image,buffer);
1296 (void) FormatLocaleString(buffer,MaxTextExtent,"/Im%.20g Do\n",(double)
1298 (void) WriteBlobString(image,buffer);
1299 (void) WriteBlobString(image,"Q\n");
1300 offset=TellBlob(image)-offset;
1301 (void) WriteBlobString(image,"\nendstream\n");
1302 (void) WriteBlobString(image,"endobj\n");
1304 Write Length object.
1306 xref[object++]=TellBlob(image);
1307 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1309 (void) WriteBlobString(image,buffer);
1310 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
1311 (void) WriteBlobString(image,buffer);
1312 (void) WriteBlobString(image,"endobj\n");
1314 Write Procset object.
1316 xref[object++]=TellBlob(image);
1317 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1319 (void) WriteBlobString(image,buffer);
1320 if ((image->storage_class == DirectClass) || (image->colors > 256))
1321 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageC",MaxTextExtent);
1323 if ((compression == FaxCompression) || (compression == Group4Compression))
1324 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageB",MaxTextExtent);
1326 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageI",MaxTextExtent);
1327 (void) WriteBlobString(image,buffer);
1328 (void) WriteBlobString(image," ]\n");
1329 (void) WriteBlobString(image,"endobj\n");
1333 xref[object++]=TellBlob(image);
1334 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1336 (void) WriteBlobString(image,buffer);
1337 (void) WriteBlobString(image,"<<\n");
1338 if (labels != (char **) NULL)
1340 (void) WriteBlobString(image,"/Type /Font\n");
1341 (void) WriteBlobString(image,"/Subtype /Type1\n");
1342 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /F%.20g\n",
1343 (double) image->scene);
1344 (void) WriteBlobString(image,buffer);
1345 (void) WriteBlobString(image,"/BaseFont /Helvetica\n");
1346 (void) WriteBlobString(image,"/Encoding /MacRomanEncoding\n");
1347 labels=(char **) RelinquishMagickMemory(labels);
1349 (void) WriteBlobString(image,">>\n");
1350 (void) WriteBlobString(image,"endobj\n");
1352 Write XObject object.
1354 xref[object++]=TellBlob(image);
1355 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1357 (void) WriteBlobString(image,buffer);
1358 (void) WriteBlobString(image,"<<\n");
1359 (void) WriteBlobString(image,"/Type /XObject\n");
1360 (void) WriteBlobString(image,"/Subtype /Image\n");
1361 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /Im%.20g\n",(double)
1363 (void) WriteBlobString(image,buffer);
1364 switch (compression)
1368 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1371 case JPEGCompression:
1373 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1374 if (image->colorspace != CMYKColorspace)
1376 (void) WriteBlobString(image,buffer);
1377 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1381 case JPEG2000Compression:
1383 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1384 if (image->colorspace != CMYKColorspace)
1386 (void) WriteBlobString(image,buffer);
1387 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1391 case LZWCompression:
1393 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1396 case ZipCompression:
1398 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1401 case FaxCompression:
1402 case Group4Compression:
1404 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1406 (void) WriteBlobString(image,buffer);
1407 (void) FormatLocaleString(buffer,MaxTextExtent,"/DecodeParms [ << "
1408 "/K %s /BlackIs1 false /Columns %.20g /Rows %.20g >> ]\n",CCITTParam,
1409 (double) image->columns,(double) image->rows);
1414 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
1419 (void) WriteBlobString(image,buffer);
1420 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
1422 (void) WriteBlobString(image,buffer);
1423 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",(double)
1425 (void) WriteBlobString(image,buffer);
1426 (void) FormatLocaleString(buffer,MaxTextExtent,"/ColorSpace %.20g 0 R\n",
1428 (void) WriteBlobString(image,buffer);
1429 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
1430 (compression == FaxCompression) || (compression == Group4Compression) ?
1432 (void) WriteBlobString(image,buffer);
1433 if (image->alpha_trait == BlendPixelTrait)
1435 (void) FormatLocaleString(buffer,MaxTextExtent,"/SMask %.20g 0 R\n",
1437 (void) WriteBlobString(image,buffer);
1439 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1441 (void) WriteBlobString(image,buffer);
1442 (void) WriteBlobString(image,">>\n");
1443 (void) WriteBlobString(image,"stream\n");
1444 offset=TellBlob(image);
1445 number_pixels=(MagickSizeType) image->columns*image->rows;
1446 if ((4*number_pixels) != (MagickSizeType) ((size_t) (4*number_pixels)))
1447 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1448 if ((compression == FaxCompression) || (compression == Group4Compression) ||
1449 ((image_info->type != TrueColorType) &&
1450 (IsImageGray(image,exception) != MagickFalse)))
1452 switch (compression)
1454 case FaxCompression:
1455 case Group4Compression:
1457 if (LocaleCompare(CCITTParam,"0") == 0)
1459 (void) HuffmanEncodeImage(image_info,image,image,exception);
1462 (void) Huffman2DEncodeImage(image_info,image,image,exception);
1465 case JPEGCompression:
1467 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
1468 if (status == MagickFalse)
1470 (void) CloseBlob(image);
1471 return(MagickFalse);
1475 case JPEG2000Compression:
1477 status=InjectImageBlob(image_info,image,image,"jp2",exception);
1478 if (status == MagickFalse)
1480 (void) CloseBlob(image);
1481 return(MagickFalse);
1485 case RLECompression:
1489 Allocate pixel array.
1491 length=(size_t) number_pixels;
1492 pixels=(unsigned char *) AcquireQuantumMemory(length,
1494 if (pixels == (unsigned char *) NULL)
1495 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1497 Dump Runlength encoded pixels.
1500 for (y=0; y < (ssize_t) image->rows; y++)
1502 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1503 if (p == (const Quantum *) NULL)
1505 for (x=0; x < (ssize_t) image->columns; x++)
1507 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
1508 p+=GetPixelChannels(image);
1510 if (image->previous == (Image *) NULL)
1512 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1514 if (status == MagickFalse)
1518 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1519 if (compression == ZipCompression)
1520 status=ZLIBEncodeImage(image,length,pixels,exception);
1523 if (compression == LZWCompression)
1524 status=LZWEncodeImage(image,length,pixels,exception);
1526 status=PackbitsEncodeImage(image,length,pixels,exception);
1527 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1528 if (status == MagickFalse)
1530 (void) CloseBlob(image);
1531 return(MagickFalse);
1538 Dump uncompressed PseudoColor packets.
1540 Ascii85Initialize(image);
1541 for (y=0; y < (ssize_t) image->rows; y++)
1543 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1544 if (p == (const Quantum *) NULL)
1546 for (x=0; x < (ssize_t) image->columns; x++)
1548 Ascii85Encode(image,ScaleQuantumToChar(
1549 GetPixelIntensity(image,p)));
1550 p+=GetPixelChannels(image);
1552 if (image->previous == (Image *) NULL)
1554 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1556 if (status == MagickFalse)
1560 Ascii85Flush(image);
1566 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1567 (compression == JPEGCompression) ||
1568 (compression == JPEG2000Compression))
1569 switch (compression)
1571 case JPEGCompression:
1573 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
1574 if (status == MagickFalse)
1576 (void) CloseBlob(image);
1577 return(MagickFalse);
1581 case JPEG2000Compression:
1583 status=InjectImageBlob(image_info,image,image,"jp2",exception);
1584 if (status == MagickFalse)
1586 (void) CloseBlob(image);
1587 return(MagickFalse);
1591 case RLECompression:
1595 Allocate pixel array.
1597 length=(size_t) number_pixels;
1598 pixels=(unsigned char *) AcquireQuantumMemory(length,
1600 length*=image->colorspace == CMYKColorspace ? 4UL : 3UL;
1601 if (pixels == (unsigned char *) NULL)
1602 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1604 Dump runoffset encoded pixels.
1607 for (y=0; y < (ssize_t) image->rows; y++)
1609 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1610 if (p == (const Quantum *) NULL)
1612 for (x=0; x < (ssize_t) image->columns; x++)
1614 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1615 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1616 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1617 if (image->colorspace == CMYKColorspace)
1618 *q++=ScaleQuantumToChar(GetPixelBlack(image,p));
1619 p+=GetPixelChannels(image);
1621 if (image->previous == (Image *) NULL)
1623 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1625 if (status == MagickFalse)
1629 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1630 if (compression == ZipCompression)
1631 status=ZLIBEncodeImage(image,length,pixels,exception);
1634 if (compression == LZWCompression)
1635 status=LZWEncodeImage(image,length,pixels,exception);
1637 status=PackbitsEncodeImage(image,length,pixels,exception);
1638 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1639 if (status == MagickFalse)
1641 (void) CloseBlob(image);
1642 return(MagickFalse);
1649 Dump uncompressed DirectColor packets.
1651 Ascii85Initialize(image);
1652 for (y=0; y < (ssize_t) image->rows; y++)
1654 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1655 if (p == (const Quantum *) NULL)
1657 for (x=0; x < (ssize_t) image->columns; x++)
1659 Ascii85Encode(image,ScaleQuantumToChar(GetPixelRed(image,p)));
1660 Ascii85Encode(image,ScaleQuantumToChar(GetPixelGreen(image,p)));
1661 Ascii85Encode(image,ScaleQuantumToChar(GetPixelBlue(image,p)));
1662 if (image->colorspace == CMYKColorspace)
1663 Ascii85Encode(image,ScaleQuantumToChar(
1664 GetPixelBlack(image,p)));
1665 p+=GetPixelChannels(image);
1667 if (image->previous == (Image *) NULL)
1669 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1671 if (status == MagickFalse)
1675 Ascii85Flush(image);
1682 Dump number of colors and colormap.
1684 switch (compression)
1686 case RLECompression:
1690 Allocate pixel array.
1692 length=(size_t) number_pixels;
1693 pixels=(unsigned char *) AcquireQuantumMemory(length,
1695 if (pixels == (unsigned char *) NULL)
1696 ThrowWriterException(ResourceLimitError,
1697 "MemoryAllocationFailed");
1699 Dump Runlength encoded pixels.
1702 for (y=0; y < (ssize_t) image->rows; y++)
1704 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1705 if (p == (const Quantum *) NULL)
1707 for (x=0; x < (ssize_t) image->columns; x++)
1709 *q++=(unsigned char) GetPixelIndex(image,p);
1710 p+=GetPixelChannels(image);
1712 if (image->previous == (Image *) NULL)
1714 status=SetImageProgress(image,SaveImageTag,
1715 (MagickOffsetType) y,image->rows);
1716 if (status == MagickFalse)
1720 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1721 if (compression == ZipCompression)
1722 status=ZLIBEncodeImage(image,length,pixels,exception);
1725 if (compression == LZWCompression)
1726 status=LZWEncodeImage(image,length,pixels,exception);
1728 status=PackbitsEncodeImage(image,length,pixels,exception);
1729 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1730 if (status == MagickFalse)
1732 (void) CloseBlob(image);
1733 return(MagickFalse);
1740 Dump uncompressed PseudoColor packets.
1742 Ascii85Initialize(image);
1743 for (y=0; y < (ssize_t) image->rows; y++)
1745 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1746 if (p == (const Quantum *) NULL)
1748 for (x=0; x < (ssize_t) image->columns; x++)
1750 Ascii85Encode(image,(unsigned char) GetPixelIndex(image,p));
1751 p+=GetPixelChannels(image);
1753 if (image->previous == (Image *) NULL)
1755 status=SetImageProgress(image,SaveImageTag,
1756 (MagickOffsetType) y,image->rows);
1757 if (status == MagickFalse)
1761 Ascii85Flush(image);
1766 offset=TellBlob(image)-offset;
1767 (void) WriteBlobString(image,"\nendstream\n");
1768 (void) WriteBlobString(image,"endobj\n");
1770 Write Length object.
1772 xref[object++]=TellBlob(image);
1773 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1775 (void) WriteBlobString(image,buffer);
1776 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
1777 (void) WriteBlobString(image,buffer);
1778 (void) WriteBlobString(image,"endobj\n");
1780 Write Colorspace object.
1782 xref[object++]=TellBlob(image);
1783 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1785 (void) WriteBlobString(image,buffer);
1786 if (image->colorspace == CMYKColorspace)
1787 (void) CopyMagickString(buffer,"/DeviceCMYK\n",MaxTextExtent);
1789 if ((compression == FaxCompression) ||
1790 (compression == Group4Compression) ||
1791 ((image_info->type != TrueColorType) &&
1792 (IsImageGray(image,exception) != MagickFalse)))
1793 (void) CopyMagickString(buffer,"/DeviceGray\n",MaxTextExtent);
1795 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1796 (compression == JPEGCompression) ||
1797 (compression == JPEG2000Compression))
1798 (void) CopyMagickString(buffer,"/DeviceRGB\n",MaxTextExtent);
1800 (void) FormatLocaleString(buffer,MaxTextExtent,
1801 "[ /Indexed /DeviceRGB %.20g %.20g 0 R ]\n",(double) image->colors-
1802 1,(double) object+3);
1803 (void) WriteBlobString(image,buffer);
1804 (void) WriteBlobString(image,"endobj\n");
1808 SetGeometry(image,&geometry);
1809 (void) ParseMetaGeometry("106x106+0+0>",&geometry.x,&geometry.y,
1810 &geometry.width,&geometry.height);
1811 tile_image=ThumbnailImage(image,geometry.width,geometry.height,exception);
1812 if (tile_image == (Image *) NULL)
1813 return(MagickFalse);
1814 xref[object++]=TellBlob(image);
1815 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1817 (void) WriteBlobString(image,buffer);
1818 (void) WriteBlobString(image,"<<\n");
1819 switch (compression)
1823 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1826 case JPEGCompression:
1828 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1829 if (image->colorspace != CMYKColorspace)
1831 (void) WriteBlobString(image,buffer);
1832 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1836 case JPEG2000Compression:
1838 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1839 if (image->colorspace != CMYKColorspace)
1841 (void) WriteBlobString(image,buffer);
1842 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1846 case LZWCompression:
1848 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1851 case ZipCompression:
1853 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1856 case FaxCompression:
1857 case Group4Compression:
1859 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1861 (void) WriteBlobString(image,buffer);
1862 (void) FormatLocaleString(buffer,MaxTextExtent,"/DecodeParms [ << "
1863 "/K %s /BlackIs1 false /Columns %.20g /Rows %.20g >> ]\n",CCITTParam,
1864 (double) tile_image->columns,(double) tile_image->rows);
1869 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
1874 (void) WriteBlobString(image,buffer);
1875 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
1876 tile_image->columns);
1877 (void) WriteBlobString(image,buffer);
1878 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",(double)
1880 (void) WriteBlobString(image,buffer);
1881 (void) FormatLocaleString(buffer,MaxTextExtent,"/ColorSpace %.20g 0 R\n",
1883 (void) WriteBlobString(image,buffer);
1884 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
1885 (compression == FaxCompression) || (compression == Group4Compression) ?
1887 (void) WriteBlobString(image,buffer);
1888 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1890 (void) WriteBlobString(image,buffer);
1891 (void) WriteBlobString(image,">>\n");
1892 (void) WriteBlobString(image,"stream\n");
1893 offset=TellBlob(image);
1894 number_pixels=(MagickSizeType) tile_image->columns*tile_image->rows;
1895 if ((compression == FaxCompression) ||
1896 (compression == Group4Compression) ||
1897 ((image_info->type != TrueColorType) &&
1898 (IsImageGray(tile_image,exception) != MagickFalse)))
1900 switch (compression)
1902 case FaxCompression:
1903 case Group4Compression:
1905 if (LocaleCompare(CCITTParam,"0") == 0)
1907 (void) HuffmanEncodeImage(image_info,image,tile_image,
1911 (void) Huffman2DEncodeImage(image_info,image,tile_image,exception);
1914 case JPEGCompression:
1916 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
1918 if (status == MagickFalse)
1920 (void) CloseBlob(image);
1921 return(MagickFalse);
1925 case JPEG2000Compression:
1927 status=InjectImageBlob(image_info,image,tile_image,"jp2",exception);
1928 if (status == MagickFalse)
1930 (void) CloseBlob(image);
1931 return(MagickFalse);
1935 case RLECompression:
1939 Allocate pixel array.
1941 length=(size_t) number_pixels;
1942 pixels=(unsigned char *) AcquireQuantumMemory(length,
1944 if (pixels == (unsigned char *) NULL)
1946 tile_image=DestroyImage(tile_image);
1947 ThrowWriterException(ResourceLimitError,
1948 "MemoryAllocationFailed");
1951 Dump Runlength encoded pixels.
1954 for (y=0; y < (ssize_t) tile_image->rows; y++)
1956 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
1958 if (p == (const Quantum *) NULL)
1960 for (x=0; x < (ssize_t) tile_image->columns; x++)
1962 *q++=ScaleQuantumToChar(GetPixelIntensity(tile_image,p));
1963 p+=GetPixelChannels(tile_image);
1966 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1967 if (compression == ZipCompression)
1968 status=ZLIBEncodeImage(image,length,pixels,exception);
1971 if (compression == LZWCompression)
1972 status=LZWEncodeImage(image,length,pixels,exception);
1974 status=PackbitsEncodeImage(image,length,pixels,exception);
1975 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1976 if (status == MagickFalse)
1978 (void) CloseBlob(image);
1979 return(MagickFalse);
1986 Dump uncompressed PseudoColor packets.
1988 Ascii85Initialize(image);
1989 for (y=0; y < (ssize_t) tile_image->rows; y++)
1991 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
1993 if (p == (const Quantum *) NULL)
1995 for (x=0; x < (ssize_t) tile_image->columns; x++)
1997 Ascii85Encode(image,
1998 ScaleQuantumToChar(GetPixelIntensity(tile_image,p)));
1999 p+=GetPixelChannels(tile_image);
2002 Ascii85Flush(image);
2008 if ((tile_image->storage_class == DirectClass) ||
2009 (tile_image->colors > 256) || (compression == JPEGCompression) ||
2010 (compression == JPEG2000Compression))
2011 switch (compression)
2013 case JPEGCompression:
2015 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
2017 if (status == MagickFalse)
2019 (void) CloseBlob(image);
2020 return(MagickFalse);
2024 case JPEG2000Compression:
2026 status=InjectImageBlob(image_info,image,tile_image,"jp2",exception);
2027 if (status == MagickFalse)
2029 (void) CloseBlob(image);
2030 return(MagickFalse);
2034 case RLECompression:
2038 Allocate pixel array.
2040 length=(size_t) number_pixels;
2041 pixels=(unsigned char *) AcquireQuantumMemory(length,4*
2043 length*=tile_image->colorspace == CMYKColorspace ? 4UL : 3UL;
2044 if (pixels == (unsigned char *) NULL)
2046 tile_image=DestroyImage(tile_image);
2047 ThrowWriterException(ResourceLimitError,
2048 "MemoryAllocationFailed");
2051 Dump runoffset encoded pixels.
2054 for (y=0; y < (ssize_t) tile_image->rows; y++)
2056 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2058 if (p == (const Quantum *) NULL)
2060 for (x=0; x < (ssize_t) tile_image->columns; x++)
2062 *q++=ScaleQuantumToChar(GetPixelRed(tile_image,p));
2063 *q++=ScaleQuantumToChar(GetPixelGreen(tile_image,p));
2064 *q++=ScaleQuantumToChar(GetPixelBlue(tile_image,p));
2065 if (image->colorspace == CMYKColorspace)
2066 *q++=ScaleQuantumToChar(GetPixelBlack(tile_image,p));
2067 p+=GetPixelChannels(tile_image);
2070 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2071 if (compression == ZipCompression)
2072 status=ZLIBEncodeImage(image,length,pixels,exception);
2075 if (compression == LZWCompression)
2076 status=LZWEncodeImage(image,length,pixels,exception);
2078 status=PackbitsEncodeImage(image,length,pixels,exception);
2079 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2080 if (status == MagickFalse)
2082 (void) CloseBlob(image);
2083 return(MagickFalse);
2090 Dump uncompressed DirectColor packets.
2092 Ascii85Initialize(image);
2093 for (y=0; y < (ssize_t) tile_image->rows; y++)
2095 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2097 if (p == (const Quantum *) NULL)
2099 for (x=0; x < (ssize_t) tile_image->columns; x++)
2101 Ascii85Encode(image,ScaleQuantumToChar(
2102 GetPixelRed(tile_image,p)));
2103 Ascii85Encode(image,ScaleQuantumToChar(
2104 GetPixelGreen(tile_image,p)));
2105 Ascii85Encode(image,ScaleQuantumToChar(
2106 GetPixelBlue(tile_image,p)));
2107 if (image->colorspace == CMYKColorspace)
2108 Ascii85Encode(image,ScaleQuantumToChar(
2109 GetPixelBlack(tile_image,p)));
2110 p+=GetPixelChannels(tile_image);
2113 Ascii85Flush(image);
2120 Dump number of colors and colormap.
2122 switch (compression)
2124 case RLECompression:
2128 Allocate pixel array.
2130 length=(size_t) number_pixels;
2131 pixels=(unsigned char *) AcquireQuantumMemory(length,
2133 if (pixels == (unsigned char *) NULL)
2135 tile_image=DestroyImage(tile_image);
2136 ThrowWriterException(ResourceLimitError,
2137 "MemoryAllocationFailed");
2140 Dump Runlength encoded pixels.
2143 for (y=0; y < (ssize_t) tile_image->rows; y++)
2145 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2147 if (p == (const Quantum *) NULL)
2149 for (x=0; x < (ssize_t) tile_image->columns; x++)
2151 *q++=(unsigned char) GetPixelIndex(tile_image,p);
2152 p+=GetPixelChannels(tile_image);
2155 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2156 if (compression == ZipCompression)
2157 status=ZLIBEncodeImage(image,length,pixels,exception);
2160 if (compression == LZWCompression)
2161 status=LZWEncodeImage(image,length,pixels,exception);
2163 status=PackbitsEncodeImage(image,length,pixels,exception);
2164 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2165 if (status == MagickFalse)
2167 (void) CloseBlob(image);
2168 return(MagickFalse);
2175 Dump uncompressed PseudoColor packets.
2177 Ascii85Initialize(image);
2178 for (y=0; y < (ssize_t) tile_image->rows; y++)
2180 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2182 if (p == (const Quantum *) NULL)
2184 for (x=0; x < (ssize_t) tile_image->columns; x++)
2186 Ascii85Encode(image,(unsigned char)
2187 GetPixelIndex(tile_image,p));
2188 p+=GetPixelChannels(image);
2191 Ascii85Flush(image);
2196 tile_image=DestroyImage(tile_image);
2197 offset=TellBlob(image)-offset;
2198 (void) WriteBlobString(image,"\nendstream\n");
2199 (void) WriteBlobString(image,"endobj\n");
2201 Write Length object.
2203 xref[object++]=TellBlob(image);
2204 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2206 (void) WriteBlobString(image,buffer);
2207 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2208 (void) WriteBlobString(image,buffer);
2209 (void) WriteBlobString(image,"endobj\n");
2210 xref[object++]=TellBlob(image);
2211 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2213 (void) WriteBlobString(image,buffer);
2214 (void) WriteBlobString(image,"<<\n");
2215 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
2216 (compression == FaxCompression) || (compression == Group4Compression))
2217 (void) WriteBlobString(image,">>\n");
2221 Write Colormap object.
2223 if (compression == NoCompression)
2224 (void) WriteBlobString(image,"/Filter [ /ASCII85Decode ]\n");
2225 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
2227 (void) WriteBlobString(image,buffer);
2228 (void) WriteBlobString(image,">>\n");
2229 (void) WriteBlobString(image,"stream\n");
2230 offset=TellBlob(image);
2231 if (compression == NoCompression)
2232 Ascii85Initialize(image);
2233 for (i=0; i < (ssize_t) image->colors; i++)
2235 if (compression == NoCompression)
2237 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].red));
2238 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].green));
2239 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].blue));
2242 (void) WriteBlobByte(image,
2243 ScaleQuantumToChar(image->colormap[i].red));
2244 (void) WriteBlobByte(image,
2245 ScaleQuantumToChar(image->colormap[i].green));
2246 (void) WriteBlobByte(image,
2247 ScaleQuantumToChar(image->colormap[i].blue));
2249 if (compression == NoCompression)
2250 Ascii85Flush(image);
2251 offset=TellBlob(image)-offset;
2252 (void) WriteBlobString(image,"\nendstream\n");
2254 (void) WriteBlobString(image,"endobj\n");
2256 Write Length object.
2258 xref[object++]=TellBlob(image);
2259 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2261 (void) WriteBlobString(image,buffer);
2262 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double)
2264 (void) WriteBlobString(image,buffer);
2265 (void) WriteBlobString(image,"endobj\n");
2267 Write softmask object.
2269 xref[object++]=TellBlob(image);
2270 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2272 (void) WriteBlobString(image,buffer);
2273 (void) WriteBlobString(image,"<<\n");
2274 if (image->alpha_trait != BlendPixelTrait)
2275 (void) WriteBlobString(image,">>\n");
2278 (void) WriteBlobString(image,"/Type /XObject\n");
2279 (void) WriteBlobString(image,"/Subtype /Image\n");
2280 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /Ma%.20g\n",
2281 (double) image->scene);
2282 (void) WriteBlobString(image,buffer);
2283 switch (compression)
2287 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
2291 case LZWCompression:
2293 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
2296 case ZipCompression:
2298 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
2304 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
2309 (void) WriteBlobString(image,buffer);
2310 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
2312 (void) WriteBlobString(image,buffer);
2313 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",
2314 (double) image->rows);
2315 (void) WriteBlobString(image,buffer);
2316 (void) WriteBlobString(image,"/ColorSpace /DeviceGray\n");
2317 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
2318 (compression == FaxCompression) || (compression == Group4Compression)
2320 (void) WriteBlobString(image,buffer);
2321 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
2323 (void) WriteBlobString(image,buffer);
2324 (void) WriteBlobString(image,">>\n");
2325 (void) WriteBlobString(image,"stream\n");
2326 offset=TellBlob(image);
2327 number_pixels=(MagickSizeType) image->columns*image->rows;
2328 switch (compression)
2330 case RLECompression:
2334 Allocate pixel array.
2336 length=(size_t) number_pixels;
2337 pixels=(unsigned char *) AcquireQuantumMemory(length,
2339 if (pixels == (unsigned char *) NULL)
2341 image=DestroyImage(image);
2342 ThrowWriterException(ResourceLimitError,
2343 "MemoryAllocationFailed");
2346 Dump Runlength encoded pixels.
2349 for (y=0; y < (ssize_t) image->rows; y++)
2351 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2352 if (p == (const Quantum *) NULL)
2354 for (x=0; x < (ssize_t) image->columns; x++)
2356 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
2357 p+=GetPixelChannels(image);
2360 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2361 if (compression == ZipCompression)
2362 status=ZLIBEncodeImage(image,length,pixels,exception);
2365 if (compression == LZWCompression)
2366 status=LZWEncodeImage(image,length,pixels,exception);
2368 status=PackbitsEncodeImage(image,length,pixels,exception);
2369 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2370 if (status == MagickFalse)
2372 (void) CloseBlob(image);
2373 return(MagickFalse);
2380 Dump uncompressed PseudoColor packets.
2382 Ascii85Initialize(image);
2383 for (y=0; y < (ssize_t) image->rows; y++)
2385 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2386 if (p == (const Quantum *) NULL)
2388 for (x=0; x < (ssize_t) image->columns; x++)
2390 Ascii85Encode(image,ScaleQuantumToChar(GetPixelAlpha(image,p)));
2391 p+=GetPixelChannels(image);
2394 Ascii85Flush(image);
2398 offset=TellBlob(image)-offset;
2399 (void) WriteBlobString(image,"\nendstream\n");
2401 (void) WriteBlobString(image,"endobj\n");
2403 Write Length object.
2405 xref[object++]=TellBlob(image);
2406 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2408 (void) WriteBlobString(image,buffer);
2409 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2410 (void) WriteBlobString(image,buffer);
2411 (void) WriteBlobString(image,"endobj\n");
2412 if (GetNextImageInList(image) == (Image *) NULL)
2414 image=SyncNextImageInList(image);
2415 status=SetImageProgress(image,SaveImagesTag,scene++,
2416 GetImageListLength(image));
2417 if (status == MagickFalse)
2419 } while (image_info->adjoin != MagickFalse);
2421 Write Metadata object.
2423 xref[object++]=TellBlob(image);
2425 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2427 (void) WriteBlobString(image,buffer);
2428 (void) WriteBlobString(image,"<<\n");
2429 (void) FormatLocaleString(buffer,MaxTextExtent,"/Title (%s)\n",
2430 EscapeParenthesis(basename));
2431 (void) WriteBlobString(image,buffer);
2432 seconds=time((time_t *) NULL);
2433 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
2434 (void) localtime_r(&seconds,&local_time);
2436 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
2438 (void) FormatLocaleString(date,MaxTextExtent,"D:%04d%02d%02d%02d%02d%02d",
2439 local_time.tm_year+1900,local_time.tm_mon+1,local_time.tm_mday,
2440 local_time.tm_hour,local_time.tm_min,local_time.tm_sec);
2441 (void) FormatLocaleString(buffer,MaxTextExtent,"/CreationDate (%s)\n",date);
2442 (void) WriteBlobString(image,buffer);
2443 (void) FormatLocaleString(buffer,MaxTextExtent,"/ModDate (%s)\n",date);
2444 (void) WriteBlobString(image,buffer);
2445 (void) FormatLocaleString(buffer,MaxTextExtent,"/Producer (%s)\n",
2446 EscapeParenthesis(GetMagickVersion((size_t *) NULL)));
2447 (void) WriteBlobString(image,buffer);
2448 (void) WriteBlobString(image,">>\n");
2449 (void) WriteBlobString(image,"endobj\n");
2453 offset=TellBlob(image)-xref[0]+
2454 (LocaleCompare(image_info->magick,"PDFA") == 0 ? 6 : 0)+10;
2455 (void) WriteBlobString(image,"xref\n");
2456 (void) FormatLocaleString(buffer,MaxTextExtent,"0 %.20g\n",(double)
2458 (void) WriteBlobString(image,buffer);
2459 (void) WriteBlobString(image,"0000000000 65535 f \n");
2460 for (i=0; i < (ssize_t) object; i++)
2462 (void) FormatLocaleString(buffer,MaxTextExtent,"%010lu 00000 n \n",
2463 (unsigned long) xref[i]);
2464 (void) WriteBlobString(image,buffer);
2466 (void) WriteBlobString(image,"trailer\n");
2467 (void) WriteBlobString(image,"<<\n");
2468 (void) FormatLocaleString(buffer,MaxTextExtent,"/Size %.20g\n",(double)
2470 (void) WriteBlobString(image,buffer);
2471 (void) FormatLocaleString(buffer,MaxTextExtent,"/Info %.20g 0 R\n",(double)
2473 (void) WriteBlobString(image,buffer);
2474 (void) FormatLocaleString(buffer,MaxTextExtent,"/Root %.20g 0 R\n",(double)
2476 (void) WriteBlobString(image,buffer);
2477 (void) SignatureImage(image,exception);
2478 (void) FormatLocaleString(buffer,MaxTextExtent,"/ID [<%s> <%s>]\n",
2479 GetImageProperty(image,"signature",exception),
2480 GetImageProperty(image,"signature",exception));
2481 (void) WriteBlobString(image,buffer);
2482 (void) WriteBlobString(image,">>\n");
2483 (void) WriteBlobString(image,"startxref\n");
2484 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2485 (void) WriteBlobString(image,buffer);
2486 (void) WriteBlobString(image,"%%EOF\n");
2487 xref=(MagickOffsetType *) RelinquishMagickMemory(xref);
2488 (void) CloseBlob(image);