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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 % I n v o k e P D F D e l e g a t e %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % InvokePDFDelegate() executes the PDF interpreter with the specified command.
110 % The format of the InvokePDFDelegate method is:
112 % MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
113 % const char *command,ExceptionInfo *exception)
115 % A description of each parameter follows:
117 % o verbose: A value other than zero displays the command prior to
120 % o command: the address of a character string containing the command to
123 % o exception: return any errors or warnings in this structure.
126 static MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
127 const char *command,ExceptionInfo *exception)
132 #if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
149 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
150 ghost_info=NTGhostscriptDLLVectors();
155 ghost_info=(&ghost_info_struct);
156 (void) ResetMagickMemory(&ghost_info,0,sizeof(ghost_info));
157 ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
159 ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
160 gsapi_init_with_args;
161 ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
162 int *)) gsapi_run_string;
163 ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
164 gsapi_delete_instance;
165 ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
167 if (ghost_info == (GhostInfo *) NULL)
169 status=SystemCommand(MagickFalse,verbose,command,exception);
170 return(status == 0 ? MagickTrue : MagickFalse);
172 if (verbose != MagickFalse)
174 (void) fputs("[ghostscript library]",stdout);
175 (void) fputs(strchr(command,' '),stdout);
177 status=(ghost_info->new_instance)(&interpreter,(void *) NULL);
180 status=SystemCommand(MagickFalse,verbose,command,exception);
181 return(status == 0 ? MagickTrue : MagickFalse);
184 argv=StringToArgv(command,&argc);
185 if (argv == (char **) NULL)
187 status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
189 status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
191 (ghost_info->exit)(interpreter);
192 (ghost_info->delete_instance)(interpreter);
193 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
194 NTGhostscriptUnLoadDLL();
196 for (i=0; i < (ssize_t) argc; i++)
197 argv[i]=DestroyString(argv[i]);
198 argv=(char **) RelinquishMagickMemory(argv);
199 if ((status != 0) && (status != -101))
204 message=GetExceptionMessage(errno);
205 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
206 "`%s': %s",command,message);
207 message=DestroyString(message);
208 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
209 "Ghostscript returns status %d, exit code %d",status,code);
214 status=SystemCommand(MagickFalse,verbose,command,exception);
215 return(status == 0 ? MagickTrue : MagickFalse);
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 % IsPDF() returns MagickTrue if the image format type, identified by the
231 % magick string, is PDF.
233 % The format of the IsPDF method is:
235 % MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
237 % A description of each parameter follows:
239 % o magick: compare image format pattern against these bytes.
241 % o offset: Specifies the offset of the magick string.
244 static MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
248 if (LocaleNCompare((const char *) magick,"%PDF-",5) == 0)
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % R e a d P D F I m a g e %
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 % ReadPDFImage() reads a Portable Document Format image file and
265 % returns it. It allocates the memory necessary for the new Image structure
266 % and returns a pointer to the new image.
268 % The format of the ReadPDFImage method is:
270 % Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
272 % A description of each parameter follows:
274 % o image_info: the image info.
276 % o exception: return any errors or warnings in this structure.
280 static MagickBooleanType IsPDFRendered(const char *path)
288 if ((path == (const char *) NULL) || (*path == '\0'))
290 status=GetPathAttributes(path,&attributes);
291 if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
292 (attributes.st_size > 0))
297 static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
299 #define CMYKProcessColor "CMYKProcessColor"
300 #define CropBox "CropBox"
301 #define DefaultCMYK "DefaultCMYK"
302 #define DeviceCMYK "DeviceCMYK"
303 #define MediaBox "MediaBox"
304 #define RenderPostscriptText "Rendering Postscript... "
305 #define PDFRotate "Rotate"
306 #define SpotColor "Separation"
307 #define TrimBox "TrimBox"
308 #define PDFVersion "PDF-"
311 command[MaxTextExtent],
312 density[MaxTextExtent],
313 filename[MaxTextExtent],
314 geometry[MaxTextExtent],
315 options[MaxTextExtent],
316 input_filename[MaxTextExtent],
317 postscript_filename[MaxTextExtent];
376 assert(image_info != (const ImageInfo *) NULL);
377 assert(image_info->signature == MagickSignature);
378 if (image_info->debug != MagickFalse)
379 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
380 image_info->filename);
381 assert(exception != (ExceptionInfo *) NULL);
382 assert(exception->signature == MagickSignature);
386 image=AcquireImage(image_info,exception);
387 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
388 if (status == MagickFalse)
390 image=DestroyImageList(image);
391 return((Image *) NULL);
393 status=AcquireUniqueSymbolicLink(image_info->filename,input_filename);
394 if (status == MagickFalse)
396 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
397 image_info->filename);
398 image=DestroyImageList(image);
399 return((Image *) NULL);
402 Set the page density.
404 delta.x=DefaultResolution;
405 delta.y=DefaultResolution;
406 if ((image->resolution.x == 0.0) || (image->resolution.y == 0.0))
408 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
409 image->resolution.x=geometry_info.rho;
410 image->resolution.y=geometry_info.sigma;
411 if ((flags & SigmaValue) == 0)
412 image->resolution.y=image->resolution.x;
414 if (image_info->density != (char *) NULL)
416 flags=ParseGeometry(image_info->density,&geometry_info);
417 image->resolution.x=geometry_info.rho;
418 image->resolution.y=geometry_info.sigma;
419 if ((flags & SigmaValue) == 0)
420 image->resolution.y=image->resolution.x;
422 (void) ParseAbsoluteGeometry(PSPageGeometry,&page);
423 if (image_info->page != (char *) NULL)
424 (void) ParseAbsoluteGeometry(image_info->page,&page);
425 page.width=(size_t) ceil((double) (page.width*image->resolution.x/delta.x)-
427 page.height=(size_t) ceil((double) (page.height*image->resolution.y/delta.y)-
430 Determine page geometry from the PDF media box.
432 cmyk=image_info->colorspace == CMYKColorspace ? MagickTrue : MagickFalse;
433 cropbox=IsStringTrue(GetImageOption(image_info,"pdf:use-cropbox"));
434 trimbox=IsStringTrue(GetImageOption(image_info,"pdf:use-trimbox"));
437 (void) ResetMagickMemory(&bounding_box,0,sizeof(bounding_box));
438 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
439 (void) ResetMagickMemory(&hires_bounds,0,sizeof(hires_bounds));
440 (void) ResetMagickMemory(command,0,sizeof(command));
443 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
451 if ((c != (int) '/') && (c != (int) '%') &&
452 ((size_t) (p-command) < (MaxTextExtent-1)))
456 if (LocaleNCompare(PDFRotate,command,strlen(PDFRotate)) == 0)
457 count=(ssize_t) sscanf(command,"Rotate %lf",&angle);
459 Is this a CMYK document?
461 if (LocaleNCompare(DefaultCMYK,command,strlen(DefaultCMYK)) == 0)
463 if (LocaleNCompare(DeviceCMYK,command,strlen(DeviceCMYK)) == 0)
465 if (LocaleNCompare(CMYKProcessColor,command,strlen(CMYKProcessColor)) == 0)
467 if (LocaleNCompare(SpotColor,command,strlen(SpotColor)) == 0)
471 property[MaxTextExtent],
480 (void) FormatLocaleString(property,MaxTextExtent,"pdf:SpotColor-%.20g",
481 (double) spotcolor++);
483 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
485 if ((isspace(c) != 0) || (c == '/') || ((i+1) == MaxTextExtent))
490 value=AcquireString(name);
491 (void) SubstituteString(&value,"#20"," ");
492 (void) SetImageProperty(image,property,value,exception);
493 value=DestroyString(value);
496 if (LocaleNCompare(PDFVersion,command,strlen(PDFVersion)) == 0)
497 (void) SetImageProperty(image,"pdf:Version",command,exception);
498 if (image_info->page != (char *) NULL)
501 if (cropbox != MagickFalse)
503 if (LocaleNCompare(CropBox,command,strlen(CropBox)) == 0)
506 Note region defined by crop box.
508 count=(ssize_t) sscanf(command,"CropBox [%lf %lf %lf %lf",
509 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
511 count=(ssize_t) sscanf(command,"CropBox[%lf %lf %lf %lf",
512 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
516 if (trimbox != MagickFalse)
518 if (LocaleNCompare(TrimBox,command,strlen(TrimBox)) == 0)
521 Note region defined by trim box.
523 count=(ssize_t) sscanf(command,"TrimBox [%lf %lf %lf %lf",
524 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
526 count=(ssize_t) sscanf(command,"TrimBox[%lf %lf %lf %lf",
527 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
531 if (LocaleNCompare(MediaBox,command,strlen(MediaBox)) == 0)
534 Note region defined by media box.
536 count=(ssize_t) sscanf(command,"MediaBox [%lf %lf %lf %lf",
537 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
539 count=(ssize_t) sscanf(command,"MediaBox[%lf %lf %lf %lf",
540 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
544 if ((fabs(bounds.x2-bounds.x1) <= fabs(hires_bounds.x2-hires_bounds.x1)) ||
545 (fabs(bounds.y2-bounds.y1) <= fabs(hires_bounds.y2-hires_bounds.y1)))
549 if ((fabs(hires_bounds.x2-hires_bounds.x1) >= MagickEpsilon) &&
550 (fabs(hires_bounds.y2-hires_bounds.y1) >= MagickEpsilon))
553 Set PDF render geometry.
555 (void) FormatLocaleString(geometry,MaxTextExtent,"%gx%g%+.15g%+.15g",
556 hires_bounds.x2-bounds.x1,hires_bounds.y2-hires_bounds.y1,
557 hires_bounds.x1,hires_bounds.y1);
558 (void) SetImageProperty(image,"pdf:HiResBoundingBox",geometry,exception);
559 page.width=(size_t) ceil((double) ((hires_bounds.x2-hires_bounds.x1)*
560 image->resolution.x/delta.x)-0.5);
561 page.height=(size_t) ceil((double) ((hires_bounds.y2-hires_bounds.y1)*
562 image->resolution.y/delta.y)-0.5);
564 (void) CloseBlob(image);
565 if ((fabs(angle) == 90.0) || (fabs(angle) == 270.0))
571 page.width=page.height;
574 if (IssRGBCompatibleColorspace(image_info->colorspace) != MagickFalse)
577 Create Ghostscript control file.
579 file=AcquireUniqueFileResource(postscript_filename);
582 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
583 image_info->filename);
584 image=DestroyImage(image);
585 return((Image *) NULL);
587 count=write(file," ",1);
590 Render Postscript with the Ghostscript delegate.
592 if ((image_info->ping != MagickFalse) ||
593 (image_info->monochrome != MagickFalse))
594 delegate_info=GetDelegateInfo("ps:mono",(char *) NULL,exception);
596 if (cmyk != MagickFalse)
597 delegate_info=GetDelegateInfo("ps:cmyk",(char *) NULL,exception);
599 delegate_info=GetDelegateInfo("ps:alpha",(char *) NULL,exception);
600 if (delegate_info == (const DelegateInfo *) NULL)
602 (void) RelinquishUniqueFileResource(postscript_filename);
603 image=DestroyImage(image);
604 return((Image *) NULL);
607 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",image->resolution.x,
608 image->resolution.y);
609 if (image_info->page != (char *) NULL)
610 (void) FormatLocaleString(options,MaxTextExtent,"-g%.20gx%.20g ",(double)
611 page.width,(double) page.height);
612 if (cmyk != MagickFalse)
613 (void) ConcatenateMagickString(options,"-dUseCIEColor ",MaxTextExtent);
614 if (cropbox != MagickFalse)
615 (void) ConcatenateMagickString(options,"-dUseCropBox ",MaxTextExtent);
616 if (trimbox != MagickFalse)
617 (void) ConcatenateMagickString(options,"-dUseTrimBox ",MaxTextExtent);
618 read_info=CloneImageInfo(image_info);
619 *read_info->magick='\0';
620 if (read_info->number_scenes != 0)
623 pages[MaxTextExtent];
625 (void) FormatLocaleString(pages,MaxTextExtent,"-dFirstPage=%.20g "
626 "-dLastPage=%.20g",(double) read_info->scene+1,(double)
627 (read_info->scene+read_info->number_scenes));
628 (void) ConcatenateMagickString(options,pages,MaxTextExtent);
629 read_info->number_scenes=0;
630 if (read_info->scenes != (char *) NULL)
631 *read_info->scenes='\0';
633 option=GetImageOption(read_info,"authenticate");
634 if (option != (const char *) NULL)
635 (void) FormatLocaleString(options+strlen(options),MaxTextExtent,
636 " -sPCLPassword=%s",option);
637 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
638 (void) AcquireUniqueFilename(filename);
639 (void) ConcatenateMagickString(filename,"%d",MaxTextExtent);
640 (void) FormatLocaleString(command,MaxTextExtent,
641 GetDelegateCommands(delegate_info),
642 read_info->antialias != MagickFalse ? 4 : 1,
643 read_info->antialias != MagickFalse ? 4 : 1,density,options,filename,
644 postscript_filename,input_filename);
645 status=InvokePDFDelegate(read_info->verbose,command,exception);
646 (void) RelinquishUniqueFileResource(postscript_filename);
647 (void) RelinquishUniqueFileResource(input_filename);
648 pdf_image=(Image *) NULL;
649 if (status == MagickFalse)
652 (void) InterpretImageFilename(image_info,image,filename,(int) i,
653 read_info->filename,exception);
654 if (IsPDFRendered(read_info->filename) == MagickFalse)
656 (void) RelinquishUniqueFileResource(read_info->filename);
661 (void) InterpretImageFilename(image_info,image,filename,(int) i,
662 read_info->filename,exception);
663 if (IsPDFRendered(read_info->filename) == MagickFalse)
665 read_info->blob=NULL;
667 next=ReadImage(read_info,exception);
668 (void) RelinquishUniqueFileResource(read_info->filename);
669 if (next == (Image *) NULL)
671 AppendImageToList(&pdf_image,next);
673 read_info=DestroyImageInfo(read_info);
674 if (pdf_image == (Image *) NULL)
676 ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
677 image_info->filename);
678 image=DestroyImage(image);
679 return((Image *) NULL);
681 if (LocaleCompare(pdf_image->magick,"BMP") == 0)
686 cmyk_image=ConsolidateCMYKImages(pdf_image,exception);
687 if (cmyk_image != (Image *) NULL)
689 pdf_image=DestroyImageList(pdf_image);
690 pdf_image=cmyk_image;
693 if (image_info->number_scenes != 0)
702 Add place holder images to meet the subimage specification requirement.
704 for (i=0; i < (ssize_t) image_info->scene; i++)
706 clone_image=CloneImage(pdf_image,1,1,MagickTrue,exception);
707 if (clone_image != (Image *) NULL)
708 PrependImageToList(&pdf_image,clone_image);
713 (void) CopyMagickString(pdf_image->filename,filename,MaxTextExtent);
714 pdf_image->page=page;
715 (void) CloneImageProfiles(pdf_image,image);
716 (void) CloneImageProperties(pdf_image,image);
717 next=SyncNextImageInList(pdf_image);
718 if (next != (Image *) NULL)
720 } while (next != (Image *) NULL);
721 image=DestroyImage(image);
723 for (next=GetFirstImageInList(pdf_image); next != (Image *) NULL; )
726 next=GetNextImageInList(next);
728 return(GetFirstImageInList(pdf_image));
732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
736 % R e g i s t e r P D F I m a g e %
740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 % RegisterPDFImage() adds properties for the PDF image format to
743 % the list of supported formats. The properties include the image format
744 % tag, a method to read and/or write the format, whether the format
745 % supports the saving of more than one frame to the same file or blob,
746 % whether the format supports native in-memory I/O, and a brief
747 % description of the format.
749 % The format of the RegisterPDFImage method is:
751 % size_t RegisterPDFImage(void)
754 ModuleExport size_t RegisterPDFImage(void)
759 entry=SetMagickInfo("AI");
760 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
761 entry->encoder=(EncodeImageHandler *) WritePDFImage;
762 entry->adjoin=MagickFalse;
763 entry->blob_support=MagickFalse;
764 entry->seekable_stream=MagickTrue;
765 entry->description=ConstantString("Adobe Illustrator CS2");
766 entry->module=ConstantString("PDF");
767 (void) RegisterMagickInfo(entry);
768 entry=SetMagickInfo("EPDF");
769 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
770 entry->encoder=(EncodeImageHandler *) WritePDFImage;
771 entry->adjoin=MagickFalse;
772 entry->blob_support=MagickFalse;
773 entry->seekable_stream=MagickTrue;
774 entry->description=ConstantString("Encapsulated Portable Document Format");
775 entry->module=ConstantString("PDF");
776 (void) RegisterMagickInfo(entry);
777 entry=SetMagickInfo("PDF");
778 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
779 entry->encoder=(EncodeImageHandler *) WritePDFImage;
780 entry->magick=(IsImageFormatHandler *) IsPDF;
781 entry->blob_support=MagickFalse;
782 entry->seekable_stream=MagickTrue;
783 entry->description=ConstantString("Portable Document Format");
784 entry->module=ConstantString("PDF");
785 (void) RegisterMagickInfo(entry);
786 entry=SetMagickInfo("PDFA");
787 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
788 entry->encoder=(EncodeImageHandler *) WritePDFImage;
789 entry->magick=(IsImageFormatHandler *) IsPDF;
790 entry->blob_support=MagickFalse;
791 entry->seekable_stream=MagickTrue;
792 entry->description=ConstantString("Portable Document Archive Format");
793 entry->module=ConstantString("PDF");
794 (void) RegisterMagickInfo(entry);
795 return(MagickImageCoderSignature);
799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
803 % U n r e g i s t e r P D F I m a g e %
807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
809 % UnregisterPDFImage() removes format registrations made by the
810 % PDF module from the list of supported formats.
812 % The format of the UnregisterPDFImage method is:
814 % UnregisterPDFImage(void)
817 ModuleExport void UnregisterPDFImage(void)
819 (void) UnregisterMagickInfo("AI");
820 (void) UnregisterMagickInfo("EPDF");
821 (void) UnregisterMagickInfo("PDF");
822 (void) UnregisterMagickInfo("PDFA");
826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830 % W r i t e P D F I m a g e %
834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
836 % WritePDFImage() writes an image in the Portable Document image
839 % The format of the WritePDFImage method is:
841 % MagickBooleanType WritePDFImage(const ImageInfo *image_info,
842 % Image *image,ExceptionInfo *exception)
844 % A description of each parameter follows.
846 % o image_info: the image info.
848 % o image: The image.
850 % o exception: return any errors or warnings in this structure.
854 static inline size_t MagickMax(const size_t x,const size_t y)
861 static inline size_t MagickMin(const size_t x,const size_t y)
868 static char *EscapeParenthesis(const char *text)
880 buffer[MaxTextExtent];
884 for (i=0; i < (ssize_t) MagickMin(strlen(text),(MaxTextExtent-escapes-1)); i++)
886 if ((text[i] == '(') || (text[i] == ')'))
897 static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info,
898 Image *image,Image *inject_image,ExceptionInfo *exception)
916 write_info=CloneImageInfo(image_info);
917 (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent);
918 (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent);
919 group4_image=CloneImage(inject_image,0,0,MagickTrue,exception);
920 if (group4_image == (Image *) NULL)
922 group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length,
924 group4_image=DestroyImage(group4_image);
925 if (group4 == (unsigned char *) NULL)
927 write_info=DestroyImageInfo(write_info);
928 if (WriteBlob(image,length,group4) != (ssize_t) length)
930 group4=(unsigned char *) RelinquishMagickMemory(group4);
934 static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image,
935 ExceptionInfo *exception)
937 #define CFormat "/Filter [ /%s ]\n"
938 #define ObjectsPerImage 14
943 "<?xpacket begin=\"%s\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
944 "<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"
945 " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
946 " <rdf:Description rdf:about=\"\"\n"
947 " xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">\n"
948 " <xap:ModifyDate>%s</xap:ModifyDate>\n"
949 " <xap:CreateDate>%s</xap:CreateDate>\n"
950 " <xap:MetadataDate>%s</xap:MetadataDate>\n"
951 " <xap:CreatorTool>%s</xap:CreatorTool>\n"
952 " </rdf:Description>\n"
953 " <rdf:Description rdf:about=\"\"\n"
954 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
955 " <dc:format>application/pdf</dc:format>\n"
958 " <rdf:li xml:lang=\"x-default\">%s</rdf:li>\n"
961 " </rdf:Description>\n"
962 " <rdf:Description rdf:about=\"\"\n"
963 " xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\">\n"
964 " <xapMM:DocumentID>uuid:6ec119d7-7982-4f56-808d-dfe64f5b35cf</xapMM:DocumentID>\n"
965 " <xapMM:InstanceID>uuid:a79b99b4-6235-447f-9f6c-ec18ef7555cb</xapMM:InstanceID>\n"
966 " </rdf:Description>\n"
967 " <rdf:Description rdf:about=\"\"\n"
968 " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">\n"
969 " <pdf:Producer>%s</pdf:Producer>\n"
970 " </rdf:Description>\n"
971 " <rdf:Description rdf:about=\"\"\n"
972 " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n"
973 " <pdfaid:part>2</pdfaid:part>\n"
974 " <pdfaid:conformance>B</pdfaid:conformance>\n"
975 " </rdf:Description>\n"
978 "<?xpacket end=\"w\"?>\n"
980 XMPProfileMagick[4]= { (char) 0xef, (char) 0xbb, (char) 0xbf, (char) 0x00 };
983 basename[MaxTextExtent],
984 buffer[MaxTextExtent],
987 page_geometry[MaxTextExtent];
1029 register const Quantum
1032 register unsigned char
1062 Open output image file.
1064 assert(image_info != (const ImageInfo *) NULL);
1065 assert(image_info->signature == MagickSignature);
1066 assert(image != (Image *) NULL);
1067 assert(image->signature == MagickSignature);
1068 if (image->debug != MagickFalse)
1069 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1070 assert(exception != (ExceptionInfo *) NULL);
1071 assert(exception->signature == MagickSignature);
1072 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1073 if (status == MagickFalse)
1076 Allocate X ref memory.
1078 xref=(MagickOffsetType *) AcquireQuantumMemory(2048UL,sizeof(*xref));
1079 if (xref == (MagickOffsetType *) NULL)
1080 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1081 (void) ResetMagickMemory(xref,0,2048UL*sizeof(*xref));
1087 if (image_info->compression == JPEG2000Compression)
1088 version=(size_t) MagickMax(version,5);
1089 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1090 if (next->alpha_trait == BlendPixelTrait)
1091 version=(size_t) MagickMax(version,4);
1092 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1093 version=(size_t) MagickMax(version,6);
1094 (void) FormatLocaleString(buffer,MaxTextExtent,"%%PDF-1.%.20g \n",(double)
1096 (void) WriteBlobString(image,buffer);
1097 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1098 (void) WriteBlobString(image,"%âãÏÓ\n");
1100 Write Catalog object.
1102 xref[object++]=TellBlob(image);
1104 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1106 (void) WriteBlobString(image,buffer);
1107 (void) WriteBlobString(image,"<<\n");
1108 if (LocaleCompare(image_info->magick,"PDFA") != 0)
1109 (void) FormatLocaleString(buffer,MaxTextExtent,"/Pages %.20g 0 R\n",(double)
1113 (void) FormatLocaleString(buffer,MaxTextExtent,"/Metadata %.20g 0 R\n",
1115 (void) WriteBlobString(image,buffer);
1116 (void) FormatLocaleString(buffer,MaxTextExtent,"/Pages %.20g 0 R\n",
1119 (void) WriteBlobString(image,buffer);
1120 (void) WriteBlobString(image,"/Type /Catalog\n");
1121 (void) WriteBlobString(image,">>\n");
1122 (void) WriteBlobString(image,"endobj\n");
1123 GetPathComponent(image->filename,BasePath,basename);
1124 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1127 create_date[MaxTextExtent],
1128 modify_date[MaxTextExtent],
1129 timestamp[MaxTextExtent],
1130 xmp_profile[MaxTextExtent];
1138 xref[object++]=TellBlob(image);
1139 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1141 (void) WriteBlobString(image,buffer);
1142 (void) WriteBlobString(image,"<<\n");
1143 (void) WriteBlobString(image,"/Subtype /XML\n");
1145 value=GetImageProperty(image,"date:modify",exception);
1146 if (value != (const char *) NULL)
1147 (void) CopyMagickString(modify_date,value,MaxTextExtent);
1149 value=GetImageProperty(image,"date:create",exception);
1150 if (value != (const char *) NULL)
1151 (void) CopyMagickString(create_date,value,MaxTextExtent);
1152 (void) FormatMagickTime(time((time_t *) NULL),MaxTextExtent,timestamp);
1153 i=FormatLocaleString(xmp_profile,MaxTextExtent,XMPProfile,
1154 XMPProfileMagick,modify_date,create_date,timestamp,
1155 GetMagickVersion(&version),EscapeParenthesis(basename),
1156 GetMagickVersion(&version));
1157 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g\n",(double)
1159 (void) WriteBlobString(image,buffer);
1160 (void) WriteBlobString(image,"/Type /Metadata\n");
1161 (void) WriteBlobString(image,">>\nstream\n");
1162 (void) WriteBlobString(image,xmp_profile);
1163 (void) WriteBlobString(image,"\nendstream\n");
1164 (void) WriteBlobString(image,"endobj\n");
1169 xref[object++]=TellBlob(image);
1171 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1173 (void) WriteBlobString(image,buffer);
1174 (void) WriteBlobString(image,"<<\n");
1175 (void) WriteBlobString(image,"/Type /Pages\n");
1176 (void) FormatLocaleString(buffer,MaxTextExtent,"/Kids [ %.20g 0 R ",(double)
1178 (void) WriteBlobString(image,buffer);
1179 count=(ssize_t) (pages_id+ObjectsPerImage+1);
1180 if (image_info->adjoin != MagickFalse)
1186 Predict page object id's.
1189 for ( ; GetNextImageInList(kid_image) != (Image *) NULL; count+=ObjectsPerImage)
1191 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 R ",(double)
1193 (void) WriteBlobString(image,buffer);
1194 kid_image=GetNextImageInList(kid_image);
1196 xref=(MagickOffsetType *) ResizeQuantumMemory(xref,(size_t) count+2048UL,
1198 if (xref == (MagickOffsetType *) NULL)
1199 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1201 (void) WriteBlobString(image,"]\n");
1202 (void) FormatLocaleString(buffer,MaxTextExtent,"/Count %.20g\n",(double)
1203 ((count-pages_id)/ObjectsPerImage));
1204 (void) WriteBlobString(image,buffer);
1205 (void) WriteBlobString(image,">>\n");
1206 (void) WriteBlobString(image,"endobj\n");
1210 compression=image->compression;
1211 if (image_info->compression != UndefinedCompression)
1212 compression=image_info->compression;
1213 switch (compression)
1215 case FaxCompression:
1216 case Group4Compression:
1218 if ((IsImageMonochrome(image,exception) == MagickFalse) ||
1219 (image->alpha_trait == BlendPixelTrait))
1220 compression=RLECompression;
1223 #if !defined(MAGICKCORE_JPEG_DELEGATE)
1224 case JPEGCompression:
1226 compression=RLECompression;
1227 (void) ThrowMagickException(exception,GetMagickModule(),
1228 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)",
1233 #if !defined(MAGICKCORE_JP2_DELEGATE)
1234 case JPEG2000Compression:
1236 compression=RLECompression;
1237 (void) ThrowMagickException(exception,GetMagickModule(),
1238 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JP2)",
1243 #if !defined(MAGICKCORE_ZLIB_DELEGATE)
1244 case ZipCompression:
1246 compression=RLECompression;
1247 (void) ThrowMagickException(exception,GetMagickModule(),
1248 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (ZLIB)",
1253 case LZWCompression:
1255 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1256 compression=RLECompression; /* LZW compression is forbidden */
1261 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1262 compression=RLECompression; /* ASCII 85 compression is forbidden */
1268 if (compression == JPEG2000Compression)
1270 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
1271 (void) TransformImageColorspace(image,sRGBColorspace,exception);
1274 Scale relative to dots-per-inch.
1276 delta.x=DefaultResolution;
1277 delta.y=DefaultResolution;
1278 resolution.x=image->resolution.x;
1279 resolution.y=image->resolution.y;
1280 if ((resolution.x == 0.0) || (resolution.y == 0.0))
1282 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
1283 resolution.x=geometry_info.rho;
1284 resolution.y=geometry_info.sigma;
1285 if ((flags & SigmaValue) == 0)
1286 resolution.y=resolution.x;
1288 if (image_info->density != (char *) NULL)
1290 flags=ParseGeometry(image_info->density,&geometry_info);
1291 resolution.x=geometry_info.rho;
1292 resolution.y=geometry_info.sigma;
1293 if ((flags & SigmaValue) == 0)
1294 resolution.y=resolution.x;
1296 if (image->units == PixelsPerCentimeterResolution)
1298 resolution.x=(double) ((size_t) (100.0*2.54*resolution.x+0.5)/100.0);
1299 resolution.y=(double) ((size_t) (100.0*2.54*resolution.y+0.5)/100.0);
1301 SetGeometry(image,&geometry);
1302 (void) FormatLocaleString(page_geometry,MaxTextExtent,"%.20gx%.20g",(double)
1303 image->columns,(double) image->rows);
1304 if (image_info->page != (char *) NULL)
1305 (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent);
1307 if ((image->page.width != 0) && (image->page.height != 0))
1308 (void) FormatLocaleString(page_geometry,MaxTextExtent,
1309 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
1310 image->page.height,(double) image->page.x,(double) image->page.y);
1312 if ((image->gravity != UndefinedGravity) &&
1313 (LocaleCompare(image_info->magick,"PDF") == 0))
1314 (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent);
1315 (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent);
1316 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
1317 &geometry.width,&geometry.height);
1318 scale.x=(double) (geometry.width*delta.x)/resolution.x;
1319 geometry.width=(size_t) floor(scale.x+0.5);
1320 scale.y=(double) (geometry.height*delta.y)/resolution.y;
1321 geometry.height=(size_t) floor(scale.y+0.5);
1322 (void) ParseAbsoluteGeometry(page_geometry,&media_info);
1323 (void) ParseGravityGeometry(image,page_geometry,&page_info,exception);
1324 if (image->gravity != UndefinedGravity)
1326 geometry.x=(-page_info.x);
1327 geometry.y=(ssize_t) (media_info.height+page_info.y-image->rows);
1330 if (image_info->pointsize != 0.0)
1331 pointsize=image_info->pointsize;
1333 value=GetImageProperty(image,"label",exception);
1334 if (value != (const char *) NULL)
1335 text_size=(size_t) (MultilineCensus(value)*pointsize+12);
1340 xref[object++]=TellBlob(image);
1341 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1343 (void) WriteBlobString(image,buffer);
1344 (void) WriteBlobString(image,"<<\n");
1345 (void) WriteBlobString(image,"/Type /Page\n");
1346 (void) FormatLocaleString(buffer,MaxTextExtent,"/Parent %.20g 0 R\n",
1348 (void) WriteBlobString(image,buffer);
1349 (void) WriteBlobString(image,"/Resources <<\n");
1350 labels=(char **) NULL;
1351 value=GetImageProperty(image,"label",exception);
1352 if (value != (const char *) NULL)
1353 labels=StringToList(value);
1354 if (labels != (char **) NULL)
1356 (void) FormatLocaleString(buffer,MaxTextExtent,
1357 "/Font << /F%.20g %.20g 0 R >>\n",(double) image->scene,(double)
1359 (void) WriteBlobString(image,buffer);
1361 (void) FormatLocaleString(buffer,MaxTextExtent,
1362 "/XObject << /Im%.20g %.20g 0 R >>\n",(double) image->scene,(double)
1364 (void) WriteBlobString(image,buffer);
1365 (void) FormatLocaleString(buffer,MaxTextExtent,"/ProcSet %.20g 0 R >>\n",
1367 (void) WriteBlobString(image,buffer);
1368 (void) FormatLocaleString(buffer,MaxTextExtent,
1369 "/MediaBox [0 0 %g %g]\n",72.0*media_info.width/resolution.x,
1370 72.0*media_info.height/resolution.y);
1371 (void) WriteBlobString(image,buffer);
1372 (void) FormatLocaleString(buffer,MaxTextExtent,
1373 "/CropBox [0 0 %g %g]\n",72.0*media_info.width/resolution.x,
1374 72.0*media_info.height/resolution.y);
1375 (void) WriteBlobString(image,buffer);
1376 (void) FormatLocaleString(buffer,MaxTextExtent,"/Contents %.20g 0 R\n",
1378 (void) WriteBlobString(image,buffer);
1379 (void) FormatLocaleString(buffer,MaxTextExtent,"/Thumb %.20g 0 R\n",(double)
1381 (void) WriteBlobString(image,buffer);
1382 (void) WriteBlobString(image,">>\n");
1383 (void) WriteBlobString(image,"endobj\n");
1385 Write Contents object.
1387 xref[object++]=TellBlob(image);
1388 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1390 (void) WriteBlobString(image,buffer);
1391 (void) WriteBlobString(image,"<<\n");
1392 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1394 (void) WriteBlobString(image,buffer);
1395 (void) WriteBlobString(image,">>\n");
1396 (void) WriteBlobString(image,"stream\n");
1397 offset=TellBlob(image);
1398 (void) WriteBlobString(image,"q\n");
1399 if (labels != (char **) NULL)
1400 for (i=0; labels[i] != (char *) NULL; i++)
1402 (void) WriteBlobString(image,"BT\n");
1403 (void) FormatLocaleString(buffer,MaxTextExtent,"/F%.20g %g Tf\n",
1404 (double) image->scene,pointsize);
1405 (void) WriteBlobString(image,buffer);
1406 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g Td\n",
1407 (double) geometry.x,(double) (geometry.y+geometry.height+i*pointsize+
1409 (void) WriteBlobString(image,buffer);
1410 (void) FormatLocaleString(buffer,MaxTextExtent,"(%s) Tj\n",labels[i]);
1411 (void) WriteBlobString(image,buffer);
1412 (void) WriteBlobString(image,"ET\n");
1413 labels[i]=DestroyString(labels[i]);
1415 (void) FormatLocaleString(buffer,MaxTextExtent,"%g 0 0 %g %.20g %.20g cm\n",
1416 scale.x,scale.y,(double) geometry.x,(double) geometry.y);
1417 (void) WriteBlobString(image,buffer);
1418 (void) FormatLocaleString(buffer,MaxTextExtent,"/Im%.20g Do\n",(double)
1420 (void) WriteBlobString(image,buffer);
1421 (void) WriteBlobString(image,"Q\n");
1422 offset=TellBlob(image)-offset;
1423 (void) WriteBlobString(image,"\nendstream\n");
1424 (void) WriteBlobString(image,"endobj\n");
1426 Write Length object.
1428 xref[object++]=TellBlob(image);
1429 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1431 (void) WriteBlobString(image,buffer);
1432 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
1433 (void) WriteBlobString(image,buffer);
1434 (void) WriteBlobString(image,"endobj\n");
1436 Write Procset object.
1438 xref[object++]=TellBlob(image);
1439 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1441 (void) WriteBlobString(image,buffer);
1442 if ((image->storage_class == DirectClass) || (image->colors > 256))
1443 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageC",MaxTextExtent);
1445 if ((compression == FaxCompression) || (compression == Group4Compression))
1446 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageB",MaxTextExtent);
1448 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageI",MaxTextExtent);
1449 (void) WriteBlobString(image,buffer);
1450 (void) WriteBlobString(image," ]\n");
1451 (void) WriteBlobString(image,"endobj\n");
1455 xref[object++]=TellBlob(image);
1456 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1458 (void) WriteBlobString(image,buffer);
1459 (void) WriteBlobString(image,"<<\n");
1460 if (labels != (char **) NULL)
1462 (void) WriteBlobString(image,"/Type /Font\n");
1463 (void) WriteBlobString(image,"/Subtype /Type1\n");
1464 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /F%.20g\n",
1465 (double) image->scene);
1466 (void) WriteBlobString(image,buffer);
1467 (void) WriteBlobString(image,"/BaseFont /Helvetica\n");
1468 (void) WriteBlobString(image,"/Encoding /MacRomanEncoding\n");
1469 labels=(char **) RelinquishMagickMemory(labels);
1471 (void) WriteBlobString(image,">>\n");
1472 (void) WriteBlobString(image,"endobj\n");
1474 Write XObject object.
1476 xref[object++]=TellBlob(image);
1477 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1479 (void) WriteBlobString(image,buffer);
1480 (void) WriteBlobString(image,"<<\n");
1481 (void) WriteBlobString(image,"/Type /XObject\n");
1482 (void) WriteBlobString(image,"/Subtype /Image\n");
1483 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /Im%.20g\n",(double)
1485 (void) WriteBlobString(image,buffer);
1486 switch (compression)
1490 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1493 case JPEGCompression:
1495 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1496 if (image->colorspace != CMYKColorspace)
1498 (void) WriteBlobString(image,buffer);
1499 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1503 case JPEG2000Compression:
1505 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1506 if (image->colorspace != CMYKColorspace)
1508 (void) WriteBlobString(image,buffer);
1509 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1513 case LZWCompression:
1515 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1518 case ZipCompression:
1520 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1523 case FaxCompression:
1524 case Group4Compression:
1526 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1528 (void) WriteBlobString(image,buffer);
1529 (void) FormatLocaleString(buffer,MaxTextExtent,"/DecodeParms [ << "
1530 "/K %s /BlackIs1 false /Columns %.20g /Rows %.20g >> ]\n",CCITTParam,
1531 (double) image->columns,(double) image->rows);
1536 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
1541 (void) WriteBlobString(image,buffer);
1542 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
1544 (void) WriteBlobString(image,buffer);
1545 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",(double)
1547 (void) WriteBlobString(image,buffer);
1548 (void) FormatLocaleString(buffer,MaxTextExtent,"/ColorSpace %.20g 0 R\n",
1550 (void) WriteBlobString(image,buffer);
1551 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
1552 (compression == FaxCompression) || (compression == Group4Compression) ?
1554 (void) WriteBlobString(image,buffer);
1555 if (image->alpha_trait == BlendPixelTrait)
1557 (void) FormatLocaleString(buffer,MaxTextExtent,"/SMask %.20g 0 R\n",
1559 (void) WriteBlobString(image,buffer);
1561 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1563 (void) WriteBlobString(image,buffer);
1564 (void) WriteBlobString(image,">>\n");
1565 (void) WriteBlobString(image,"stream\n");
1566 offset=TellBlob(image);
1567 number_pixels=(MagickSizeType) image->columns*image->rows;
1568 if ((4*number_pixels) != (MagickSizeType) ((size_t) (4*number_pixels)))
1569 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1570 if ((compression == FaxCompression) || (compression == Group4Compression) ||
1571 ((image_info->type != TrueColorType) &&
1572 (IsImageGray(image,exception) != MagickFalse)))
1574 switch (compression)
1576 case FaxCompression:
1577 case Group4Compression:
1579 if (LocaleCompare(CCITTParam,"0") == 0)
1581 (void) HuffmanEncodeImage(image_info,image,image,exception);
1584 (void) Huffman2DEncodeImage(image_info,image,image,exception);
1587 case JPEGCompression:
1589 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
1590 if (status == MagickFalse)
1592 (void) CloseBlob(image);
1593 return(MagickFalse);
1597 case JPEG2000Compression:
1599 status=InjectImageBlob(image_info,image,image,"jp2",exception);
1600 if (status == MagickFalse)
1602 (void) CloseBlob(image);
1603 return(MagickFalse);
1607 case RLECompression:
1611 Allocate pixel array.
1613 length=(size_t) number_pixels;
1614 pixels=(unsigned char *) AcquireQuantumMemory(length,
1616 if (pixels == (unsigned char *) NULL)
1617 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1619 Dump Runlength encoded pixels.
1622 for (y=0; y < (ssize_t) image->rows; y++)
1624 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1625 if (p == (const Quantum *) NULL)
1627 for (x=0; x < (ssize_t) image->columns; x++)
1629 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
1630 p+=GetPixelChannels(image);
1632 if (image->previous == (Image *) NULL)
1634 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1636 if (status == MagickFalse)
1640 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1641 if (compression == ZipCompression)
1642 status=ZLIBEncodeImage(image,length,pixels,exception);
1645 if (compression == LZWCompression)
1646 status=LZWEncodeImage(image,length,pixels,exception);
1648 status=PackbitsEncodeImage(image,length,pixels,exception);
1649 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1650 if (status == MagickFalse)
1652 (void) CloseBlob(image);
1653 return(MagickFalse);
1660 Dump uncompressed PseudoColor packets.
1662 Ascii85Initialize(image);
1663 for (y=0; y < (ssize_t) image->rows; y++)
1665 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1666 if (p == (const Quantum *) NULL)
1668 for (x=0; x < (ssize_t) image->columns; x++)
1670 Ascii85Encode(image,ScaleQuantumToChar(
1671 GetPixelIntensity(image,p)));
1672 p+=GetPixelChannels(image);
1674 if (image->previous == (Image *) NULL)
1676 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1678 if (status == MagickFalse)
1682 Ascii85Flush(image);
1688 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1689 (compression == JPEGCompression) ||
1690 (compression == JPEG2000Compression))
1691 switch (compression)
1693 case JPEGCompression:
1695 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
1696 if (status == MagickFalse)
1698 (void) CloseBlob(image);
1699 return(MagickFalse);
1703 case JPEG2000Compression:
1705 status=InjectImageBlob(image_info,image,image,"jp2",exception);
1706 if (status == MagickFalse)
1708 (void) CloseBlob(image);
1709 return(MagickFalse);
1713 case RLECompression:
1717 Allocate pixel array.
1719 length=(size_t) number_pixels;
1720 pixels=(unsigned char *) AcquireQuantumMemory(length,
1722 length*=image->colorspace == CMYKColorspace ? 4UL : 3UL;
1723 if (pixels == (unsigned char *) NULL)
1724 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1726 Dump runoffset encoded pixels.
1729 for (y=0; y < (ssize_t) image->rows; y++)
1731 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1732 if (p == (const Quantum *) NULL)
1734 for (x=0; x < (ssize_t) image->columns; x++)
1736 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1737 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1738 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1739 if (image->colorspace == CMYKColorspace)
1740 *q++=ScaleQuantumToChar(GetPixelBlack(image,p));
1741 p+=GetPixelChannels(image);
1743 if (image->previous == (Image *) NULL)
1745 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1747 if (status == MagickFalse)
1751 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1752 if (compression == ZipCompression)
1753 status=ZLIBEncodeImage(image,length,pixels,exception);
1756 if (compression == LZWCompression)
1757 status=LZWEncodeImage(image,length,pixels,exception);
1759 status=PackbitsEncodeImage(image,length,pixels,exception);
1760 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1761 if (status == MagickFalse)
1763 (void) CloseBlob(image);
1764 return(MagickFalse);
1771 Dump uncompressed DirectColor packets.
1773 Ascii85Initialize(image);
1774 for (y=0; y < (ssize_t) image->rows; y++)
1776 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1777 if (p == (const Quantum *) NULL)
1779 for (x=0; x < (ssize_t) image->columns; x++)
1781 Ascii85Encode(image,ScaleQuantumToChar(GetPixelRed(image,p)));
1782 Ascii85Encode(image,ScaleQuantumToChar(GetPixelGreen(image,p)));
1783 Ascii85Encode(image,ScaleQuantumToChar(GetPixelBlue(image,p)));
1784 if (image->colorspace == CMYKColorspace)
1785 Ascii85Encode(image,ScaleQuantumToChar(
1786 GetPixelBlack(image,p)));
1787 p+=GetPixelChannels(image);
1789 if (image->previous == (Image *) NULL)
1791 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1793 if (status == MagickFalse)
1797 Ascii85Flush(image);
1804 Dump number of colors and colormap.
1806 switch (compression)
1808 case RLECompression:
1812 Allocate pixel array.
1814 length=(size_t) number_pixels;
1815 pixels=(unsigned char *) AcquireQuantumMemory(length,
1817 if (pixels == (unsigned char *) NULL)
1818 ThrowWriterException(ResourceLimitError,
1819 "MemoryAllocationFailed");
1821 Dump Runlength encoded pixels.
1824 for (y=0; y < (ssize_t) image->rows; y++)
1826 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1827 if (p == (const Quantum *) NULL)
1829 for (x=0; x < (ssize_t) image->columns; x++)
1831 *q++=(unsigned char) GetPixelIndex(image,p);
1832 p+=GetPixelChannels(image);
1834 if (image->previous == (Image *) NULL)
1836 status=SetImageProgress(image,SaveImageTag,
1837 (MagickOffsetType) y,image->rows);
1838 if (status == MagickFalse)
1842 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1843 if (compression == ZipCompression)
1844 status=ZLIBEncodeImage(image,length,pixels,exception);
1847 if (compression == LZWCompression)
1848 status=LZWEncodeImage(image,length,pixels,exception);
1850 status=PackbitsEncodeImage(image,length,pixels,exception);
1851 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1852 if (status == MagickFalse)
1854 (void) CloseBlob(image);
1855 return(MagickFalse);
1862 Dump uncompressed PseudoColor packets.
1864 Ascii85Initialize(image);
1865 for (y=0; y < (ssize_t) image->rows; y++)
1867 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1868 if (p == (const Quantum *) NULL)
1870 for (x=0; x < (ssize_t) image->columns; x++)
1872 Ascii85Encode(image,(unsigned char) GetPixelIndex(image,p));
1873 p+=GetPixelChannels(image);
1875 if (image->previous == (Image *) NULL)
1877 status=SetImageProgress(image,SaveImageTag,
1878 (MagickOffsetType) y,image->rows);
1879 if (status == MagickFalse)
1883 Ascii85Flush(image);
1888 offset=TellBlob(image)-offset;
1889 (void) WriteBlobString(image,"\nendstream\n");
1890 (void) WriteBlobString(image,"endobj\n");
1892 Write Length object.
1894 xref[object++]=TellBlob(image);
1895 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1897 (void) WriteBlobString(image,buffer);
1898 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
1899 (void) WriteBlobString(image,buffer);
1900 (void) WriteBlobString(image,"endobj\n");
1902 Write Colorspace object.
1904 xref[object++]=TellBlob(image);
1905 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1907 (void) WriteBlobString(image,buffer);
1908 if (image->colorspace == CMYKColorspace)
1909 (void) CopyMagickString(buffer,"/DeviceCMYK\n",MaxTextExtent);
1911 if ((compression == FaxCompression) ||
1912 (compression == Group4Compression) ||
1913 ((image_info->type != TrueColorType) &&
1914 (IsImageGray(image,exception) != MagickFalse)))
1915 (void) CopyMagickString(buffer,"/DeviceGray\n",MaxTextExtent);
1917 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1918 (compression == JPEGCompression) ||
1919 (compression == JPEG2000Compression))
1920 (void) CopyMagickString(buffer,"/DeviceRGB\n",MaxTextExtent);
1922 (void) FormatLocaleString(buffer,MaxTextExtent,
1923 "[ /Indexed /DeviceRGB %.20g %.20g 0 R ]\n",(double) image->colors-
1924 1,(double) object+3);
1925 (void) WriteBlobString(image,buffer);
1926 (void) WriteBlobString(image,"endobj\n");
1930 SetGeometry(image,&geometry);
1931 (void) ParseMetaGeometry("106x106+0+0>",&geometry.x,&geometry.y,
1932 &geometry.width,&geometry.height);
1933 tile_image=ThumbnailImage(image,geometry.width,geometry.height,exception);
1934 if (tile_image == (Image *) NULL)
1935 return(MagickFalse);
1936 xref[object++]=TellBlob(image);
1937 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1939 (void) WriteBlobString(image,buffer);
1940 (void) WriteBlobString(image,"<<\n");
1941 switch (compression)
1945 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1948 case JPEGCompression:
1950 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1951 if (image->colorspace != CMYKColorspace)
1953 (void) WriteBlobString(image,buffer);
1954 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1958 case JPEG2000Compression:
1960 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1961 if (image->colorspace != CMYKColorspace)
1963 (void) WriteBlobString(image,buffer);
1964 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1968 case LZWCompression:
1970 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1973 case ZipCompression:
1975 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1978 case FaxCompression:
1979 case Group4Compression:
1981 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1983 (void) WriteBlobString(image,buffer);
1984 (void) FormatLocaleString(buffer,MaxTextExtent,"/DecodeParms [ << "
1985 "/K %s /BlackIs1 false /Columns %.20g /Rows %.20g >> ]\n",CCITTParam,
1986 (double) tile_image->columns,(double) tile_image->rows);
1991 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
1996 (void) WriteBlobString(image,buffer);
1997 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
1998 tile_image->columns);
1999 (void) WriteBlobString(image,buffer);
2000 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",(double)
2002 (void) WriteBlobString(image,buffer);
2003 (void) FormatLocaleString(buffer,MaxTextExtent,"/ColorSpace %.20g 0 R\n",
2005 (void) WriteBlobString(image,buffer);
2006 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
2007 (compression == FaxCompression) || (compression == Group4Compression) ?
2009 (void) WriteBlobString(image,buffer);
2010 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
2012 (void) WriteBlobString(image,buffer);
2013 (void) WriteBlobString(image,">>\n");
2014 (void) WriteBlobString(image,"stream\n");
2015 offset=TellBlob(image);
2016 number_pixels=(MagickSizeType) tile_image->columns*tile_image->rows;
2017 if ((compression == FaxCompression) ||
2018 (compression == Group4Compression) ||
2019 ((image_info->type != TrueColorType) &&
2020 (IsImageGray(tile_image,exception) != MagickFalse)))
2022 switch (compression)
2024 case FaxCompression:
2025 case Group4Compression:
2027 if (LocaleCompare(CCITTParam,"0") == 0)
2029 (void) HuffmanEncodeImage(image_info,image,tile_image,
2033 (void) Huffman2DEncodeImage(image_info,image,tile_image,exception);
2036 case JPEGCompression:
2038 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
2040 if (status == MagickFalse)
2042 (void) CloseBlob(image);
2043 return(MagickFalse);
2047 case JPEG2000Compression:
2049 status=InjectImageBlob(image_info,image,tile_image,"jp2",exception);
2050 if (status == MagickFalse)
2052 (void) CloseBlob(image);
2053 return(MagickFalse);
2057 case RLECompression:
2061 Allocate pixel array.
2063 length=(size_t) number_pixels;
2064 pixels=(unsigned char *) AcquireQuantumMemory(length,
2066 if (pixels == (unsigned char *) NULL)
2068 tile_image=DestroyImage(tile_image);
2069 ThrowWriterException(ResourceLimitError,
2070 "MemoryAllocationFailed");
2073 Dump Runlength encoded pixels.
2076 for (y=0; y < (ssize_t) tile_image->rows; y++)
2078 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2080 if (p == (const Quantum *) NULL)
2082 for (x=0; x < (ssize_t) tile_image->columns; x++)
2084 *q++=ScaleQuantumToChar(GetPixelIntensity(tile_image,p));
2085 p+=GetPixelChannels(tile_image);
2088 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2089 if (compression == ZipCompression)
2090 status=ZLIBEncodeImage(image,length,pixels,exception);
2093 if (compression == LZWCompression)
2094 status=LZWEncodeImage(image,length,pixels,exception);
2096 status=PackbitsEncodeImage(image,length,pixels,exception);
2097 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2098 if (status == MagickFalse)
2100 (void) CloseBlob(image);
2101 return(MagickFalse);
2108 Dump uncompressed PseudoColor packets.
2110 Ascii85Initialize(image);
2111 for (y=0; y < (ssize_t) tile_image->rows; y++)
2113 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2115 if (p == (const Quantum *) NULL)
2117 for (x=0; x < (ssize_t) tile_image->columns; x++)
2119 Ascii85Encode(image,
2120 ScaleQuantumToChar(GetPixelIntensity(tile_image,p)));
2121 p+=GetPixelChannels(tile_image);
2124 Ascii85Flush(image);
2130 if ((tile_image->storage_class == DirectClass) ||
2131 (tile_image->colors > 256) || (compression == JPEGCompression) ||
2132 (compression == JPEG2000Compression))
2133 switch (compression)
2135 case JPEGCompression:
2137 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
2139 if (status == MagickFalse)
2141 (void) CloseBlob(image);
2142 return(MagickFalse);
2146 case JPEG2000Compression:
2148 status=InjectImageBlob(image_info,image,tile_image,"jp2",exception);
2149 if (status == MagickFalse)
2151 (void) CloseBlob(image);
2152 return(MagickFalse);
2156 case RLECompression:
2160 Allocate pixel array.
2162 length=(size_t) number_pixels;
2163 pixels=(unsigned char *) AcquireQuantumMemory(length,4*
2165 length*=tile_image->colorspace == CMYKColorspace ? 4UL : 3UL;
2166 if (pixels == (unsigned char *) NULL)
2168 tile_image=DestroyImage(tile_image);
2169 ThrowWriterException(ResourceLimitError,
2170 "MemoryAllocationFailed");
2173 Dump runoffset encoded pixels.
2176 for (y=0; y < (ssize_t) tile_image->rows; y++)
2178 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2180 if (p == (const Quantum *) NULL)
2182 for (x=0; x < (ssize_t) tile_image->columns; x++)
2184 *q++=ScaleQuantumToChar(GetPixelRed(tile_image,p));
2185 *q++=ScaleQuantumToChar(GetPixelGreen(tile_image,p));
2186 *q++=ScaleQuantumToChar(GetPixelBlue(tile_image,p));
2187 if (image->colorspace == CMYKColorspace)
2188 *q++=ScaleQuantumToChar(GetPixelBlack(tile_image,p));
2189 p+=GetPixelChannels(tile_image);
2192 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2193 if (compression == ZipCompression)
2194 status=ZLIBEncodeImage(image,length,pixels,exception);
2197 if (compression == LZWCompression)
2198 status=LZWEncodeImage(image,length,pixels,exception);
2200 status=PackbitsEncodeImage(image,length,pixels,exception);
2201 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2202 if (status == MagickFalse)
2204 (void) CloseBlob(image);
2205 return(MagickFalse);
2212 Dump uncompressed DirectColor packets.
2214 Ascii85Initialize(image);
2215 for (y=0; y < (ssize_t) tile_image->rows; y++)
2217 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2219 if (p == (const Quantum *) NULL)
2221 for (x=0; x < (ssize_t) tile_image->columns; x++)
2223 Ascii85Encode(image,ScaleQuantumToChar(
2224 GetPixelRed(tile_image,p)));
2225 Ascii85Encode(image,ScaleQuantumToChar(
2226 GetPixelGreen(tile_image,p)));
2227 Ascii85Encode(image,ScaleQuantumToChar(
2228 GetPixelBlue(tile_image,p)));
2229 if (image->colorspace == CMYKColorspace)
2230 Ascii85Encode(image,ScaleQuantumToChar(
2231 GetPixelBlack(tile_image,p)));
2232 p+=GetPixelChannels(tile_image);
2235 Ascii85Flush(image);
2242 Dump number of colors and colormap.
2244 switch (compression)
2246 case RLECompression:
2250 Allocate pixel array.
2252 length=(size_t) number_pixels;
2253 pixels=(unsigned char *) AcquireQuantumMemory(length,
2255 if (pixels == (unsigned char *) NULL)
2257 tile_image=DestroyImage(tile_image);
2258 ThrowWriterException(ResourceLimitError,
2259 "MemoryAllocationFailed");
2262 Dump Runlength encoded pixels.
2265 for (y=0; y < (ssize_t) tile_image->rows; y++)
2267 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2269 if (p == (const Quantum *) NULL)
2271 for (x=0; x < (ssize_t) tile_image->columns; x++)
2273 *q++=(unsigned char) GetPixelIndex(tile_image,p);
2274 p+=GetPixelChannels(tile_image);
2277 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2278 if (compression == ZipCompression)
2279 status=ZLIBEncodeImage(image,length,pixels,exception);
2282 if (compression == LZWCompression)
2283 status=LZWEncodeImage(image,length,pixels,exception);
2285 status=PackbitsEncodeImage(image,length,pixels,exception);
2286 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2287 if (status == MagickFalse)
2289 (void) CloseBlob(image);
2290 return(MagickFalse);
2297 Dump uncompressed PseudoColor packets.
2299 Ascii85Initialize(image);
2300 for (y=0; y < (ssize_t) tile_image->rows; y++)
2302 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2304 if (p == (const Quantum *) NULL)
2306 for (x=0; x < (ssize_t) tile_image->columns; x++)
2308 Ascii85Encode(image,(unsigned char)
2309 GetPixelIndex(tile_image,p));
2310 p+=GetPixelChannels(image);
2313 Ascii85Flush(image);
2318 tile_image=DestroyImage(tile_image);
2319 offset=TellBlob(image)-offset;
2320 (void) WriteBlobString(image,"\nendstream\n");
2321 (void) WriteBlobString(image,"endobj\n");
2323 Write Length object.
2325 xref[object++]=TellBlob(image);
2326 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2328 (void) WriteBlobString(image,buffer);
2329 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2330 (void) WriteBlobString(image,buffer);
2331 (void) WriteBlobString(image,"endobj\n");
2332 xref[object++]=TellBlob(image);
2333 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2335 (void) WriteBlobString(image,buffer);
2336 (void) WriteBlobString(image,"<<\n");
2337 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
2338 (compression == FaxCompression) || (compression == Group4Compression))
2339 (void) WriteBlobString(image,">>\n");
2343 Write Colormap object.
2345 if (compression == NoCompression)
2346 (void) WriteBlobString(image,"/Filter [ /ASCII85Decode ]\n");
2347 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
2349 (void) WriteBlobString(image,buffer);
2350 (void) WriteBlobString(image,">>\n");
2351 (void) WriteBlobString(image,"stream\n");
2352 offset=TellBlob(image);
2353 if (compression == NoCompression)
2354 Ascii85Initialize(image);
2355 for (i=0; i < (ssize_t) image->colors; i++)
2357 if (compression == NoCompression)
2359 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].red));
2360 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].green));
2361 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].blue));
2364 (void) WriteBlobByte(image,
2365 ScaleQuantumToChar(image->colormap[i].red));
2366 (void) WriteBlobByte(image,
2367 ScaleQuantumToChar(image->colormap[i].green));
2368 (void) WriteBlobByte(image,
2369 ScaleQuantumToChar(image->colormap[i].blue));
2371 if (compression == NoCompression)
2372 Ascii85Flush(image);
2373 offset=TellBlob(image)-offset;
2374 (void) WriteBlobString(image,"\nendstream\n");
2376 (void) WriteBlobString(image,"endobj\n");
2378 Write Length object.
2380 xref[object++]=TellBlob(image);
2381 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2383 (void) WriteBlobString(image,buffer);
2384 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double)
2386 (void) WriteBlobString(image,buffer);
2387 (void) WriteBlobString(image,"endobj\n");
2389 Write softmask object.
2391 xref[object++]=TellBlob(image);
2392 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2394 (void) WriteBlobString(image,buffer);
2395 (void) WriteBlobString(image,"<<\n");
2396 if (image->alpha_trait != BlendPixelTrait)
2397 (void) WriteBlobString(image,">>\n");
2400 (void) WriteBlobString(image,"/Type /XObject\n");
2401 (void) WriteBlobString(image,"/Subtype /Image\n");
2402 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /Ma%.20g\n",
2403 (double) image->scene);
2404 (void) WriteBlobString(image,buffer);
2405 switch (compression)
2409 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
2413 case LZWCompression:
2415 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
2418 case ZipCompression:
2420 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
2426 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
2431 (void) WriteBlobString(image,buffer);
2432 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
2434 (void) WriteBlobString(image,buffer);
2435 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",
2436 (double) image->rows);
2437 (void) WriteBlobString(image,buffer);
2438 (void) WriteBlobString(image,"/ColorSpace /DeviceGray\n");
2439 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
2440 (compression == FaxCompression) || (compression == Group4Compression)
2442 (void) WriteBlobString(image,buffer);
2443 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
2445 (void) WriteBlobString(image,buffer);
2446 (void) WriteBlobString(image,">>\n");
2447 (void) WriteBlobString(image,"stream\n");
2448 offset=TellBlob(image);
2449 number_pixels=(MagickSizeType) image->columns*image->rows;
2450 switch (compression)
2452 case RLECompression:
2456 Allocate pixel array.
2458 length=(size_t) number_pixels;
2459 pixels=(unsigned char *) AcquireQuantumMemory(length,
2461 if (pixels == (unsigned char *) NULL)
2463 image=DestroyImage(image);
2464 ThrowWriterException(ResourceLimitError,
2465 "MemoryAllocationFailed");
2468 Dump Runlength encoded pixels.
2471 for (y=0; y < (ssize_t) image->rows; y++)
2473 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2474 if (p == (const Quantum *) NULL)
2476 for (x=0; x < (ssize_t) image->columns; x++)
2478 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
2479 p+=GetPixelChannels(image);
2482 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2483 if (compression == ZipCompression)
2484 status=ZLIBEncodeImage(image,length,pixels,exception);
2487 if (compression == LZWCompression)
2488 status=LZWEncodeImage(image,length,pixels,exception);
2490 status=PackbitsEncodeImage(image,length,pixels,exception);
2491 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2492 if (status == MagickFalse)
2494 (void) CloseBlob(image);
2495 return(MagickFalse);
2502 Dump uncompressed PseudoColor packets.
2504 Ascii85Initialize(image);
2505 for (y=0; y < (ssize_t) image->rows; y++)
2507 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2508 if (p == (const Quantum *) NULL)
2510 for (x=0; x < (ssize_t) image->columns; x++)
2512 Ascii85Encode(image,ScaleQuantumToChar(GetPixelAlpha(image,p)));
2513 p+=GetPixelChannels(image);
2516 Ascii85Flush(image);
2520 offset=TellBlob(image)-offset;
2521 (void) WriteBlobString(image,"\nendstream\n");
2523 (void) WriteBlobString(image,"endobj\n");
2525 Write Length object.
2527 xref[object++]=TellBlob(image);
2528 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2530 (void) WriteBlobString(image,buffer);
2531 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2532 (void) WriteBlobString(image,buffer);
2533 (void) WriteBlobString(image,"endobj\n");
2534 if (GetNextImageInList(image) == (Image *) NULL)
2536 image=SyncNextImageInList(image);
2537 status=SetImageProgress(image,SaveImagesTag,scene++,
2538 GetImageListLength(image));
2539 if (status == MagickFalse)
2541 } while (image_info->adjoin != MagickFalse);
2543 Write Metadata object.
2545 xref[object++]=TellBlob(image);
2547 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2549 (void) WriteBlobString(image,buffer);
2550 (void) WriteBlobString(image,"<<\n");
2551 (void) FormatLocaleString(buffer,MaxTextExtent,"/Title (%s)\n",
2552 EscapeParenthesis(basename));
2553 (void) WriteBlobString(image,buffer);
2554 seconds=time((time_t *) NULL);
2555 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
2556 (void) localtime_r(&seconds,&local_time);
2558 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
2560 (void) FormatLocaleString(date,MaxTextExtent,"D:%04d%02d%02d%02d%02d%02d",
2561 local_time.tm_year+1900,local_time.tm_mon+1,local_time.tm_mday,
2562 local_time.tm_hour,local_time.tm_min,local_time.tm_sec);
2563 (void) FormatLocaleString(buffer,MaxTextExtent,"/CreationDate (%s)\n",date);
2564 (void) WriteBlobString(image,buffer);
2565 (void) FormatLocaleString(buffer,MaxTextExtent,"/ModDate (%s)\n",date);
2566 (void) WriteBlobString(image,buffer);
2567 (void) FormatLocaleString(buffer,MaxTextExtent,"/Producer (%s)\n",
2568 EscapeParenthesis(GetMagickVersion((size_t *) NULL)));
2569 (void) WriteBlobString(image,buffer);
2570 (void) WriteBlobString(image,">>\n");
2571 (void) WriteBlobString(image,"endobj\n");
2575 offset=TellBlob(image)-xref[0]+
2576 (LocaleCompare(image_info->magick,"PDFA") == 0 ? 6 : 0)+10;
2577 (void) WriteBlobString(image,"xref\n");
2578 (void) FormatLocaleString(buffer,MaxTextExtent,"0 %.20g\n",(double)
2580 (void) WriteBlobString(image,buffer);
2581 (void) WriteBlobString(image,"0000000000 65535 f \n");
2582 for (i=0; i < (ssize_t) object; i++)
2584 (void) FormatLocaleString(buffer,MaxTextExtent,"%010lu 00000 n \n",
2585 (unsigned long) xref[i]);
2586 (void) WriteBlobString(image,buffer);
2588 (void) WriteBlobString(image,"trailer\n");
2589 (void) WriteBlobString(image,"<<\n");
2590 (void) FormatLocaleString(buffer,MaxTextExtent,"/Size %.20g\n",(double)
2592 (void) WriteBlobString(image,buffer);
2593 (void) FormatLocaleString(buffer,MaxTextExtent,"/Info %.20g 0 R\n",(double)
2595 (void) WriteBlobString(image,buffer);
2596 (void) FormatLocaleString(buffer,MaxTextExtent,"/Root %.20g 0 R\n",(double)
2598 (void) WriteBlobString(image,buffer);
2599 (void) SignatureImage(image,exception);
2600 (void) FormatLocaleString(buffer,MaxTextExtent,"/ID [<%s> <%s>]\n",
2601 GetImageProperty(image,"signature",exception),
2602 GetImageProperty(image,"signature",exception));
2603 (void) WriteBlobString(image,buffer);
2604 (void) WriteBlobString(image,">>\n");
2605 (void) WriteBlobString(image,"startxref\n");
2606 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2607 (void) WriteBlobString(image,buffer);
2608 (void) WriteBlobString(image,"%%EOF\n");
2609 xref=(MagickOffsetType *) RelinquishMagickMemory(xref);
2610 (void) CloseBlob(image);