2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Portable Document Format %
20 % Copyright 1999-2012 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 status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
187 status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
189 (ghost_info->exit)(interpreter);
190 (ghost_info->delete_instance)(interpreter);
191 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
192 NTGhostscriptUnLoadDLL();
194 for (i=0; i < (ssize_t) argc; i++)
195 argv[i]=DestroyString(argv[i]);
196 argv=(char **) RelinquishMagickMemory(argv);
197 if ((status != 0) && (status != -101))
202 message=GetExceptionMessage(errno);
203 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
204 "`%s': %s",command,message);
205 message=DestroyString(message);
206 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
207 "Ghostscript returns status %d, exit code %d",status,code);
212 status=SystemCommand(MagickFalse,verbose,command,exception);
213 return(status == 0 ? MagickTrue : MagickFalse);
218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % IsPDF() returns MagickTrue if the image format type, identified by the
229 % magick string, is PDF.
231 % The format of the IsPDF method is:
233 % MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
235 % A description of each parameter follows:
237 % o magick: compare image format pattern against these bytes.
239 % o offset: Specifies the offset of the magick string.
242 static MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
246 if (LocaleNCompare((const char *) magick,"%PDF-",5) == 0)
252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 % R e a d P D F I m a g e %
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 % ReadPDFImage() reads a Portable Document Format image file and
263 % returns it. It allocates the memory necessary for the new Image structure
264 % and returns a pointer to the new image.
266 % The format of the ReadPDFImage method is:
268 % Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
270 % A description of each parameter follows:
272 % o image_info: the image info.
274 % o exception: return any errors or warnings in this structure.
278 static MagickBooleanType IsPDFRendered(const char *path)
286 if ((path == (const char *) NULL) || (*path == '\0'))
288 status=GetPathAttributes(path,&attributes);
289 if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
290 (attributes.st_size > 0))
295 static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
297 #define CMYKProcessColor "CMYKProcessColor"
298 #define CropBox "CropBox"
299 #define DefaultCMYK "DefaultCMYK"
300 #define DeviceCMYK "DeviceCMYK"
301 #define MediaBox "MediaBox"
302 #define RenderPostscriptText "Rendering Postscript... "
303 #define PDFRotate "Rotate"
304 #define SpotColor "Separation"
305 #define TrimBox "TrimBox"
306 #define PDFVersion "PDF-"
309 command[MaxTextExtent],
310 density[MaxTextExtent],
311 filename[MaxTextExtent],
312 geometry[MaxTextExtent],
313 options[MaxTextExtent],
314 input_filename[MaxTextExtent],
315 postscript_filename[MaxTextExtent];
374 assert(image_info != (const ImageInfo *) NULL);
375 assert(image_info->signature == MagickSignature);
376 if (image_info->debug != MagickFalse)
377 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
378 image_info->filename);
379 assert(exception != (ExceptionInfo *) NULL);
380 assert(exception->signature == MagickSignature);
384 image=AcquireImage(image_info,exception);
385 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
386 if (status == MagickFalse)
388 image=DestroyImageList(image);
389 return((Image *) NULL);
391 status=AcquireUniqueSymbolicLink(image_info->filename,input_filename);
392 if (status == MagickFalse)
394 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
395 image_info->filename);
396 image=DestroyImageList(image);
397 return((Image *) NULL);
400 Set the page density.
402 delta.x=DefaultResolution;
403 delta.y=DefaultResolution;
404 if ((image->resolution.x == 0.0) || (image->resolution.y == 0.0))
406 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
407 image->resolution.x=geometry_info.rho;
408 image->resolution.y=geometry_info.sigma;
409 if ((flags & SigmaValue) == 0)
410 image->resolution.y=image->resolution.x;
412 if (image_info->density != (char *) NULL)
414 flags=ParseGeometry(image_info->density,&geometry_info);
415 image->resolution.x=geometry_info.rho;
416 image->resolution.y=geometry_info.sigma;
417 if ((flags & SigmaValue) == 0)
418 image->resolution.y=image->resolution.x;
420 (void) ParseAbsoluteGeometry(PSPageGeometry,&page);
421 if (image_info->page != (char *) NULL)
422 (void) ParseAbsoluteGeometry(image_info->page,&page);
423 page.width=(size_t) ceil((double) (page.width*image->resolution.x/delta.x)-
425 page.height=(size_t) ceil((double) (page.height*image->resolution.y/delta.y)-
428 Determine page geometry from the PDF media box.
430 cmyk=image_info->colorspace == CMYKColorspace ? MagickTrue : MagickFalse;
431 cropbox=IsStringTrue(GetImageOption(image_info,"pdf:use-cropbox"));
432 trimbox=IsStringTrue(GetImageOption(image_info,"pdf:use-trimbox"));
435 (void) ResetMagickMemory(&bounding_box,0,sizeof(bounding_box));
436 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
437 (void) ResetMagickMemory(&hires_bounds,0,sizeof(hires_bounds));
438 (void) ResetMagickMemory(command,0,sizeof(command));
441 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
449 if ((c != (int) '/') && (c != (int) '%') &&
450 ((size_t) (p-command) < (MaxTextExtent-1)))
454 if (LocaleNCompare(PDFRotate,command,strlen(PDFRotate)) == 0)
455 count=(ssize_t) sscanf(command,"Rotate %lf",&angle);
457 Is this a CMYK document?
459 if (LocaleNCompare(DefaultCMYK,command,strlen(DefaultCMYK)) == 0)
461 if (LocaleNCompare(DeviceCMYK,command,strlen(DeviceCMYK)) == 0)
463 if (LocaleNCompare(CMYKProcessColor,command,strlen(CMYKProcessColor)) == 0)
465 if (LocaleNCompare(SpotColor,command,strlen(SpotColor)) == 0)
469 property[MaxTextExtent],
478 (void) FormatLocaleString(property,MaxTextExtent,"pdf:SpotColor-%.20g",
479 (double) spotcolor++);
481 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
483 if ((isspace(c) != 0) || (c == '/') || ((i+1) == MaxTextExtent))
488 value=AcquireString(name);
489 (void) SubstituteString(&value,"#20"," ");
490 (void) SetImageProperty(image,property,value,exception);
491 value=DestroyString(value);
494 if (LocaleNCompare(PDFVersion,command,strlen(PDFVersion)) == 0)
495 (void) SetImageProperty(image,"pdf:Version",command,exception);
496 if (image_info->page != (char *) NULL)
499 if (cropbox != MagickFalse)
501 if (LocaleNCompare(CropBox,command,strlen(CropBox)) == 0)
504 Note region defined by crop box.
506 count=(ssize_t) sscanf(command,"CropBox [%lf %lf %lf %lf",
507 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
509 count=(ssize_t) sscanf(command,"CropBox[%lf %lf %lf %lf",
510 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
514 if (trimbox != MagickFalse)
516 if (LocaleNCompare(TrimBox,command,strlen(TrimBox)) == 0)
519 Note region defined by trim box.
521 count=(ssize_t) sscanf(command,"TrimBox [%lf %lf %lf %lf",
522 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
524 count=(ssize_t) sscanf(command,"TrimBox[%lf %lf %lf %lf",
525 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
529 if (LocaleNCompare(MediaBox,command,strlen(MediaBox)) == 0)
532 Note region defined by media box.
534 count=(ssize_t) sscanf(command,"MediaBox [%lf %lf %lf %lf",
535 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
537 count=(ssize_t) sscanf(command,"MediaBox[%lf %lf %lf %lf",
538 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
542 if ((fabs(bounds.x2-bounds.x1) <= fabs(hires_bounds.x2-hires_bounds.x1)) ||
543 (fabs(bounds.y2-bounds.y1) <= fabs(hires_bounds.y2-hires_bounds.y1)))
547 if ((fabs(hires_bounds.x2-hires_bounds.x1) >= MagickEpsilon) &&
548 (fabs(hires_bounds.y2-hires_bounds.y1) >= MagickEpsilon))
551 Set PDF render geometry.
553 (void) FormatLocaleString(geometry,MaxTextExtent,"%gx%g%+.15g%+.15g",
554 hires_bounds.x2-bounds.x1,hires_bounds.y2-hires_bounds.y1,
555 hires_bounds.x1,hires_bounds.y1);
556 (void) SetImageProperty(image,"pdf:HiResBoundingBox",geometry,exception);
557 page.width=(size_t) ceil((double) ((hires_bounds.x2-hires_bounds.x1)*
558 image->resolution.x/delta.x)-0.5);
559 page.height=(size_t) ceil((double) ((hires_bounds.y2-hires_bounds.y1)*
560 image->resolution.y/delta.y)-0.5);
562 (void) CloseBlob(image);
563 if ((fabs(angle) == 90.0) || (fabs(angle) == 270.0))
569 page.width=page.height;
572 if (IssRGBCompatibleColorspace(image_info->colorspace) != MagickFalse)
575 Create Ghostscript control file.
577 file=AcquireUniqueFileResource(postscript_filename);
580 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
581 image_info->filename);
582 image=DestroyImage(image);
583 return((Image *) NULL);
585 count=write(file," ",1);
588 Render Postscript with the Ghostscript delegate.
590 if ((image_info->ping != MagickFalse) ||
591 (image_info->monochrome != MagickFalse))
592 delegate_info=GetDelegateInfo("ps:mono",(char *) NULL,exception);
594 if (cmyk != MagickFalse)
595 delegate_info=GetDelegateInfo("ps:cmyk",(char *) NULL,exception);
597 delegate_info=GetDelegateInfo("ps:alpha",(char *) NULL,exception);
598 if (delegate_info == (const DelegateInfo *) NULL)
600 (void) RelinquishUniqueFileResource(postscript_filename);
601 image=DestroyImage(image);
602 return((Image *) NULL);
605 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",image->resolution.x,
606 image->resolution.y);
607 if (image_info->page != (char *) NULL)
608 (void) FormatLocaleString(options,MaxTextExtent,"-g%.20gx%.20g ",(double)
609 page.width,(double) page.height);
610 if (cmyk != MagickFalse)
611 (void) ConcatenateMagickString(options,"-dUseCIEColor ",MaxTextExtent);
612 if (cropbox != MagickFalse)
613 (void) ConcatenateMagickString(options,"-dUseCropBox ",MaxTextExtent);
614 if (trimbox != MagickFalse)
615 (void) ConcatenateMagickString(options,"-dUseTrimBox ",MaxTextExtent);
616 read_info=CloneImageInfo(image_info);
617 *read_info->magick='\0';
618 if (read_info->number_scenes != 0)
621 pages[MaxTextExtent];
623 (void) FormatLocaleString(pages,MaxTextExtent,"-dFirstPage=%.20g "
624 "-dLastPage=%.20g",(double) read_info->scene+1,(double)
625 (read_info->scene+read_info->number_scenes));
626 (void) ConcatenateMagickString(options,pages,MaxTextExtent);
627 read_info->number_scenes=0;
628 if (read_info->scenes != (char *) NULL)
629 *read_info->scenes='\0';
631 option=GetImageOption(read_info,"authenticate");
632 if (option != (const char *) NULL)
633 (void) FormatLocaleString(options+strlen(options),MaxTextExtent,
634 " -sPCLPassword=%s",option);
635 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
636 (void) AcquireUniqueFilename(filename);
637 (void) ConcatenateMagickString(filename,"-%08d",MaxTextExtent);
638 (void) FormatLocaleString(command,MaxTextExtent,
639 GetDelegateCommands(delegate_info),
640 read_info->antialias != MagickFalse ? 4 : 1,
641 read_info->antialias != MagickFalse ? 4 : 1,density,options,filename,
642 postscript_filename,input_filename);
643 status=InvokePDFDelegate(read_info->verbose,command,exception);
644 (void) RelinquishUniqueFileResource(postscript_filename);
645 (void) RelinquishUniqueFileResource(input_filename);
646 pdf_image=(Image *) NULL;
647 if (status == MagickFalse)
650 (void) InterpretImageFilename(image_info,image,filename,(int) i,
651 read_info->filename,exception);
652 if (IsPDFRendered(read_info->filename) == MagickFalse)
654 (void) RelinquishUniqueFileResource(read_info->filename);
659 (void) InterpretImageFilename(image_info,image,filename,(int) i,
660 read_info->filename,exception);
661 if (IsPDFRendered(read_info->filename) == MagickFalse)
663 read_info->blob=NULL;
665 next=ReadImage(read_info,exception);
666 (void) RelinquishUniqueFileResource(read_info->filename);
667 if (next == (Image *) NULL)
669 AppendImageToList(&pdf_image,next);
671 read_info=DestroyImageInfo(read_info);
672 if (pdf_image == (Image *) NULL)
674 ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
675 image_info->filename);
676 image=DestroyImage(image);
677 return((Image *) NULL);
679 if (LocaleCompare(pdf_image->magick,"BMP") == 0)
684 cmyk_image=ConsolidateCMYKImages(pdf_image,exception);
685 if (cmyk_image != (Image *) NULL)
687 pdf_image=DestroyImageList(pdf_image);
688 pdf_image=cmyk_image;
691 if (image_info->number_scenes != 0)
700 Add place holder images to meet the subimage specification requirement.
702 for (i=0; i < (ssize_t) image_info->scene; i++)
704 clone_image=CloneImage(pdf_image,1,1,MagickTrue,exception);
705 if (clone_image != (Image *) NULL)
706 PrependImageToList(&pdf_image,clone_image);
711 (void) CopyMagickString(pdf_image->filename,filename,MaxTextExtent);
712 pdf_image->page=page;
713 (void) CloneImageProfiles(pdf_image,image);
714 (void) CloneImageProperties(pdf_image,image);
715 next=SyncNextImageInList(pdf_image);
716 if (next != (Image *) NULL)
718 } while (next != (Image *) NULL);
719 image=DestroyImage(image);
721 for (next=GetFirstImageInList(pdf_image); next != (Image *) NULL; )
724 next=GetNextImageInList(next);
726 return(GetFirstImageInList(pdf_image));
730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734 % R e g i s t e r P D F I m a g e %
738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740 % RegisterPDFImage() adds properties for the PDF image format to
741 % the list of supported formats. The properties include the image format
742 % tag, a method to read and/or write the format, whether the format
743 % supports the saving of more than one frame to the same file or blob,
744 % whether the format supports native in-memory I/O, and a brief
745 % description of the format.
747 % The format of the RegisterPDFImage method is:
749 % size_t RegisterPDFImage(void)
752 ModuleExport size_t RegisterPDFImage(void)
757 entry=SetMagickInfo("AI");
758 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
759 entry->encoder=(EncodeImageHandler *) WritePDFImage;
760 entry->adjoin=MagickFalse;
761 entry->blob_support=MagickFalse;
762 entry->seekable_stream=MagickTrue;
763 entry->thread_support=EncoderThreadSupport;
764 entry->description=ConstantString("Adobe Illustrator CS2");
765 entry->module=ConstantString("PDF");
766 (void) RegisterMagickInfo(entry);
767 entry=SetMagickInfo("EPDF");
768 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
769 entry->encoder=(EncodeImageHandler *) WritePDFImage;
770 entry->adjoin=MagickFalse;
771 entry->blob_support=MagickFalse;
772 entry->seekable_stream=MagickTrue;
773 entry->thread_support=EncoderThreadSupport;
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->thread_support=EncoderThreadSupport;
784 entry->description=ConstantString("Portable Document Format");
785 entry->module=ConstantString("PDF");
786 (void) RegisterMagickInfo(entry);
787 entry=SetMagickInfo("PDFA");
788 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
789 entry->encoder=(EncodeImageHandler *) WritePDFImage;
790 entry->magick=(IsImageFormatHandler *) IsPDF;
791 entry->blob_support=MagickFalse;
792 entry->seekable_stream=MagickTrue;
793 entry->thread_support=EncoderThreadSupport;
794 entry->description=ConstantString("Portable Document Archive Format");
795 entry->module=ConstantString("PDF");
796 (void) RegisterMagickInfo(entry);
797 return(MagickImageCoderSignature);
801 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805 % U n r e g i s t e r P D F I m a g e %
809 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
811 % UnregisterPDFImage() removes format registrations made by the
812 % PDF module from the list of supported formats.
814 % The format of the UnregisterPDFImage method is:
816 % UnregisterPDFImage(void)
819 ModuleExport void UnregisterPDFImage(void)
821 (void) UnregisterMagickInfo("AI");
822 (void) UnregisterMagickInfo("EPDF");
823 (void) UnregisterMagickInfo("PDF");
824 (void) UnregisterMagickInfo("PDFA");
828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
832 % W r i t e P D F I m a g e %
836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838 % WritePDFImage() writes an image in the Portable Document image
841 % The format of the WritePDFImage method is:
843 % MagickBooleanType WritePDFImage(const ImageInfo *image_info,
844 % Image *image,ExceptionInfo *exception)
846 % A description of each parameter follows.
848 % o image_info: the image info.
850 % o image: The image.
852 % o exception: return any errors or warnings in this structure.
856 static inline size_t MagickMax(const size_t x,const size_t y)
863 static inline size_t MagickMin(const size_t x,const size_t y)
870 static char *EscapeParenthesis(const char *text)
882 buffer[MaxTextExtent];
886 for (i=0; i < (ssize_t) MagickMin(strlen(text),(MaxTextExtent-escapes-1)); i++)
888 if ((text[i] == '(') || (text[i] == ')'))
899 static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info,
900 Image *image,Image *inject_image,ExceptionInfo *exception)
918 write_info=CloneImageInfo(image_info);
919 (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent);
920 (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent);
921 group4_image=CloneImage(inject_image,0,0,MagickTrue,exception);
922 if (group4_image == (Image *) NULL)
924 group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length,
926 group4_image=DestroyImage(group4_image);
927 if (group4 == (unsigned char *) NULL)
929 write_info=DestroyImageInfo(write_info);
930 if (WriteBlob(image,length,group4) != (ssize_t) length)
932 group4=(unsigned char *) RelinquishMagickMemory(group4);
936 static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image,
937 ExceptionInfo *exception)
939 #define CFormat "/Filter [ /%s ]\n"
940 #define ObjectsPerImage 14
945 "<?xpacket begin=\"%s\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
946 "<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"
947 " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
948 " <rdf:Description rdf:about=\"\"\n"
949 " xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">\n"
950 " <xap:ModifyDate>%s</xap:ModifyDate>\n"
951 " <xap:CreateDate>%s</xap:CreateDate>\n"
952 " <xap:MetadataDate>%s</xap:MetadataDate>\n"
953 " <xap:CreatorTool>%s</xap:CreatorTool>\n"
954 " </rdf:Description>\n"
955 " <rdf:Description rdf:about=\"\"\n"
956 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
957 " <dc:format>application/pdf</dc:format>\n"
960 " <rdf:li xml:lang=\"x-default\">%s</rdf:li>\n"
963 " </rdf:Description>\n"
964 " <rdf:Description rdf:about=\"\"\n"
965 " xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\">\n"
966 " <xapMM:DocumentID>uuid:6ec119d7-7982-4f56-808d-dfe64f5b35cf</xapMM:DocumentID>\n"
967 " <xapMM:InstanceID>uuid:a79b99b4-6235-447f-9f6c-ec18ef7555cb</xapMM:InstanceID>\n"
968 " </rdf:Description>\n"
969 " <rdf:Description rdf:about=\"\"\n"
970 " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">\n"
971 " <pdf:Producer>%s</pdf:Producer>\n"
972 " </rdf:Description>\n"
973 " <rdf:Description rdf:about=\"\"\n"
974 " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n"
975 " <pdfaid:part>2</pdfaid:part>\n"
976 " <pdfaid:conformance>B</pdfaid:conformance>\n"
977 " </rdf:Description>\n"
980 "<?xpacket end=\"w\"?>\n"
982 XMPProfileMagick[4]= { (char) 0xef, (char) 0xbb, (char) 0xbf, (char) 0x00 };
985 basename[MaxTextExtent],
986 buffer[MaxTextExtent],
989 page_geometry[MaxTextExtent];
1031 register const Quantum
1034 register unsigned char
1064 Open output image file.
1066 assert(image_info != (const ImageInfo *) NULL);
1067 assert(image_info->signature == MagickSignature);
1068 assert(image != (Image *) NULL);
1069 assert(image->signature == MagickSignature);
1070 if (image->debug != MagickFalse)
1071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1072 assert(exception != (ExceptionInfo *) NULL);
1073 assert(exception->signature == MagickSignature);
1074 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1075 if (status == MagickFalse)
1078 Allocate X ref memory.
1080 xref=(MagickOffsetType *) AcquireQuantumMemory(2048UL,sizeof(*xref));
1081 if (xref == (MagickOffsetType *) NULL)
1082 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1083 (void) ResetMagickMemory(xref,0,2048UL*sizeof(*xref));
1089 if (image_info->compression == JPEG2000Compression)
1090 version=(size_t) MagickMax(version,5);
1091 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1092 if (next->alpha_trait == BlendPixelTrait)
1093 version=(size_t) MagickMax(version,4);
1094 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1095 version=(size_t) MagickMax(version,6);
1096 (void) FormatLocaleString(buffer,MaxTextExtent,"%%PDF-1.%.20g \n",(double)
1098 (void) WriteBlobString(image,buffer);
1099 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1100 (void) WriteBlobString(image,"%âãÏÓ\n");
1102 Write Catalog object.
1104 xref[object++]=TellBlob(image);
1106 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1108 (void) WriteBlobString(image,buffer);
1109 (void) WriteBlobString(image,"<<\n");
1110 if (LocaleCompare(image_info->magick,"PDFA") != 0)
1111 (void) FormatLocaleString(buffer,MaxTextExtent,"/Pages %.20g 0 R\n",(double)
1115 (void) FormatLocaleString(buffer,MaxTextExtent,"/Metadata %.20g 0 R\n",
1117 (void) WriteBlobString(image,buffer);
1118 (void) FormatLocaleString(buffer,MaxTextExtent,"/Pages %.20g 0 R\n",
1121 (void) WriteBlobString(image,buffer);
1122 (void) WriteBlobString(image,"/Type /Catalog\n");
1123 (void) WriteBlobString(image,">>\n");
1124 (void) WriteBlobString(image,"endobj\n");
1125 GetPathComponent(image->filename,BasePath,basename);
1126 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1129 create_date[MaxTextExtent],
1130 modify_date[MaxTextExtent],
1131 timestamp[MaxTextExtent],
1132 xmp_profile[MaxTextExtent];
1140 xref[object++]=TellBlob(image);
1141 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1143 (void) WriteBlobString(image,buffer);
1144 (void) WriteBlobString(image,"<<\n");
1145 (void) WriteBlobString(image,"/Subtype /XML\n");
1147 value=GetImageProperty(image,"date:modify",exception);
1148 if (value != (const char *) NULL)
1149 (void) CopyMagickString(modify_date,value,MaxTextExtent);
1151 value=GetImageProperty(image,"date:create",exception);
1152 if (value != (const char *) NULL)
1153 (void) CopyMagickString(create_date,value,MaxTextExtent);
1154 (void) FormatMagickTime(time((time_t *) NULL),MaxTextExtent,timestamp);
1155 i=FormatLocaleString(xmp_profile,MaxTextExtent,XMPProfile,
1156 XMPProfileMagick,modify_date,create_date,timestamp,
1157 GetMagickVersion(&version),EscapeParenthesis(basename),
1158 GetMagickVersion(&version));
1159 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g\n",(double)
1161 (void) WriteBlobString(image,buffer);
1162 (void) WriteBlobString(image,"/Type /Metadata\n");
1163 (void) WriteBlobString(image,">>\nstream\n");
1164 (void) WriteBlobString(image,xmp_profile);
1165 (void) WriteBlobString(image,"\nendstream\n");
1166 (void) WriteBlobString(image,"endobj\n");
1171 xref[object++]=TellBlob(image);
1173 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1175 (void) WriteBlobString(image,buffer);
1176 (void) WriteBlobString(image,"<<\n");
1177 (void) WriteBlobString(image,"/Type /Pages\n");
1178 (void) FormatLocaleString(buffer,MaxTextExtent,"/Kids [ %.20g 0 R ",(double)
1180 (void) WriteBlobString(image,buffer);
1181 count=(ssize_t) (pages_id+ObjectsPerImage+1);
1182 if (image_info->adjoin != MagickFalse)
1188 Predict page object id's.
1191 for ( ; GetNextImageInList(kid_image) != (Image *) NULL; count+=ObjectsPerImage)
1193 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 R ",(double)
1195 (void) WriteBlobString(image,buffer);
1196 kid_image=GetNextImageInList(kid_image);
1198 xref=(MagickOffsetType *) ResizeQuantumMemory(xref,(size_t) count+2048UL,
1200 if (xref == (MagickOffsetType *) NULL)
1201 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1203 (void) WriteBlobString(image,"]\n");
1204 (void) FormatLocaleString(buffer,MaxTextExtent,"/Count %.20g\n",(double)
1205 ((count-pages_id)/ObjectsPerImage));
1206 (void) WriteBlobString(image,buffer);
1207 (void) WriteBlobString(image,">>\n");
1208 (void) WriteBlobString(image,"endobj\n");
1212 compression=image->compression;
1213 if (image_info->compression != UndefinedCompression)
1214 compression=image_info->compression;
1215 switch (compression)
1217 case FaxCompression:
1218 case Group4Compression:
1220 if ((IsImageMonochrome(image,exception) == MagickFalse) ||
1221 (image->alpha_trait == BlendPixelTrait))
1222 compression=RLECompression;
1225 #if !defined(MAGICKCORE_JPEG_DELEGATE)
1226 case JPEGCompression:
1228 compression=RLECompression;
1229 (void) ThrowMagickException(exception,GetMagickModule(),
1230 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)",
1235 #if !defined(MAGICKCORE_JP2_DELEGATE)
1236 case JPEG2000Compression:
1238 compression=RLECompression;
1239 (void) ThrowMagickException(exception,GetMagickModule(),
1240 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JP2)",
1245 #if !defined(MAGICKCORE_ZLIB_DELEGATE)
1246 case ZipCompression:
1248 compression=RLECompression;
1249 (void) ThrowMagickException(exception,GetMagickModule(),
1250 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (ZLIB)",
1255 case LZWCompression:
1257 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1258 compression=RLECompression; /* LZW compression is forbidden */
1263 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1264 compression=RLECompression; /* ASCII 85 compression is forbidden */
1270 if (compression == JPEG2000Compression)
1272 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
1273 (void) TransformImageColorspace(image,sRGBColorspace,exception);
1276 Scale relative to dots-per-inch.
1278 delta.x=DefaultResolution;
1279 delta.y=DefaultResolution;
1280 resolution.x=image->resolution.x;
1281 resolution.y=image->resolution.y;
1282 if ((resolution.x == 0.0) || (resolution.y == 0.0))
1284 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
1285 resolution.x=geometry_info.rho;
1286 resolution.y=geometry_info.sigma;
1287 if ((flags & SigmaValue) == 0)
1288 resolution.y=resolution.x;
1290 if (image_info->density != (char *) NULL)
1292 flags=ParseGeometry(image_info->density,&geometry_info);
1293 resolution.x=geometry_info.rho;
1294 resolution.y=geometry_info.sigma;
1295 if ((flags & SigmaValue) == 0)
1296 resolution.y=resolution.x;
1298 if (image->units == PixelsPerCentimeterResolution)
1300 resolution.x=(double) ((size_t) (100.0*2.54*resolution.x+0.5)/100.0);
1301 resolution.y=(double) ((size_t) (100.0*2.54*resolution.y+0.5)/100.0);
1303 SetGeometry(image,&geometry);
1304 (void) FormatLocaleString(page_geometry,MaxTextExtent,"%.20gx%.20g",(double)
1305 image->columns,(double) image->rows);
1306 if (image_info->page != (char *) NULL)
1307 (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent);
1309 if ((image->page.width != 0) && (image->page.height != 0))
1310 (void) FormatLocaleString(page_geometry,MaxTextExtent,
1311 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
1312 image->page.height,(double) image->page.x,(double) image->page.y);
1314 if ((image->gravity != UndefinedGravity) &&
1315 (LocaleCompare(image_info->magick,"PDF") == 0))
1316 (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent);
1317 (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent);
1318 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
1319 &geometry.width,&geometry.height);
1320 scale.x=(double) (geometry.width*delta.x)/resolution.x;
1321 geometry.width=(size_t) floor(scale.x+0.5);
1322 scale.y=(double) (geometry.height*delta.y)/resolution.y;
1323 geometry.height=(size_t) floor(scale.y+0.5);
1324 (void) ParseAbsoluteGeometry(page_geometry,&media_info);
1325 (void) ParseGravityGeometry(image,page_geometry,&page_info,exception);
1326 if (image->gravity != UndefinedGravity)
1328 geometry.x=(-page_info.x);
1329 geometry.y=(ssize_t) (media_info.height+page_info.y-image->rows);
1332 if (image_info->pointsize != 0.0)
1333 pointsize=image_info->pointsize;
1335 value=GetImageProperty(image,"label",exception);
1336 if (value != (const char *) NULL)
1337 text_size=(size_t) (MultilineCensus(value)*pointsize+12);
1342 xref[object++]=TellBlob(image);
1343 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1345 (void) WriteBlobString(image,buffer);
1346 (void) WriteBlobString(image,"<<\n");
1347 (void) WriteBlobString(image,"/Type /Page\n");
1348 (void) FormatLocaleString(buffer,MaxTextExtent,"/Parent %.20g 0 R\n",
1350 (void) WriteBlobString(image,buffer);
1351 (void) WriteBlobString(image,"/Resources <<\n");
1352 labels=(char **) NULL;
1353 value=GetImageProperty(image,"label",exception);
1354 if (value != (const char *) NULL)
1355 labels=StringToList(value);
1356 if (labels != (char **) NULL)
1358 (void) FormatLocaleString(buffer,MaxTextExtent,
1359 "/Font << /F%.20g %.20g 0 R >>\n",(double) image->scene,(double)
1361 (void) WriteBlobString(image,buffer);
1363 (void) FormatLocaleString(buffer,MaxTextExtent,
1364 "/XObject << /Im%.20g %.20g 0 R >>\n",(double) image->scene,(double)
1366 (void) WriteBlobString(image,buffer);
1367 (void) FormatLocaleString(buffer,MaxTextExtent,"/ProcSet %.20g 0 R >>\n",
1369 (void) WriteBlobString(image,buffer);
1370 (void) FormatLocaleString(buffer,MaxTextExtent,
1371 "/MediaBox [0 0 %g %g]\n",72.0*media_info.width/resolution.x,
1372 72.0*media_info.height/resolution.y);
1373 (void) WriteBlobString(image,buffer);
1374 (void) FormatLocaleString(buffer,MaxTextExtent,
1375 "/CropBox [0 0 %g %g]\n",72.0*media_info.width/resolution.x,
1376 72.0*media_info.height/resolution.y);
1377 (void) WriteBlobString(image,buffer);
1378 (void) FormatLocaleString(buffer,MaxTextExtent,"/Contents %.20g 0 R\n",
1380 (void) WriteBlobString(image,buffer);
1381 (void) FormatLocaleString(buffer,MaxTextExtent,"/Thumb %.20g 0 R\n",(double)
1383 (void) WriteBlobString(image,buffer);
1384 (void) WriteBlobString(image,">>\n");
1385 (void) WriteBlobString(image,"endobj\n");
1387 Write Contents object.
1389 xref[object++]=TellBlob(image);
1390 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1392 (void) WriteBlobString(image,buffer);
1393 (void) WriteBlobString(image,"<<\n");
1394 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1396 (void) WriteBlobString(image,buffer);
1397 (void) WriteBlobString(image,">>\n");
1398 (void) WriteBlobString(image,"stream\n");
1399 offset=TellBlob(image);
1400 (void) WriteBlobString(image,"q\n");
1401 if (labels != (char **) NULL)
1402 for (i=0; labels[i] != (char *) NULL; i++)
1404 (void) WriteBlobString(image,"BT\n");
1405 (void) FormatLocaleString(buffer,MaxTextExtent,"/F%.20g %g Tf\n",
1406 (double) image->scene,pointsize);
1407 (void) WriteBlobString(image,buffer);
1408 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g Td\n",
1409 (double) geometry.x,(double) (geometry.y+geometry.height+i*pointsize+
1411 (void) WriteBlobString(image,buffer);
1412 (void) FormatLocaleString(buffer,MaxTextExtent,"(%s) Tj\n",labels[i]);
1413 (void) WriteBlobString(image,buffer);
1414 (void) WriteBlobString(image,"ET\n");
1415 labels[i]=DestroyString(labels[i]);
1417 (void) FormatLocaleString(buffer,MaxTextExtent,"%g 0 0 %g %.20g %.20g cm\n",
1418 scale.x,scale.y,(double) geometry.x,(double) geometry.y);
1419 (void) WriteBlobString(image,buffer);
1420 (void) FormatLocaleString(buffer,MaxTextExtent,"/Im%.20g Do\n",(double)
1422 (void) WriteBlobString(image,buffer);
1423 (void) WriteBlobString(image,"Q\n");
1424 offset=TellBlob(image)-offset;
1425 (void) WriteBlobString(image,"\nendstream\n");
1426 (void) WriteBlobString(image,"endobj\n");
1428 Write Length object.
1430 xref[object++]=TellBlob(image);
1431 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1433 (void) WriteBlobString(image,buffer);
1434 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
1435 (void) WriteBlobString(image,buffer);
1436 (void) WriteBlobString(image,"endobj\n");
1438 Write Procset object.
1440 xref[object++]=TellBlob(image);
1441 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1443 (void) WriteBlobString(image,buffer);
1444 if ((image->storage_class == DirectClass) || (image->colors > 256))
1445 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageC",MaxTextExtent);
1447 if ((compression == FaxCompression) || (compression == Group4Compression))
1448 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageB",MaxTextExtent);
1450 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageI",MaxTextExtent);
1451 (void) WriteBlobString(image,buffer);
1452 (void) WriteBlobString(image," ]\n");
1453 (void) WriteBlobString(image,"endobj\n");
1457 xref[object++]=TellBlob(image);
1458 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1460 (void) WriteBlobString(image,buffer);
1461 (void) WriteBlobString(image,"<<\n");
1462 if (labels != (char **) NULL)
1464 (void) WriteBlobString(image,"/Type /Font\n");
1465 (void) WriteBlobString(image,"/Subtype /Type1\n");
1466 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /F%.20g\n",
1467 (double) image->scene);
1468 (void) WriteBlobString(image,buffer);
1469 (void) WriteBlobString(image,"/BaseFont /Helvetica\n");
1470 (void) WriteBlobString(image,"/Encoding /MacRomanEncoding\n");
1471 labels=(char **) RelinquishMagickMemory(labels);
1473 (void) WriteBlobString(image,">>\n");
1474 (void) WriteBlobString(image,"endobj\n");
1476 Write XObject object.
1478 xref[object++]=TellBlob(image);
1479 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1481 (void) WriteBlobString(image,buffer);
1482 (void) WriteBlobString(image,"<<\n");
1483 (void) WriteBlobString(image,"/Type /XObject\n");
1484 (void) WriteBlobString(image,"/Subtype /Image\n");
1485 (void) FormatLocaleString(buffer,MaxTextExtent,"/Name /Im%.20g\n",(double)
1487 (void) WriteBlobString(image,buffer);
1488 switch (compression)
1492 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1495 case JPEGCompression:
1497 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1498 if (image->colorspace != CMYKColorspace)
1500 (void) WriteBlobString(image,buffer);
1501 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1505 case JPEG2000Compression:
1507 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1508 if (image->colorspace != CMYKColorspace)
1510 (void) WriteBlobString(image,buffer);
1511 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1515 case LZWCompression:
1517 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1520 case ZipCompression:
1522 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1525 case FaxCompression:
1526 case Group4Compression:
1528 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1530 (void) WriteBlobString(image,buffer);
1531 (void) FormatLocaleString(buffer,MaxTextExtent,"/DecodeParms [ << "
1532 "/K %s /BlackIs1 false /Columns %.20g /Rows %.20g >> ]\n",CCITTParam,
1533 (double) image->columns,(double) image->rows);
1538 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
1543 (void) WriteBlobString(image,buffer);
1544 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
1546 (void) WriteBlobString(image,buffer);
1547 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",(double)
1549 (void) WriteBlobString(image,buffer);
1550 (void) FormatLocaleString(buffer,MaxTextExtent,"/ColorSpace %.20g 0 R\n",
1552 (void) WriteBlobString(image,buffer);
1553 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
1554 (compression == FaxCompression) || (compression == Group4Compression) ?
1556 (void) WriteBlobString(image,buffer);
1557 if (image->alpha_trait == BlendPixelTrait)
1559 (void) FormatLocaleString(buffer,MaxTextExtent,"/SMask %.20g 0 R\n",
1561 (void) WriteBlobString(image,buffer);
1563 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
1565 (void) WriteBlobString(image,buffer);
1566 (void) WriteBlobString(image,">>\n");
1567 (void) WriteBlobString(image,"stream\n");
1568 offset=TellBlob(image);
1569 number_pixels=(MagickSizeType) image->columns*image->rows;
1570 if ((4*number_pixels) != (MagickSizeType) ((size_t) (4*number_pixels)))
1571 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1572 if ((compression == FaxCompression) || (compression == Group4Compression) ||
1573 ((image_info->type != TrueColorType) &&
1574 (IsImageGray(image,exception) != MagickFalse)))
1576 switch (compression)
1578 case FaxCompression:
1579 case Group4Compression:
1581 if (LocaleCompare(CCITTParam,"0") == 0)
1583 (void) HuffmanEncodeImage(image_info,image,image,exception);
1586 (void) Huffman2DEncodeImage(image_info,image,image,exception);
1589 case JPEGCompression:
1591 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
1592 if (status == MagickFalse)
1594 (void) CloseBlob(image);
1595 return(MagickFalse);
1599 case JPEG2000Compression:
1601 status=InjectImageBlob(image_info,image,image,"jp2",exception);
1602 if (status == MagickFalse)
1604 (void) CloseBlob(image);
1605 return(MagickFalse);
1609 case RLECompression:
1613 Allocate pixel array.
1615 length=(size_t) number_pixels;
1616 pixels=(unsigned char *) AcquireQuantumMemory(length,
1618 if (pixels == (unsigned char *) NULL)
1619 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1621 Dump Runlength encoded pixels.
1624 for (y=0; y < (ssize_t) image->rows; y++)
1626 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1627 if (p == (const Quantum *) NULL)
1629 for (x=0; x < (ssize_t) image->columns; x++)
1631 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
1632 p+=GetPixelChannels(image);
1634 if (image->previous == (Image *) NULL)
1636 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1638 if (status == MagickFalse)
1642 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1643 if (compression == ZipCompression)
1644 status=ZLIBEncodeImage(image,length,pixels,exception);
1647 if (compression == LZWCompression)
1648 status=LZWEncodeImage(image,length,pixels,exception);
1650 status=PackbitsEncodeImage(image,length,pixels,exception);
1651 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1652 if (status == MagickFalse)
1654 (void) CloseBlob(image);
1655 return(MagickFalse);
1662 Dump uncompressed PseudoColor packets.
1664 Ascii85Initialize(image);
1665 for (y=0; y < (ssize_t) image->rows; y++)
1667 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1668 if (p == (const Quantum *) NULL)
1670 for (x=0; x < (ssize_t) image->columns; x++)
1672 Ascii85Encode(image,ScaleQuantumToChar(
1673 GetPixelIntensity(image,p)));
1674 p+=GetPixelChannels(image);
1676 if (image->previous == (Image *) NULL)
1678 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1680 if (status == MagickFalse)
1684 Ascii85Flush(image);
1690 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1691 (compression == JPEGCompression) ||
1692 (compression == JPEG2000Compression))
1693 switch (compression)
1695 case JPEGCompression:
1697 status=InjectImageBlob(image_info,image,image,"jpeg",exception);
1698 if (status == MagickFalse)
1700 (void) CloseBlob(image);
1701 return(MagickFalse);
1705 case JPEG2000Compression:
1707 status=InjectImageBlob(image_info,image,image,"jp2",exception);
1708 if (status == MagickFalse)
1710 (void) CloseBlob(image);
1711 return(MagickFalse);
1715 case RLECompression:
1719 Allocate pixel array.
1721 length=(size_t) number_pixels;
1722 pixels=(unsigned char *) AcquireQuantumMemory(length,
1724 length*=image->colorspace == CMYKColorspace ? 4UL : 3UL;
1725 if (pixels == (unsigned char *) NULL)
1726 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1728 Dump runoffset encoded pixels.
1731 for (y=0; y < (ssize_t) image->rows; y++)
1733 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1734 if (p == (const Quantum *) NULL)
1736 for (x=0; x < (ssize_t) image->columns; x++)
1738 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1739 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1740 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1741 if (image->colorspace == CMYKColorspace)
1742 *q++=ScaleQuantumToChar(GetPixelBlack(image,p));
1743 p+=GetPixelChannels(image);
1745 if (image->previous == (Image *) NULL)
1747 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1749 if (status == MagickFalse)
1753 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1754 if (compression == ZipCompression)
1755 status=ZLIBEncodeImage(image,length,pixels,exception);
1758 if (compression == LZWCompression)
1759 status=LZWEncodeImage(image,length,pixels,exception);
1761 status=PackbitsEncodeImage(image,length,pixels,exception);
1762 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1763 if (status == MagickFalse)
1765 (void) CloseBlob(image);
1766 return(MagickFalse);
1773 Dump uncompressed DirectColor packets.
1775 Ascii85Initialize(image);
1776 for (y=0; y < (ssize_t) image->rows; y++)
1778 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1779 if (p == (const Quantum *) NULL)
1781 for (x=0; x < (ssize_t) image->columns; x++)
1783 Ascii85Encode(image,ScaleQuantumToChar(GetPixelRed(image,p)));
1784 Ascii85Encode(image,ScaleQuantumToChar(GetPixelGreen(image,p)));
1785 Ascii85Encode(image,ScaleQuantumToChar(GetPixelBlue(image,p)));
1786 if (image->colorspace == CMYKColorspace)
1787 Ascii85Encode(image,ScaleQuantumToChar(
1788 GetPixelBlack(image,p)));
1789 p+=GetPixelChannels(image);
1791 if (image->previous == (Image *) NULL)
1793 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1795 if (status == MagickFalse)
1799 Ascii85Flush(image);
1806 Dump number of colors and colormap.
1808 switch (compression)
1810 case RLECompression:
1814 Allocate pixel array.
1816 length=(size_t) number_pixels;
1817 pixels=(unsigned char *) AcquireQuantumMemory(length,
1819 if (pixels == (unsigned char *) NULL)
1820 ThrowWriterException(ResourceLimitError,
1821 "MemoryAllocationFailed");
1823 Dump Runlength encoded pixels.
1826 for (y=0; y < (ssize_t) image->rows; y++)
1828 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1829 if (p == (const Quantum *) NULL)
1831 for (x=0; x < (ssize_t) image->columns; x++)
1833 *q++=(unsigned char) GetPixelIndex(image,p);
1834 p+=GetPixelChannels(image);
1836 if (image->previous == (Image *) NULL)
1838 status=SetImageProgress(image,SaveImageTag,
1839 (MagickOffsetType) y,image->rows);
1840 if (status == MagickFalse)
1844 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1845 if (compression == ZipCompression)
1846 status=ZLIBEncodeImage(image,length,pixels,exception);
1849 if (compression == LZWCompression)
1850 status=LZWEncodeImage(image,length,pixels,exception);
1852 status=PackbitsEncodeImage(image,length,pixels,exception);
1853 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1854 if (status == MagickFalse)
1856 (void) CloseBlob(image);
1857 return(MagickFalse);
1864 Dump uncompressed PseudoColor packets.
1866 Ascii85Initialize(image);
1867 for (y=0; y < (ssize_t) image->rows; y++)
1869 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1870 if (p == (const Quantum *) NULL)
1872 for (x=0; x < (ssize_t) image->columns; x++)
1874 Ascii85Encode(image,(unsigned char) GetPixelIndex(image,p));
1875 p+=GetPixelChannels(image);
1877 if (image->previous == (Image *) NULL)
1879 status=SetImageProgress(image,SaveImageTag,
1880 (MagickOffsetType) y,image->rows);
1881 if (status == MagickFalse)
1885 Ascii85Flush(image);
1890 offset=TellBlob(image)-offset;
1891 (void) WriteBlobString(image,"\nendstream\n");
1892 (void) WriteBlobString(image,"endobj\n");
1894 Write Length object.
1896 xref[object++]=TellBlob(image);
1897 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1899 (void) WriteBlobString(image,buffer);
1900 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
1901 (void) WriteBlobString(image,buffer);
1902 (void) WriteBlobString(image,"endobj\n");
1904 Write Colorspace object.
1906 xref[object++]=TellBlob(image);
1907 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1909 (void) WriteBlobString(image,buffer);
1910 if (image->colorspace == CMYKColorspace)
1911 (void) CopyMagickString(buffer,"/DeviceCMYK\n",MaxTextExtent);
1913 if ((compression == FaxCompression) ||
1914 (compression == Group4Compression) ||
1915 ((image_info->type != TrueColorType) &&
1916 (IsImageGray(image,exception) != MagickFalse)))
1917 (void) CopyMagickString(buffer,"/DeviceGray\n",MaxTextExtent);
1919 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1920 (compression == JPEGCompression) ||
1921 (compression == JPEG2000Compression))
1922 (void) CopyMagickString(buffer,"/DeviceRGB\n",MaxTextExtent);
1924 (void) FormatLocaleString(buffer,MaxTextExtent,
1925 "[ /Indexed /DeviceRGB %.20g %.20g 0 R ]\n",(double) image->colors-
1926 1,(double) object+3);
1927 (void) WriteBlobString(image,buffer);
1928 (void) WriteBlobString(image,"endobj\n");
1932 SetGeometry(image,&geometry);
1933 (void) ParseMetaGeometry("106x106+0+0>",&geometry.x,&geometry.y,
1934 &geometry.width,&geometry.height);
1935 tile_image=ThumbnailImage(image,geometry.width,geometry.height,exception);
1936 if (tile_image == (Image *) NULL)
1937 return(MagickFalse);
1938 xref[object++]=TellBlob(image);
1939 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
1941 (void) WriteBlobString(image,buffer);
1942 (void) WriteBlobString(image,"<<\n");
1943 switch (compression)
1947 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1950 case JPEGCompression:
1952 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1953 if (image->colorspace != CMYKColorspace)
1955 (void) WriteBlobString(image,buffer);
1956 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1960 case JPEG2000Compression:
1962 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1963 if (image->colorspace != CMYKColorspace)
1965 (void) WriteBlobString(image,buffer);
1966 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1970 case LZWCompression:
1972 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1975 case ZipCompression:
1977 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1980 case FaxCompression:
1981 case Group4Compression:
1983 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1985 (void) WriteBlobString(image,buffer);
1986 (void) FormatLocaleString(buffer,MaxTextExtent,"/DecodeParms [ << "
1987 "/K %s /BlackIs1 false /Columns %.20g /Rows %.20g >> ]\n",CCITTParam,
1988 (double) tile_image->columns,(double) tile_image->rows);
1993 (void) FormatLocaleString(buffer,MaxTextExtent,CFormat,
1998 (void) WriteBlobString(image,buffer);
1999 (void) FormatLocaleString(buffer,MaxTextExtent,"/Width %.20g\n",(double)
2000 tile_image->columns);
2001 (void) WriteBlobString(image,buffer);
2002 (void) FormatLocaleString(buffer,MaxTextExtent,"/Height %.20g\n",(double)
2004 (void) WriteBlobString(image,buffer);
2005 (void) FormatLocaleString(buffer,MaxTextExtent,"/ColorSpace %.20g 0 R\n",
2007 (void) WriteBlobString(image,buffer);
2008 (void) FormatLocaleString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
2009 (compression == FaxCompression) || (compression == Group4Compression) ?
2011 (void) WriteBlobString(image,buffer);
2012 (void) FormatLocaleString(buffer,MaxTextExtent,"/Length %.20g 0 R\n",
2014 (void) WriteBlobString(image,buffer);
2015 (void) WriteBlobString(image,">>\n");
2016 (void) WriteBlobString(image,"stream\n");
2017 offset=TellBlob(image);
2018 number_pixels=(MagickSizeType) tile_image->columns*tile_image->rows;
2019 if ((compression == FaxCompression) ||
2020 (compression == Group4Compression) ||
2021 ((image_info->type != TrueColorType) &&
2022 (IsImageGray(tile_image,exception) != MagickFalse)))
2024 switch (compression)
2026 case FaxCompression:
2027 case Group4Compression:
2029 if (LocaleCompare(CCITTParam,"0") == 0)
2031 (void) HuffmanEncodeImage(image_info,image,tile_image,
2035 (void) Huffman2DEncodeImage(image_info,image,tile_image,exception);
2038 case JPEGCompression:
2040 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
2042 if (status == MagickFalse)
2044 (void) CloseBlob(image);
2045 return(MagickFalse);
2049 case JPEG2000Compression:
2051 status=InjectImageBlob(image_info,image,tile_image,"jp2",exception);
2052 if (status == MagickFalse)
2054 (void) CloseBlob(image);
2055 return(MagickFalse);
2059 case RLECompression:
2063 Allocate pixel array.
2065 length=(size_t) number_pixels;
2066 pixels=(unsigned char *) AcquireQuantumMemory(length,
2068 if (pixels == (unsigned char *) NULL)
2070 tile_image=DestroyImage(tile_image);
2071 ThrowWriterException(ResourceLimitError,
2072 "MemoryAllocationFailed");
2075 Dump Runlength encoded pixels.
2078 for (y=0; y < (ssize_t) tile_image->rows; y++)
2080 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2082 if (p == (const Quantum *) NULL)
2084 for (x=0; x < (ssize_t) tile_image->columns; x++)
2086 *q++=ScaleQuantumToChar(GetPixelIntensity(tile_image,p));
2087 p+=GetPixelChannels(tile_image);
2090 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2091 if (compression == ZipCompression)
2092 status=ZLIBEncodeImage(image,length,pixels,exception);
2095 if (compression == LZWCompression)
2096 status=LZWEncodeImage(image,length,pixels,exception);
2098 status=PackbitsEncodeImage(image,length,pixels,exception);
2099 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2100 if (status == MagickFalse)
2102 (void) CloseBlob(image);
2103 return(MagickFalse);
2110 Dump uncompressed PseudoColor packets.
2112 Ascii85Initialize(image);
2113 for (y=0; y < (ssize_t) tile_image->rows; y++)
2115 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2117 if (p == (const Quantum *) NULL)
2119 for (x=0; x < (ssize_t) tile_image->columns; x++)
2121 Ascii85Encode(image,
2122 ScaleQuantumToChar(GetPixelIntensity(tile_image,p)));
2123 p+=GetPixelChannels(tile_image);
2126 Ascii85Flush(image);
2132 if ((tile_image->storage_class == DirectClass) ||
2133 (tile_image->colors > 256) || (compression == JPEGCompression) ||
2134 (compression == JPEG2000Compression))
2135 switch (compression)
2137 case JPEGCompression:
2139 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
2141 if (status == MagickFalse)
2143 (void) CloseBlob(image);
2144 return(MagickFalse);
2148 case JPEG2000Compression:
2150 status=InjectImageBlob(image_info,image,tile_image,"jp2",exception);
2151 if (status == MagickFalse)
2153 (void) CloseBlob(image);
2154 return(MagickFalse);
2158 case RLECompression:
2162 Allocate pixel array.
2164 length=(size_t) number_pixels;
2165 pixels=(unsigned char *) AcquireQuantumMemory(length,4*
2167 length*=tile_image->colorspace == CMYKColorspace ? 4UL : 3UL;
2168 if (pixels == (unsigned char *) NULL)
2170 tile_image=DestroyImage(tile_image);
2171 ThrowWriterException(ResourceLimitError,
2172 "MemoryAllocationFailed");
2175 Dump runoffset encoded pixels.
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 *q++=ScaleQuantumToChar(GetPixelRed(tile_image,p));
2187 *q++=ScaleQuantumToChar(GetPixelGreen(tile_image,p));
2188 *q++=ScaleQuantumToChar(GetPixelBlue(tile_image,p));
2189 if (image->colorspace == CMYKColorspace)
2190 *q++=ScaleQuantumToChar(GetPixelBlack(tile_image,p));
2191 p+=GetPixelChannels(tile_image);
2194 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2195 if (compression == ZipCompression)
2196 status=ZLIBEncodeImage(image,length,pixels,exception);
2199 if (compression == LZWCompression)
2200 status=LZWEncodeImage(image,length,pixels,exception);
2202 status=PackbitsEncodeImage(image,length,pixels,exception);
2203 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2204 if (status == MagickFalse)
2206 (void) CloseBlob(image);
2207 return(MagickFalse);
2214 Dump uncompressed DirectColor packets.
2216 Ascii85Initialize(image);
2217 for (y=0; y < (ssize_t) tile_image->rows; y++)
2219 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2221 if (p == (const Quantum *) NULL)
2223 for (x=0; x < (ssize_t) tile_image->columns; x++)
2225 Ascii85Encode(image,ScaleQuantumToChar(
2226 GetPixelRed(tile_image,p)));
2227 Ascii85Encode(image,ScaleQuantumToChar(
2228 GetPixelGreen(tile_image,p)));
2229 Ascii85Encode(image,ScaleQuantumToChar(
2230 GetPixelBlue(tile_image,p)));
2231 if (image->colorspace == CMYKColorspace)
2232 Ascii85Encode(image,ScaleQuantumToChar(
2233 GetPixelBlack(tile_image,p)));
2234 p+=GetPixelChannels(tile_image);
2237 Ascii85Flush(image);
2244 Dump number of colors and colormap.
2246 switch (compression)
2248 case RLECompression:
2252 Allocate pixel array.
2254 length=(size_t) number_pixels;
2255 pixels=(unsigned char *) AcquireQuantumMemory(length,
2257 if (pixels == (unsigned char *) NULL)
2259 tile_image=DestroyImage(tile_image);
2260 ThrowWriterException(ResourceLimitError,
2261 "MemoryAllocationFailed");
2264 Dump Runlength encoded pixels.
2267 for (y=0; y < (ssize_t) tile_image->rows; y++)
2269 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2271 if (p == (const Quantum *) NULL)
2273 for (x=0; x < (ssize_t) tile_image->columns; x++)
2275 *q++=(unsigned char) GetPixelIndex(tile_image,p);
2276 p+=GetPixelChannels(tile_image);
2279 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2280 if (compression == ZipCompression)
2281 status=ZLIBEncodeImage(image,length,pixels,exception);
2284 if (compression == LZWCompression)
2285 status=LZWEncodeImage(image,length,pixels,exception);
2287 status=PackbitsEncodeImage(image,length,pixels,exception);
2288 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2289 if (status == MagickFalse)
2291 (void) CloseBlob(image);
2292 return(MagickFalse);
2299 Dump uncompressed PseudoColor packets.
2301 Ascii85Initialize(image);
2302 for (y=0; y < (ssize_t) tile_image->rows; y++)
2304 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2306 if (p == (const Quantum *) NULL)
2308 for (x=0; x < (ssize_t) tile_image->columns; x++)
2310 Ascii85Encode(image,(unsigned char)
2311 GetPixelIndex(tile_image,p));
2312 p+=GetPixelChannels(image);
2315 Ascii85Flush(image);
2320 tile_image=DestroyImage(tile_image);
2321 offset=TellBlob(image)-offset;
2322 (void) WriteBlobString(image,"\nendstream\n");
2323 (void) WriteBlobString(image,"endobj\n");
2325 Write Length object.
2327 xref[object++]=TellBlob(image);
2328 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2330 (void) WriteBlobString(image,buffer);
2331 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) offset);
2332 (void) WriteBlobString(image,buffer);
2333 (void) WriteBlobString(image,"endobj\n");
2334 xref[object++]=TellBlob(image);
2335 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g 0 obj\n",(double)
2337 (void) WriteBlobString(image,buffer);
2338 if ((image->storage_class != DirectClass) && (image->colors <= 256) &&
2339 (compression != FaxCompression) && (compression != Group4Compression))
2342 Write Colormap object.
2344 (void) WriteBlobString(image,"<<\n");
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);