2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Portable Document Format %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/color.h"
47 #include "magick/color-private.h"
48 #include "magick/colorspace.h"
49 #include "magick/compress.h"
50 #include "magick/constitute.h"
51 #include "magick/delegate.h"
52 #include "magick/delegate-private.h"
53 #include "magick/draw.h"
54 #include "magick/exception.h"
55 #include "magick/exception-private.h"
56 #include "magick/geometry.h"
57 #include "magick/image.h"
58 #include "magick/image-private.h"
59 #include "magick/list.h"
60 #include "magick/magick.h"
61 #include "magick/memory_.h"
62 #include "magick/monitor.h"
63 #include "magick/monitor-private.h"
64 #include "magick/option.h"
65 #include "magick/profile.h"
66 #include "magick/property.h"
67 #include "magick/quantum-private.h"
68 #include "magick/resource_.h"
69 #include "magick/resize.h"
70 #include "magick/static.h"
71 #include "magick/string_.h"
72 #include "magick/module.h"
73 #include "magick/transform.h"
74 #include "magick/utility.h"
75 #include "magick/module.h"
80 #if defined(MAGICKCORE_TIFF_DELEGATE)
81 #define CCITTParam "-1"
83 #define CCITTParam "0"
89 static MagickBooleanType
90 WritePDFImage(const ImageInfo *,Image *);
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 % I n v o k e P D F D e l e g a t e %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 % InvokePDFDelegate() executes the PDF interpreter with the specified command.
105 % The format of the InvokePDFDelegate method is:
107 % MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
108 % const char *command,ExceptionInfo *exception)
110 % A description of each parameter follows:
112 % o verbose: A value other than zero displays the command prior to
115 % o command: the address of a character string containing the command to
118 % o exception: return any errors or warnings in this structure.
121 static MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
122 const char *command,ExceptionInfo *exception)
127 #if defined(MAGICKCORE_GS_DELEGATE) || defined(__WINDOWS__)
144 #if defined(__WINDOWS__)
145 ghost_info=NTGhostscriptDLLVectors();
150 ghost_info=(&ghost_info_struct);
151 (void) ResetMagickMemory(&ghost_info,0,sizeof(ghost_info));
152 ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
154 ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
155 gsapi_init_with_args;
156 ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
157 int *)) gsapi_run_string;
158 ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
159 gsapi_delete_instance;
160 ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
162 if (ghost_info == (GhostInfo *) NULL)
164 status=SystemCommand(verbose,command,exception);
165 return(status == 0 ? MagickTrue : MagickFalse);
167 if (verbose != MagickFalse)
169 (void) fputs("[ghostscript library]",stdout);
170 (void) fputs(strchr(command,' '),stdout);
172 status=(ghost_info->new_instance)(&interpreter,(void *) NULL);
175 status=SystemCommand(verbose,command,exception);
176 return(status == 0 ? MagickTrue : MagickFalse);
178 argv=StringToArgv(command,&argc);
179 status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
181 status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
183 (ghost_info->exit)(interpreter);
184 (ghost_info->delete_instance)(interpreter);
185 #if defined(__WINDOWS__)
186 NTGhostscriptUnLoadDLL();
188 for (i=0; i < (long) argc; i++)
189 argv[i]=DestroyString(argv[i]);
190 argv=(char **) RelinquishMagickMemory(argv);
191 if ((status != 0) && (status != -101))
196 message=GetExceptionMessage(errno);
197 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
198 "`%s': %s",command,message);
199 message=DestroyString(message);
200 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
201 "Ghostscript returns status %d, exit code %d",status,code);
206 status=SystemCommand(verbose,command,exception);
207 return(status == 0 ? MagickTrue : MagickFalse);
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 % IsPDF() returns MagickTrue if the image format type, identified by the
223 % magick string, is PDF.
225 % The format of the IsPDF method is:
227 % MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
229 % A description of each parameter follows:
231 % o magick: compare image format pattern against these bytes.
233 % o offset: Specifies the offset of the magick string.
236 static MagickBooleanType IsPDF(const unsigned char *magick,const size_t offset)
240 if (LocaleNCompare((const char *) magick,"%PDF-",5) == 0)
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % R e a d P D F I m a g e %
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 % ReadPDFImage() reads a Portable Document Format image file and
257 % returns it. It allocates the memory necessary for the new Image structure
258 % and returns a pointer to the new image.
260 % The format of the ReadPDFImage method is:
262 % Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
264 % A description of each parameter follows:
266 % o image_info: the image info.
268 % o exception: return any errors or warnings in this structure.
272 static MagickBooleanType IsPDFRendered(const char *path)
280 if ((path == (const char *) NULL) || (*path == '\0'))
282 status=GetPathAttributes(path,&attributes);
283 if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
284 (attributes.st_size > 0))
289 static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
291 #define CropBox "CropBox"
292 #define DeviceCMYK "DeviceCMYK"
293 #define MediaBox "MediaBox"
294 #define RenderPostscriptText "Rendering Postscript... "
295 #define PDFRotate "Rotate"
296 #define SpotColor "Separation"
297 #define TrimBox "TrimBox"
298 #define PDFVersion "PDF-"
301 command[MaxTextExtent],
302 density[MaxTextExtent],
303 filename[MaxTextExtent],
304 geometry[MaxTextExtent],
305 options[MaxTextExtent],
306 input_filename[MaxTextExtent],
307 postscript_filename[MaxTextExtent];
359 assert(image_info != (const ImageInfo *) NULL);
360 assert(image_info->signature == MagickSignature);
361 if (image_info->debug != MagickFalse)
362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
363 image_info->filename);
364 assert(exception != (ExceptionInfo *) NULL);
365 assert(exception->signature == MagickSignature);
369 image=AcquireImage(image_info);
370 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
371 if (status == MagickFalse)
373 image=DestroyImageList(image);
374 return((Image *) NULL);
376 status=AcquireUniqueSymbolicLink(image_info->filename,input_filename);
377 if (status == MagickFalse)
379 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
380 image_info->filename);
381 image=DestroyImageList(image);
382 return((Image *) NULL);
385 Set the page density.
387 delta.x=DefaultResolution;
388 delta.y=DefaultResolution;
389 if ((image->x_resolution == 0.0) || (image->y_resolution == 0.0))
397 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
398 image->x_resolution=geometry_info.rho;
399 image->y_resolution=geometry_info.sigma;
400 if ((flags & SigmaValue) == 0)
401 image->y_resolution=image->x_resolution;
404 Determine page geometry from the PDF media box.
406 cmyk=image_info->colorspace == CMYKColorspace ? MagickTrue : MagickFalse;
408 option=GetImageOption(image_info,"pdf:use-cropbox");
409 if (option != (const char *) NULL)
410 cropbox=IsMagickTrue(option);
412 option=GetImageOption(image_info,"pdf:use-trimbox");
413 if (option != (const char *) NULL)
414 trimbox=IsMagickTrue(option);
417 (void) ResetMagickMemory(&bounding_box,0,sizeof(bounding_box));
418 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
419 (void) ResetMagickMemory(&hires_bounds,0,sizeof(hires_bounds));
420 (void) ResetMagickMemory(&page,0,sizeof(page));
421 (void) ResetMagickMemory(command,0,sizeof(command));
426 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
434 if ((c != (int) '/') && (c != (int) '%') &&
435 ((size_t) (p-command) < (MaxTextExtent-1)))
439 if (LocaleNCompare(PDFRotate,command,strlen(PDFRotate)) == 0)
440 count=(ssize_t) sscanf(command,"Rotate %lf",&angle);
442 Is this a CMYK document?
444 if (LocaleNCompare(DeviceCMYK,command,strlen(DeviceCMYK)) == 0)
446 if (LocaleNCompare(SpotColor,command,strlen(SpotColor)) == 0)
450 property[MaxTextExtent],
459 (void) FormatMagickString(property,MaxTextExtent,"pdf:SpotColor-%lu",
462 for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
464 if ((isspace(c) != 0) || (c == '/') || ((i+1) == MaxTextExtent))
469 value=AcquireString(name);
470 (void) SubstituteString(&value,"#20"," ");
471 (void) SetImageProperty(image,property,value);
472 value=DestroyString(value);
475 if (LocaleNCompare(PDFVersion,command,strlen(PDFVersion)) == 0)
476 (void) SetImageProperty(image,"pdf:Version",command);
478 if (cropbox != MagickFalse)
480 if (LocaleNCompare(CropBox,command,strlen(CropBox)) == 0)
483 Note region defined by crop box.
485 count=(ssize_t) sscanf(command,"CropBox [%lf %lf %lf %lf",
486 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
488 count=(ssize_t) sscanf(command,"CropBox[%lf %lf %lf %lf",
489 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
493 if (trimbox != MagickFalse)
495 if (LocaleNCompare(TrimBox,command,strlen(TrimBox)) == 0)
498 Note region defined by trim box.
500 count=(ssize_t) sscanf(command,"TrimBox [%lf %lf %lf %lf",
501 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
503 count=(ssize_t) sscanf(command,"TrimBox[%lf %lf %lf %lf",
504 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
508 if (LocaleNCompare(MediaBox,command,strlen(MediaBox)) == 0)
511 Note region defined by media box.
513 count=(ssize_t) sscanf(command,"MediaBox [%lf %lf %lf %lf",
514 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
516 count=(ssize_t) sscanf(command,"MediaBox[%lf %lf %lf %lf",
517 &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
521 if (((bounds.x2 > hires_bounds.x2) && (bounds.y2 > hires_bounds.y2)) ||
522 ((hires_bounds.x2 == 0.0) && (hires_bounds.y2 == 0.0)))
525 Set PDF render geometry.
527 (void) FormatMagickString(geometry,MaxTextExtent,
528 "%.15gx%.15g%+.15g%+.15g",bounds.x2-bounds.x1,bounds.y2-bounds.y1,
529 bounds.x1,bounds.y1);
530 (void) SetImageProperty(image,"pdf:HiResBoundingBox",geometry);
531 page.width=(unsigned long) (bounds.x2-bounds.x1+0.5);
532 page.height=(unsigned long) (bounds.y2-bounds.y1+0.5);
536 (void) CloseBlob(image);
537 if ((fabs(angle) == 90.0) || (fabs(angle) == 270.0))
543 page.width=page.height;
546 if (image_info->colorspace == RGBColorspace)
549 Create Ghostscript control file.
551 file=AcquireUniqueFileResource(postscript_filename);
554 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
555 image_info->filename);
556 image=DestroyImage(image);
557 return((Image *) NULL);
559 count=write(file," ",1);
562 Render Postscript with the Ghostscript delegate.
564 if ((image_info->ping != MagickFalse) ||
565 (image_info->monochrome != MagickFalse))
566 delegate_info=GetDelegateInfo("ps:mono",(char *) NULL,exception);
568 if (cmyk != MagickFalse)
569 delegate_info=GetDelegateInfo("ps:cmyk",(char *) NULL,exception);
571 if (LocaleCompare(image_info->magick,"AI") == 0)
572 delegate_info=GetDelegateInfo("ps:alpha",(char *) NULL,exception);
574 delegate_info=GetDelegateInfo("ps:color",(char *) NULL,exception);
575 if (delegate_info == (const DelegateInfo *) NULL)
577 (void) RelinquishUniqueFileResource(postscript_filename);
578 image=DestroyImage(image);
579 return((Image *) NULL);
582 (void) FormatMagickString(density,MaxTextExtent,"%.15gx%.15g",
583 image->x_resolution,image->y_resolution);
584 if (image_info->page != (char *) NULL)
586 (void) ParseAbsoluteGeometry(image_info->page,&page);
587 page.width=(unsigned long) (page.width*image->x_resolution/delta.x+0.5);
588 page.height=(unsigned long) (page.height*image->y_resolution/delta.y+0.5);
589 (void) FormatMagickString(options,MaxTextExtent,"-g%lux%lu ",page.width,
592 if (cmyk != MagickFalse)
593 (void) ConcatenateMagickString(options,"-dUseCIEColor ",MaxTextExtent);
594 if (cropbox != MagickFalse)
595 (void) ConcatenateMagickString(options,"-dUseCropBox ",MaxTextExtent);
596 if (trimbox != MagickFalse)
597 (void) ConcatenateMagickString(options,"-dUseTrimBox ",MaxTextExtent);
598 read_info=CloneImageInfo(image_info);
599 *read_info->magick='\0';
600 if (read_info->number_scenes != 0)
603 pages[MaxTextExtent];
605 (void) FormatMagickString(pages,MaxTextExtent,"-dFirstPage=%lu "
606 "-dLastPage=%lu",read_info->scene+1,read_info->scene+
607 read_info->number_scenes);
608 (void) ConcatenateMagickString(options,pages,MaxTextExtent);
609 read_info->number_scenes=0;
610 if (read_info->scenes != (char *) NULL)
611 *read_info->scenes='\0';
613 if (read_info->authenticate != (char *) NULL)
614 (void) FormatMagickString(options+strlen(options),MaxTextExtent,
615 " -sPDFPassword=%s",read_info->authenticate);
616 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
617 (void) AcquireUniqueFilename(read_info->filename);
618 (void) FormatMagickString(command,MaxTextExtent,
619 GetDelegateCommands(delegate_info),
620 read_info->antialias != MagickFalse ? 4 : 1,
621 read_info->antialias != MagickFalse ? 4 : 1,density,options,
622 read_info->filename,postscript_filename,input_filename);
623 status=InvokePDFDelegate(read_info->verbose,command,exception);
624 pdf_image=(Image *) NULL;
625 if ((status != MagickFalse) &&
626 (IsPDFRendered(read_info->filename) != MagickFalse))
627 pdf_image=ReadImage(read_info,exception);
628 (void) RelinquishUniqueFileResource(postscript_filename);
629 (void) RelinquishUniqueFileResource(read_info->filename);
630 (void) RelinquishUniqueFileResource(input_filename);
631 read_info=DestroyImageInfo(read_info);
632 if (pdf_image == (Image *) NULL)
634 ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
635 image_info->filename);
636 return((Image *) NULL);
638 if (LocaleCompare(pdf_image->magick,"BMP") == 0)
643 cmyk_image=ConsolidateCMYKImages(pdf_image,exception);
644 if (cmyk_image != (Image *) NULL)
646 pdf_image=DestroyImageList(pdf_image);
647 pdf_image=cmyk_image;
650 if (image_info->number_scenes != 0)
659 Add place holder images to meet the subimage specification requirement.
661 for (i=0; i < (long) image_info->scene; i++)
663 clone_image=CloneImage(pdf_image,1,1,MagickTrue,exception);
664 if (clone_image != (Image *) NULL)
665 PrependImageToList(&pdf_image,clone_image);
670 (void) CopyMagickString(pdf_image->filename,filename,MaxTextExtent);
671 pdf_image->page=page;
672 (void) CloneImageProfiles(pdf_image,image);
673 (void) CloneImageProperties(pdf_image,image);
674 next=SyncNextImageInList(pdf_image);
675 if (next != (Image *) NULL)
677 } while (next != (Image *) NULL);
678 image=DestroyImage(image);
680 for (next=GetFirstImageInList(pdf_image); next != (Image *) NULL; )
683 next=GetNextImageInList(next);
685 return(GetFirstImageInList(pdf_image));
689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
693 % R e g i s t e r P D F I m a g e %
697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
699 % RegisterPDFImage() adds properties for the PDF image format to
700 % the list of supported formats. The properties include the image format
701 % tag, a method to read and/or write the format, whether the format
702 % supports the saving of more than one frame to the same file or blob,
703 % whether the format supports native in-memory I/O, and a brief
704 % description of the format.
706 % The format of the RegisterPDFImage method is:
708 % unsigned long RegisterPDFImage(void)
711 ModuleExport unsigned long RegisterPDFImage(void)
716 entry=SetMagickInfo("AI");
717 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
718 entry->encoder=(EncodeImageHandler *) WritePDFImage;
719 entry->adjoin=MagickFalse;
720 entry->blob_support=MagickFalse;
721 entry->seekable_stream=MagickTrue;
722 entry->thread_support=EncoderThreadSupport;
723 entry->description=ConstantString("Adobe Illustrator CS2");
724 entry->module=ConstantString("PDF");
725 (void) RegisterMagickInfo(entry);
726 entry=SetMagickInfo("EPDF");
727 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
728 entry->encoder=(EncodeImageHandler *) WritePDFImage;
729 entry->adjoin=MagickFalse;
730 entry->blob_support=MagickFalse;
731 entry->seekable_stream=MagickTrue;
732 entry->thread_support=EncoderThreadSupport;
733 entry->description=ConstantString("Encapsulated Portable Document Format");
734 entry->module=ConstantString("PDF");
735 (void) RegisterMagickInfo(entry);
736 entry=SetMagickInfo("PDF");
737 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
738 entry->encoder=(EncodeImageHandler *) WritePDFImage;
739 entry->magick=(IsImageFormatHandler *) IsPDF;
740 entry->blob_support=MagickFalse;
741 entry->seekable_stream=MagickTrue;
742 entry->thread_support=EncoderThreadSupport;
743 entry->description=ConstantString("Portable Document Format");
744 entry->module=ConstantString("PDF");
745 (void) RegisterMagickInfo(entry);
746 entry=SetMagickInfo("PDFA");
747 entry->decoder=(DecodeImageHandler *) ReadPDFImage;
748 entry->encoder=(EncodeImageHandler *) WritePDFImage;
749 entry->magick=(IsImageFormatHandler *) IsPDF;
750 entry->blob_support=MagickFalse;
751 entry->seekable_stream=MagickTrue;
752 entry->thread_support=EncoderThreadSupport;
753 entry->description=ConstantString("Portable Document Archive Format");
754 entry->module=ConstantString("PDF");
755 (void) RegisterMagickInfo(entry);
756 return(MagickImageCoderSignature);
760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 % U n r e g i s t e r P D F I m a g e %
768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
770 % UnregisterPDFImage() removes format registrations made by the
771 % PDF module from the list of supported formats.
773 % The format of the UnregisterPDFImage method is:
775 % UnregisterPDFImage(void)
778 ModuleExport void UnregisterPDFImage(void)
780 (void) UnregisterMagickInfo("AI");
781 (void) UnregisterMagickInfo("EPDF");
782 (void) UnregisterMagickInfo("PDF");
783 (void) UnregisterMagickInfo("PDFA");
787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 % W r i t e P D F I m a g e %
795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
797 % WritePDFImage() writes an image in the Portable Document image
800 % The format of the WritePDFImage method is:
802 % MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
804 % A description of each parameter follows.
806 % o image_info: the image info.
808 % o image: The image.
812 static inline size_t MagickMax(const size_t x,const size_t y)
819 static inline size_t MagickMin(const size_t x,const size_t y)
826 static char *EscapeParenthesis(const char *text)
835 buffer[MaxTextExtent];
842 for (i=0; i < (long) MagickMin(strlen(text),(MaxTextExtent-escapes-1)); i++)
844 if ((text[i] == '(') || (text[i] == ')'))
855 static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info,
856 Image *image,Image *inject_image)
874 write_info=CloneImageInfo(image_info);
875 (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent);
876 (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent);
877 group4_image=CloneImage(inject_image,0,0,MagickTrue,&image->exception);
878 if (group4_image == (Image *) NULL)
880 group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length,
882 group4_image=DestroyImage(group4_image);
883 if (group4 == (unsigned char *) NULL)
885 write_info=DestroyImageInfo(write_info);
886 if (WriteBlob(image,length,group4) != (ssize_t) length)
888 group4=(unsigned char *) RelinquishMagickMemory(group4);
892 static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
894 #define CFormat "/Filter [ /%s ]\n"
895 #define ObjectsPerImage 14
900 "<?xpacket begin=\"%s\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
901 "<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"
902 " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
903 " <rdf:Description rdf:about=\"\"\n"
904 " xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">\n"
905 " <xap:ModifyDate>%s</xap:ModifyDate>\n"
906 " <xap:CreateDate>%s</xap:CreateDate>\n"
907 " <xap:MetadataDate>%s</xap:MetadataDate>\n"
908 " <xap:CreatorTool>%s</xap:CreatorTool>\n"
909 " </rdf:Description>\n"
910 " <rdf:Description rdf:about=\"\"\n"
911 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
912 " <dc:format>application/pdf</dc:format>\n"
913 " </rdf:Description>\n"
914 " <rdf:Description rdf:about=\"\"\n"
915 " xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\">\n"
916 " <xapMM:DocumentID>uuid:6ec119d7-7982-4f56-808d-dfe64f5b35cf</xapMM:DocumentID>\n"
917 " <xapMM:InstanceID>uuid:a79b99b4-6235-447f-9f6c-ec18ef7555cb</xapMM:InstanceID>\n"
918 " </rdf:Description>\n"
919 " <rdf:Description rdf:about=\"\"\n"
920 " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">\n"
921 " <pdf:Producer>%s</pdf:Producer>\n"
922 " </rdf:Description>\n"
923 " <rdf:Description rdf:about=\"\"\n"
924 " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n"
925 " <pdfaid:part>1</pdfaid:part>\n"
926 " <pdfaid:conformance>B</pdfaid:conformance>\n"
927 " </rdf:Description>\n"
930 "<?xpacket end=\"w\"?>\n"
932 XMPProfileMagick[4]= { (char) 0xef, (char) 0xbb, (char) 0xbf, (char) 0x00 };
935 buffer[MaxTextExtent],
938 page_geometry[MaxTextExtent];
984 register const IndexPacket
987 register const PixelPacket
990 register unsigned char
1018 Open output image file.
1020 assert(image_info != (const ImageInfo *) NULL);
1021 assert(image_info->signature == MagickSignature);
1022 assert(image != (Image *) NULL);
1023 assert(image->signature == MagickSignature);
1024 if (image->debug != MagickFalse)
1025 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1026 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1027 if (status == MagickFalse)
1030 Allocate X ref memory.
1032 xref=(MagickOffsetType *) AcquireQuantumMemory(2048UL,sizeof(*xref));
1033 if (xref == (MagickOffsetType *) NULL)
1034 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1035 (void) ResetMagickMemory(xref,0,2048UL*sizeof(*xref));
1041 if (image_info->compression == JPEG2000Compression)
1042 version=(unsigned long) MagickMax(version,5);
1043 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1044 if (next->matte != MagickFalse)
1045 version=(unsigned long) MagickMax(version,4);
1046 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1047 version=(unsigned long) MagickMax(version,6);
1048 (void) FormatMagickString(buffer,MaxTextExtent,"%%PDF-1.%lu \n",version);
1049 (void) WriteBlobString(image,buffer);
1050 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1051 (void) WriteBlobString(image,"%âãÏÓ\n");
1053 Write Catalog object.
1055 xref[object++]=TellBlob(image);
1057 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1058 (void) WriteBlobString(image,buffer);
1059 (void) WriteBlobString(image,"<<\n");
1060 if (LocaleCompare(image_info->magick,"PDFA") != 0)
1061 (void) FormatMagickString(buffer,MaxTextExtent,"/Pages %lu 0 R\n",
1065 (void) FormatMagickString(buffer,MaxTextExtent,"/Metadata %lu 0 R\n",
1067 (void) WriteBlobString(image,buffer);
1068 (void) FormatMagickString(buffer,MaxTextExtent,"/Pages %lu 0 R\n",
1071 (void) WriteBlobString(image,buffer);
1072 (void) WriteBlobString(image,"/Type /Catalog\n");
1073 (void) WriteBlobString(image,">>\n");
1074 (void) WriteBlobString(image,"endobj\n");
1075 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1078 create_date[MaxTextExtent],
1079 modify_date[MaxTextExtent],
1080 timestamp[MaxTextExtent],
1081 xmp_profile[MaxTextExtent];
1089 xref[object++]=TellBlob(image);
1090 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1091 (void) WriteBlobString(image,buffer);
1092 (void) WriteBlobString(image,"<<\n");
1093 (void) WriteBlobString(image,"/Subtype /XML\n");
1095 value=GetImageProperty(image,"date:modify");
1096 if (value != (const char *) NULL)
1097 (void) CopyMagickString(modify_date,value,MaxTextExtent);
1099 value=GetImageProperty(image,"date:create");
1100 if (value != (const char *) NULL)
1101 (void) CopyMagickString(create_date,value,MaxTextExtent);
1102 (void) FormatMagickTime(time((time_t *) NULL),MaxTextExtent,timestamp);
1103 i=FormatMagickString(xmp_profile,MaxTextExtent,XMPProfile,
1104 XMPProfileMagick,modify_date,create_date,timestamp,
1105 GetMagickVersion(&version),GetMagickVersion(&version));
1106 (void) FormatMagickString(buffer,MaxTextExtent,"/Length %lu\n",1UL*i);
1107 (void) WriteBlobString(image,buffer);
1108 (void) WriteBlobString(image,"/Type /Metadata\n");
1109 (void) WriteBlobString(image,">>\nstream\n");
1110 (void) WriteBlobString(image,xmp_profile);
1111 (void) WriteBlobString(image,"endstream\n");
1112 (void) WriteBlobString(image,"endobj\n");
1117 xref[object++]=TellBlob(image);
1119 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1120 (void) WriteBlobString(image,buffer);
1121 (void) WriteBlobString(image,"<<\n");
1122 (void) WriteBlobString(image,"/Type /Pages\n");
1123 (void) FormatMagickString(buffer,MaxTextExtent,"/Kids [ %lu 0 R ",object+1);
1124 (void) WriteBlobString(image,buffer);
1125 count=(long) (pages_id+ObjectsPerImage+1);
1126 if (image_info->adjoin != MagickFalse)
1132 Predict page object id's.
1135 for ( ; GetNextImageInList(kid_image) != (Image *) NULL; count+=ObjectsPerImage)
1137 (void) FormatMagickString(buffer,MaxTextExtent,"%ld 0 R ",count);
1138 (void) WriteBlobString(image,buffer);
1139 kid_image=GetNextImageInList(kid_image);
1141 xref=(MagickOffsetType *) ResizeQuantumMemory(xref,(size_t) count+2048UL,
1143 if (xref == (MagickOffsetType *) NULL)
1144 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1146 (void) WriteBlobString(image,"]\n");
1147 (void) FormatMagickString(buffer,MaxTextExtent,"/Count %lu\n",
1148 (count-pages_id)/ObjectsPerImage);
1149 (void) WriteBlobString(image,buffer);
1150 (void) WriteBlobString(image,">>\n");
1151 (void) WriteBlobString(image,"endobj\n");
1155 compression=image->compression;
1156 if (image_info->compression != UndefinedCompression)
1157 compression=image_info->compression;
1158 switch (compression)
1160 case FaxCompression:
1161 case Group4Compression:
1163 if ((IsMonochromeImage(image,&image->exception) == MagickFalse) ||
1164 (image->matte != MagickFalse))
1165 compression=RLECompression;
1168 #if !defined(MAGICKCORE_JPEG_DELEGATE)
1169 case JPEGCompression:
1171 compression=RLECompression;
1172 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1173 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JPEG)",
1178 #if !defined(MAGICKCORE_JP2_DELEGATE)
1179 case JPEG2000Compression:
1181 compression=RLECompression;
1182 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1183 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (JP2)",
1188 #if !defined(MAGICKCORE_ZLIB_DELEGATE)
1189 case ZipCompression:
1191 compression=RLECompression;
1192 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1193 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (ZLIB)",
1198 case LZWCompression:
1200 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1201 compression=RLECompression; /* LZW compression is forbidden */
1206 if (LocaleCompare(image_info->magick,"PDFA") == 0)
1207 compression=RLECompression; /* ASCII 85 compression is forbidden */
1213 if (compression == JPEG2000Compression)
1215 if (image->colorspace != RGBColorspace)
1216 (void) TransformImageColorspace(image,RGBColorspace);
1219 Scale relative to dots-per-inch.
1221 delta.x=DefaultResolution;
1222 delta.y=DefaultResolution;
1223 resolution.x=image->x_resolution;
1224 resolution.y=image->y_resolution;
1225 if ((resolution.x == 0.0) || (resolution.y == 0.0))
1227 flags=ParseGeometry(PSDensityGeometry,&geometry_info);
1228 resolution.x=geometry_info.rho;
1229 resolution.y=geometry_info.sigma;
1230 if ((flags & SigmaValue) == 0)
1231 resolution.y=resolution.x;
1233 if (image_info->density != (char *) NULL)
1235 flags=ParseGeometry(image_info->density,&geometry_info);
1236 resolution.x=geometry_info.rho;
1237 resolution.y=geometry_info.sigma;
1238 if ((flags & SigmaValue) == 0)
1239 resolution.y=resolution.x;
1241 if (image->units == PixelsPerCentimeterResolution)
1246 SetGeometry(image,&geometry);
1247 (void) FormatMagickString(page_geometry,MaxTextExtent,"%lux%lu",
1248 image->columns,image->rows);
1249 if (image_info->page != (char *) NULL)
1250 (void) CopyMagickString(page_geometry,image_info->page,MaxTextExtent);
1252 if ((image->page.width != 0) && (image->page.height != 0))
1253 (void) FormatMagickString(page_geometry,MaxTextExtent,"%lux%lu%+ld%+ld",
1254 image->page.width,image->page.height,image->page.x,image->page.y);
1256 if ((image->gravity != UndefinedGravity) &&
1257 (LocaleCompare(image_info->magick,"PDF") == 0))
1258 (void) CopyMagickString(page_geometry,PSPageGeometry,MaxTextExtent);
1259 (void) ConcatenateMagickString(page_geometry,">",MaxTextExtent);
1260 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
1261 &geometry.width,&geometry.height);
1262 scale.x=(double) (geometry.width*delta.x)/resolution.x;
1263 geometry.width=(unsigned long) (scale.x+0.5);
1264 scale.y=(double) (geometry.height*delta.y)/resolution.y;
1265 geometry.height=(unsigned long) (scale.y+0.5);
1266 (void) ParseAbsoluteGeometry(page_geometry,&media_info);
1267 (void) ParseGravityGeometry(image,page_geometry,&page_info,
1269 if (image->gravity != UndefinedGravity)
1271 geometry.x=(-page_info.x);
1272 geometry.y=(long) (media_info.height+page_info.y-image->rows);
1275 if (image_info->pointsize != 0.0)
1276 pointsize=image_info->pointsize;
1278 value=GetImageProperty(image,"Label");
1279 if (value != (const char *) NULL)
1280 text_size=(unsigned long) (MultilineCensus(value)*pointsize+12);
1284 xref[object++]=TellBlob(image);
1285 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1286 (void) WriteBlobString(image,buffer);
1287 (void) WriteBlobString(image,"<<\n");
1288 (void) WriteBlobString(image,"/Type /Page\n");
1289 (void) FormatMagickString(buffer,MaxTextExtent,"/Parent %lu 0 R\n",
1291 (void) WriteBlobString(image,buffer);
1292 (void) WriteBlobString(image,"/Resources <<\n");
1293 labels=(char **) NULL;
1294 value=GetImageProperty(image,"Label");
1295 if (value != (const char *) NULL)
1296 labels=StringToList(value);
1297 if (labels != (char **) NULL)
1299 (void) FormatMagickString(buffer,MaxTextExtent,
1300 "/Font << /F%lu %lu 0 R >>\n",image->scene,object+4);
1301 (void) WriteBlobString(image,buffer);
1303 (void) FormatMagickString(buffer,MaxTextExtent,
1304 "/XObject << /Im%lu %lu 0 R >>\n",image->scene,object+5);
1305 (void) WriteBlobString(image,buffer);
1306 (void) FormatMagickString(buffer,MaxTextExtent,"/ProcSet %lu 0 R >>\n",
1308 (void) WriteBlobString(image,buffer);
1309 (void) FormatMagickString(buffer,MaxTextExtent,
1310 "/MediaBox [0 0 %.15g %.15g]\n",72.0*media_info.width/resolution.x,
1311 72.0*media_info.height/resolution.y);
1312 (void) WriteBlobString(image,buffer);
1313 (void) FormatMagickString(buffer,MaxTextExtent,
1314 "/CropBox [0 0 %.15g %.15g]\n",72.0*media_info.width/resolution.x,
1315 72.0*media_info.height/resolution.y);
1316 (void) WriteBlobString(image,buffer);
1317 (void) FormatMagickString(buffer,MaxTextExtent,"/Contents %lu 0 R\n",
1319 (void) WriteBlobString(image,buffer);
1320 (void) FormatMagickString(buffer,MaxTextExtent,"/Thumb %lu 0 R\n",
1322 (void) WriteBlobString(image,buffer);
1323 (void) WriteBlobString(image,">>\n");
1324 (void) WriteBlobString(image,"endobj\n");
1326 Write Contents object.
1328 xref[object++]=TellBlob(image);
1329 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1330 (void) WriteBlobString(image,buffer);
1331 (void) WriteBlobString(image,"<<\n");
1332 (void) FormatMagickString(buffer,MaxTextExtent,"/Length %lu 0 R\n",
1334 (void) WriteBlobString(image,buffer);
1335 (void) WriteBlobString(image,">>\n");
1336 (void) WriteBlobString(image,"stream\n");
1337 offset=TellBlob(image);
1338 (void) WriteBlobString(image,"q\n");
1339 if (labels != (char **) NULL)
1340 for (i=0; labels[i] != (char *) NULL; i++)
1342 (void) WriteBlobString(image,"BT\n");
1343 (void) FormatMagickString(buffer,MaxTextExtent,"/F%lu %.15g Tf\n",
1344 image->scene,pointsize);
1345 (void) WriteBlobString(image,buffer);
1346 (void) FormatMagickString(buffer,MaxTextExtent,"%ld %ld Td\n",
1347 geometry.x,(long) (geometry.y+geometry.height+i*pointsize+12));
1348 (void) WriteBlobString(image,buffer);
1349 (void) FormatMagickString(buffer,MaxTextExtent,"(%s) Tj\n",labels[i]);
1350 (void) WriteBlobString(image,buffer);
1351 (void) WriteBlobString(image,"ET\n");
1352 labels[i]=DestroyString(labels[i]);
1354 (void) FormatMagickString(buffer,MaxTextExtent,
1355 "%.15g 0 0 %.15g %ld %ld cm\n",scale.x,scale.y,geometry.x,geometry.y);
1356 (void) WriteBlobString(image,buffer);
1357 (void) FormatMagickString(buffer,MaxTextExtent,"/Im%lu Do\n",image->scene);
1358 (void) WriteBlobString(image,buffer);
1359 (void) WriteBlobString(image,"Q\n");
1360 offset=TellBlob(image)-offset;
1361 (void) WriteBlobString(image,"endstream\n");
1362 (void) WriteBlobString(image,"endobj\n");
1364 Write Length object.
1366 xref[object++]=TellBlob(image);
1367 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1368 (void) WriteBlobString(image,buffer);
1369 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",
1370 (unsigned long) offset);
1371 (void) WriteBlobString(image,buffer);
1372 (void) WriteBlobString(image,"endobj\n");
1374 Write Procset object.
1376 xref[object++]=TellBlob(image);
1377 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1378 (void) WriteBlobString(image,buffer);
1379 if ((image->storage_class == DirectClass) || (image->colors > 256))
1380 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageC",MaxTextExtent);
1382 if ((compression == FaxCompression) || (compression == Group4Compression))
1383 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageB",MaxTextExtent);
1385 (void) CopyMagickString(buffer,"[ /PDF /Text /ImageI",MaxTextExtent);
1386 (void) WriteBlobString(image,buffer);
1387 (void) WriteBlobString(image," ]\n");
1388 (void) WriteBlobString(image,"endobj\n");
1392 xref[object++]=TellBlob(image);
1393 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1394 (void) WriteBlobString(image,buffer);
1395 (void) WriteBlobString(image,"<<\n");
1396 if (labels != (char **) NULL)
1398 (void) WriteBlobString(image,"/Type /Font\n");
1399 (void) WriteBlobString(image,"/Subtype /Type1\n");
1400 (void) FormatMagickString(buffer,MaxTextExtent,"/Name /F%lu\n",
1402 (void) WriteBlobString(image,buffer);
1403 (void) WriteBlobString(image,"/BaseFont /Helvetica\n");
1404 (void) WriteBlobString(image,"/Encoding /MacRomanEncoding\n");
1405 labels=(char **) RelinquishMagickMemory(labels);
1407 (void) WriteBlobString(image,">>\n");
1408 (void) WriteBlobString(image,"endobj\n");
1410 Write XObject object.
1412 xref[object++]=TellBlob(image);
1413 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1414 (void) WriteBlobString(image,buffer);
1415 (void) WriteBlobString(image,"<<\n");
1416 (void) WriteBlobString(image,"/Type /XObject\n");
1417 (void) WriteBlobString(image,"/Subtype /Image\n");
1418 (void) FormatMagickString(buffer,MaxTextExtent,"/Name /Im%lu\n",
1420 (void) WriteBlobString(image,buffer);
1421 switch (compression)
1425 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1428 case JPEGCompression:
1430 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1431 if (image->colorspace != CMYKColorspace)
1433 (void) WriteBlobString(image,buffer);
1434 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1438 case JPEG2000Compression:
1440 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1441 if (image->colorspace != CMYKColorspace)
1443 (void) WriteBlobString(image,buffer);
1444 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1448 case LZWCompression:
1450 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1453 case ZipCompression:
1455 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1458 case FaxCompression:
1459 case Group4Compression:
1461 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1463 (void) WriteBlobString(image,buffer);
1464 (void) FormatMagickString(buffer,MaxTextExtent,"/DecodeParms [ << "
1465 "/K %s /BlackIs1 false /Columns %ld /Rows %ld >> ]\n",CCITTParam,
1466 image->columns,image->rows);
1471 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,
1476 (void) WriteBlobString(image,buffer);
1477 (void) FormatMagickString(buffer,MaxTextExtent,"/Width %lu\n",
1479 (void) WriteBlobString(image,buffer);
1480 (void) FormatMagickString(buffer,MaxTextExtent,"/Height %lu\n",image->rows);
1481 (void) WriteBlobString(image,buffer);
1482 (void) FormatMagickString(buffer,MaxTextExtent,"/ColorSpace %lu 0 R\n",
1484 (void) WriteBlobString(image,buffer);
1485 (void) FormatMagickString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
1486 (compression == FaxCompression) || (compression == Group4Compression) ?
1488 (void) WriteBlobString(image,buffer);
1489 if (image->matte != MagickFalse)
1491 (void) FormatMagickString(buffer,MaxTextExtent,"/SMask %lu 0 R\n",
1493 (void) WriteBlobString(image,buffer);
1495 (void) FormatMagickString(buffer,MaxTextExtent,"/Length %lu 0 R\n",
1497 (void) WriteBlobString(image,buffer);
1498 (void) WriteBlobString(image,">>\n");
1499 (void) WriteBlobString(image,"stream\n");
1500 offset=TellBlob(image);
1501 number_pixels=(MagickSizeType) image->columns*image->rows;
1502 if ((4*number_pixels) != (MagickSizeType) ((size_t) (4*number_pixels)))
1503 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1504 if ((compression == FaxCompression) || (compression == Group4Compression) ||
1505 ((image_info->type != TrueColorType) &&
1506 (IsGrayImage(image,&image->exception) != MagickFalse)))
1508 switch (compression)
1510 case FaxCompression:
1511 case Group4Compression:
1513 if (LocaleCompare(CCITTParam,"0") == 0)
1515 (void) HuffmanEncodeImage(image_info,image,image);
1518 (void) Huffman2DEncodeImage(image_info,image,image);
1521 case JPEGCompression:
1523 status=InjectImageBlob(image_info,image,image,"jpeg",
1525 if (status == MagickFalse)
1526 ThrowWriterException(CoderError,image->exception.reason);
1529 case JPEG2000Compression:
1531 status=InjectImageBlob(image_info,image,image,"jp2",
1533 if (status == MagickFalse)
1534 ThrowWriterException(CoderError,image->exception.reason);
1537 case RLECompression:
1541 Allocate pixel array.
1543 length=(size_t) number_pixels;
1544 pixels=(unsigned char *) AcquireQuantumMemory(length,
1546 if (pixels == (unsigned char *) NULL)
1547 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1549 Dump Runlength encoded pixels.
1552 for (y=0; y < (long) image->rows; y++)
1554 p=GetVirtualPixels(image,0,y,image->columns,1,
1556 if (p == (const PixelPacket *) NULL)
1558 for (x=0; x < (long) image->columns; x++)
1560 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1563 if (image->previous == (Image *) NULL)
1565 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1566 if (status == MagickFalse)
1570 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1571 if (compression == ZipCompression)
1572 status=ZLIBEncodeImage(image,length,pixels);
1575 if (compression == LZWCompression)
1576 status=LZWEncodeImage(image,length,pixels);
1578 status=PackbitsEncodeImage(image,length,pixels);
1579 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1580 if (status == MagickFalse)
1582 (void) CloseBlob(image);
1583 return(MagickFalse);
1590 Dump uncompressed PseudoColor packets.
1592 Ascii85Initialize(image);
1593 for (y=0; y < (long) image->rows; y++)
1595 p=GetVirtualPixels(image,0,y,image->columns,1,
1597 if (p == (const PixelPacket *) NULL)
1599 for (x=0; x < (long) image->columns; x++)
1601 Ascii85Encode(image,
1602 ScaleQuantumToChar(PixelIntensityToQuantum(p)));
1605 if (image->previous == (Image *) NULL)
1607 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1608 if (status == MagickFalse)
1612 Ascii85Flush(image);
1618 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1619 (compression == JPEGCompression) ||
1620 (compression == JPEG2000Compression))
1621 switch (compression)
1623 case JPEGCompression:
1625 status=InjectImageBlob(image_info,image,image,"jpeg",
1627 if (status == MagickFalse)
1628 ThrowWriterException(CoderError,image->exception.reason);
1631 case JPEG2000Compression:
1633 status=InjectImageBlob(image_info,image,image,"jp2",
1635 if (status == MagickFalse)
1636 ThrowWriterException(CoderError,image->exception.reason);
1639 case RLECompression:
1643 Allocate pixel array.
1645 length=(size_t) number_pixels;
1646 pixels=(unsigned char *) AcquireQuantumMemory(length,
1648 length*=image->colorspace == CMYKColorspace ? 4UL : 3UL;
1649 if (pixels == (unsigned char *) NULL)
1650 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1652 Dump runoffset encoded pixels.
1655 for (y=0; y < (long) image->rows; y++)
1657 p=GetVirtualPixels(image,0,y,image->columns,1,
1659 if (p == (const PixelPacket *) NULL)
1661 indexes=GetVirtualIndexQueue(image);
1662 for (x=0; x < (long) image->columns; x++)
1664 *q++=ScaleQuantumToChar(p->red);
1665 *q++=ScaleQuantumToChar(p->green);
1666 *q++=ScaleQuantumToChar(p->blue);
1667 if (image->colorspace == CMYKColorspace)
1668 *q++=ScaleQuantumToChar(indexes[x]);
1671 if (image->previous == (Image *) NULL)
1673 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1674 if (status == MagickFalse)
1678 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1679 if (compression == ZipCompression)
1680 status=ZLIBEncodeImage(image,length,pixels);
1683 if (compression == LZWCompression)
1684 status=LZWEncodeImage(image,length,pixels);
1686 status=PackbitsEncodeImage(image,length,pixels);
1687 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1688 if (status == MagickFalse)
1690 (void) CloseBlob(image);
1691 return(MagickFalse);
1698 Dump uncompressed DirectColor packets.
1700 Ascii85Initialize(image);
1701 for (y=0; y < (long) image->rows; y++)
1703 p=GetVirtualPixels(image,0,y,image->columns,1,
1705 if (p == (const PixelPacket *) NULL)
1707 indexes=GetVirtualIndexQueue(image);
1708 for (x=0; x < (long) image->columns; x++)
1710 Ascii85Encode(image,ScaleQuantumToChar(p->red));
1711 Ascii85Encode(image,ScaleQuantumToChar(p->green));
1712 Ascii85Encode(image,ScaleQuantumToChar(p->blue));
1713 if (image->colorspace == CMYKColorspace)
1714 Ascii85Encode(image,ScaleQuantumToChar(indexes[x]));
1717 if (image->previous == (Image *) NULL)
1719 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1720 if (status == MagickFalse)
1724 Ascii85Flush(image);
1731 Dump number of colors and colormap.
1733 switch (compression)
1735 case RLECompression:
1739 Allocate pixel array.
1741 length=(size_t) number_pixels;
1742 pixels=(unsigned char *) AcquireQuantumMemory(length,
1744 if (pixels == (unsigned char *) NULL)
1745 ThrowWriterException(ResourceLimitError,
1746 "MemoryAllocationFailed");
1748 Dump Runlength encoded pixels.
1751 for (y=0; y < (long) image->rows; y++)
1753 p=GetVirtualPixels(image,0,y,image->columns,1,
1755 if (p == (const PixelPacket *) NULL)
1757 indexes=GetVirtualIndexQueue(image);
1758 for (x=0; x < (long) image->columns; x++)
1759 *q++=(unsigned char) indexes[x];
1760 if (image->previous == (Image *) NULL)
1762 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1763 if (status == MagickFalse)
1767 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1768 if (compression == ZipCompression)
1769 status=ZLIBEncodeImage(image,length,pixels);
1772 if (compression == LZWCompression)
1773 status=LZWEncodeImage(image,length,pixels);
1775 status=PackbitsEncodeImage(image,length,pixels);
1776 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1777 if (status == MagickFalse)
1779 (void) CloseBlob(image);
1780 return(MagickFalse);
1787 Dump uncompressed PseudoColor packets.
1789 Ascii85Initialize(image);
1790 for (y=0; y < (long) image->rows; y++)
1792 p=GetVirtualPixels(image,0,y,image->columns,1,
1794 if (p == (const PixelPacket *) NULL)
1796 indexes=GetVirtualIndexQueue(image);
1797 for (x=0; x < (long) image->columns; x++)
1798 Ascii85Encode(image,(unsigned char) indexes[x]);
1799 if (image->previous == (Image *) NULL)
1801 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1802 if (status == MagickFalse)
1806 Ascii85Flush(image);
1811 offset=TellBlob(image)-offset;
1812 (void) WriteBlobString(image,"\nendstream\n");
1813 (void) WriteBlobString(image,"endobj\n");
1815 Write Length object.
1817 xref[object++]=TellBlob(image);
1818 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1819 (void) WriteBlobString(image,buffer);
1820 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",
1821 (unsigned long) offset);
1822 (void) WriteBlobString(image,buffer);
1823 (void) WriteBlobString(image,"endobj\n");
1825 Write Colorspace object.
1827 xref[object++]=TellBlob(image);
1828 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1829 (void) WriteBlobString(image,buffer);
1830 if (image->colorspace == CMYKColorspace)
1831 (void) CopyMagickString(buffer,"/DeviceCMYK\n",MaxTextExtent);
1833 if ((compression == FaxCompression) ||
1834 (compression == Group4Compression) ||
1835 ((image_info->type != TrueColorType) &&
1836 (IsGrayImage(image,&image->exception) != MagickFalse)))
1837 (void) CopyMagickString(buffer,"/DeviceGray\n",MaxTextExtent);
1839 if ((image->storage_class == DirectClass) || (image->colors > 256) ||
1840 (compression == JPEGCompression) ||
1841 (compression == JPEG2000Compression))
1842 (void) CopyMagickString(buffer,"/DeviceRGB\n",MaxTextExtent);
1844 (void) FormatMagickString(buffer,MaxTextExtent,
1845 "[ /Indexed /DeviceRGB %lu %lu 0 R ]\n",
1846 image->colors-1,object+3);
1847 (void) WriteBlobString(image,buffer);
1848 (void) WriteBlobString(image,"endobj\n");
1852 SetGeometry(image,&geometry);
1853 (void) ParseMetaGeometry("106x106+0+0>",&geometry.x,&geometry.y,
1854 &geometry.width,&geometry.height);
1855 tile_image=ThumbnailImage(image,geometry.width,geometry.height,
1857 if (tile_image == (Image *) NULL)
1858 ThrowWriterException(ResourceLimitError,image->exception.reason);
1859 xref[object++]=TellBlob(image);
1860 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
1861 (void) WriteBlobString(image,buffer);
1862 (void) WriteBlobString(image,"<<\n");
1863 switch (compression)
1867 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"ASCII85Decode");
1870 case JPEGCompression:
1872 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"DCTDecode");
1873 if (image->colorspace != CMYKColorspace)
1875 (void) WriteBlobString(image,buffer);
1876 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1880 case JPEG2000Compression:
1882 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"JPXDecode");
1883 if (image->colorspace != CMYKColorspace)
1885 (void) WriteBlobString(image,buffer);
1886 (void) CopyMagickString(buffer,"/Decode [1 0 1 0 1 0 1 0]\n",
1890 case LZWCompression:
1892 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"LZWDecode");
1895 case ZipCompression:
1897 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"FlateDecode");
1900 case FaxCompression:
1901 case Group4Compression:
1903 (void) CopyMagickString(buffer,"/Filter [ /CCITTFaxDecode ]\n",
1905 (void) WriteBlobString(image,buffer);
1906 (void) FormatMagickString(buffer,MaxTextExtent,"/DecodeParms [ << "
1907 "/K %s /BlackIs1 false /Columns %lu /Rows %lu >> ]\n",CCITTParam,
1908 tile_image->columns,tile_image->rows);
1913 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,
1918 (void) WriteBlobString(image,buffer);
1919 (void) FormatMagickString(buffer,MaxTextExtent,"/Width %lu\n",
1920 tile_image->columns);
1921 (void) WriteBlobString(image,buffer);
1922 (void) FormatMagickString(buffer,MaxTextExtent,"/Height %lu\n",
1924 (void) WriteBlobString(image,buffer);
1925 (void) FormatMagickString(buffer,MaxTextExtent,"/ColorSpace %lu 0 R\n",
1927 (void) WriteBlobString(image,buffer);
1928 (void) FormatMagickString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
1929 (compression == FaxCompression) || (compression == Group4Compression) ?
1931 (void) WriteBlobString(image,buffer);
1932 (void) FormatMagickString(buffer,MaxTextExtent,"/Length %lu 0 R\n",
1934 (void) WriteBlobString(image,buffer);
1935 (void) WriteBlobString(image,">>\n");
1936 (void) WriteBlobString(image,"stream\n");
1937 offset=TellBlob(image);
1938 number_pixels=(MagickSizeType) tile_image->columns*tile_image->rows;
1939 if ((compression == FaxCompression) ||
1940 (compression == Group4Compression) ||
1941 ((image_info->type != TrueColorType) &&
1942 (IsGrayImage(tile_image,&image->exception) != MagickFalse)))
1944 switch (compression)
1946 case FaxCompression:
1947 case Group4Compression:
1949 if (LocaleCompare(CCITTParam,"0") == 0)
1951 (void) HuffmanEncodeImage(image_info,image,tile_image);
1954 (void) Huffman2DEncodeImage(image_info,image,tile_image);
1957 case JPEGCompression:
1959 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
1961 if (status == MagickFalse)
1962 ThrowWriterException(CoderError,tile_image->exception.reason);
1965 case JPEG2000Compression:
1967 status=InjectImageBlob(image_info,image,tile_image,"jp2",
1969 if (status == MagickFalse)
1970 ThrowWriterException(CoderError,tile_image->exception.reason);
1973 case RLECompression:
1977 Allocate pixel array.
1979 length=(size_t) number_pixels;
1980 pixels=(unsigned char *) AcquireQuantumMemory(length,
1982 if (pixels == (unsigned char *) NULL)
1984 tile_image=DestroyImage(tile_image);
1985 ThrowWriterException(ResourceLimitError,
1986 "MemoryAllocationFailed");
1989 Dump Runlength encoded pixels.
1992 for (y=0; y < (long) tile_image->rows; y++)
1994 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
1995 &tile_image->exception);
1996 if (p == (const PixelPacket *) NULL)
1998 for (x=0; x < (long) tile_image->columns; x++)
2000 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
2004 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2005 if (compression == ZipCompression)
2006 status=ZLIBEncodeImage(image,length,pixels);
2009 if (compression == LZWCompression)
2010 status=LZWEncodeImage(image,length,pixels);
2012 status=PackbitsEncodeImage(image,length,pixels);
2013 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2014 if (status == MagickFalse)
2016 (void) CloseBlob(image);
2017 return(MagickFalse);
2024 Dump uncompressed PseudoColor packets.
2026 Ascii85Initialize(image);
2027 for (y=0; y < (long) tile_image->rows; y++)
2029 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2030 &tile_image->exception);
2031 if (p == (const PixelPacket *) NULL)
2033 for (x=0; x < (long) tile_image->columns; x++)
2035 Ascii85Encode(image,
2036 ScaleQuantumToChar(PixelIntensityToQuantum(p)));
2040 Ascii85Flush(image);
2046 if ((tile_image->storage_class == DirectClass) ||
2047 (tile_image->colors > 256) || (compression == JPEGCompression) ||
2048 (compression == JPEG2000Compression))
2049 switch (compression)
2051 case JPEGCompression:
2053 status=InjectImageBlob(image_info,image,tile_image,"jpeg",
2055 if (status == MagickFalse)
2056 ThrowWriterException(CoderError,tile_image->exception.reason);
2059 case JPEG2000Compression:
2061 status=InjectImageBlob(image_info,image,tile_image,"jp2",
2063 if (status == MagickFalse)
2064 ThrowWriterException(CoderError,tile_image->exception.reason);
2067 case RLECompression:
2071 Allocate pixel array.
2073 length=(size_t) number_pixels;
2074 pixels=(unsigned char *) AcquireQuantumMemory(length,4*
2076 length*=tile_image->colorspace == CMYKColorspace ? 4UL : 3UL;
2077 if (pixels == (unsigned char *) NULL)
2079 tile_image=DestroyImage(tile_image);
2080 ThrowWriterException(ResourceLimitError,
2081 "MemoryAllocationFailed");
2084 Dump runoffset encoded pixels.
2087 for (y=0; y < (long) tile_image->rows; y++)
2089 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2090 &tile_image->exception);
2091 if (p == (const PixelPacket *) NULL)
2093 indexes=GetVirtualIndexQueue(tile_image);
2094 for (x=0; x < (long) tile_image->columns; x++)
2096 *q++=ScaleQuantumToChar(p->red);
2097 *q++=ScaleQuantumToChar(p->green);
2098 *q++=ScaleQuantumToChar(p->blue);
2099 if (image->colorspace == CMYKColorspace)
2100 *q++=ScaleQuantumToChar(indexes[x]);
2104 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2105 if (compression == ZipCompression)
2106 status=ZLIBEncodeImage(image,length,pixels);
2109 if (compression == LZWCompression)
2110 status=LZWEncodeImage(image,length,pixels);
2112 status=PackbitsEncodeImage(image,length,pixels);
2113 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2114 if (status == MagickFalse)
2116 (void) CloseBlob(image);
2117 return(MagickFalse);
2124 Dump uncompressed DirectColor packets.
2126 Ascii85Initialize(image);
2127 for (y=0; y < (long) tile_image->rows; y++)
2129 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2130 &tile_image->exception);
2131 if (p == (const PixelPacket *) NULL)
2133 indexes=GetVirtualIndexQueue(tile_image);
2134 for (x=0; x < (long) tile_image->columns; x++)
2136 Ascii85Encode(image,ScaleQuantumToChar(p->red));
2137 Ascii85Encode(image,ScaleQuantumToChar(p->green));
2138 Ascii85Encode(image,ScaleQuantumToChar(p->blue));
2139 if (image->colorspace == CMYKColorspace)
2140 Ascii85Encode(image,ScaleQuantumToChar(indexes[x]));
2144 Ascii85Flush(image);
2151 Dump number of colors and colormap.
2153 switch (compression)
2155 case RLECompression:
2159 Allocate pixel array.
2161 length=(size_t) number_pixels;
2162 pixels=(unsigned char *) AcquireQuantumMemory(length,
2164 if (pixels == (unsigned char *) NULL)
2166 tile_image=DestroyImage(tile_image);
2167 ThrowWriterException(ResourceLimitError,
2168 "MemoryAllocationFailed");
2171 Dump Runlength encoded pixels.
2174 for (y=0; y < (long) tile_image->rows; y++)
2176 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2177 &tile_image->exception);
2178 if (p == (const PixelPacket *) NULL)
2180 indexes=GetVirtualIndexQueue(tile_image);
2181 for (x=0; x < (long) tile_image->columns; x++)
2182 *q++=(unsigned char) indexes[x];
2184 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2185 if (compression == ZipCompression)
2186 status=ZLIBEncodeImage(image,length,pixels);
2189 if (compression == LZWCompression)
2190 status=LZWEncodeImage(image,length,pixels);
2192 status=PackbitsEncodeImage(image,length,pixels);
2193 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2194 if (status == MagickFalse)
2196 (void) CloseBlob(image);
2197 return(MagickFalse);
2204 Dump uncompressed PseudoColor packets.
2206 Ascii85Initialize(image);
2207 for (y=0; y < (long) tile_image->rows; y++)
2209 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,1,
2210 &tile_image->exception);
2211 if (p == (const PixelPacket *) NULL)
2213 indexes=GetVirtualIndexQueue(tile_image);
2214 for (x=0; x < (long) tile_image->columns; x++)
2215 Ascii85Encode(image,(unsigned char) indexes[x]);
2217 Ascii85Flush(image);
2222 tile_image=DestroyImage(tile_image);
2223 offset=TellBlob(image)-offset;
2224 (void) WriteBlobString(image,"\nendstream\n");
2225 (void) WriteBlobString(image,"endobj\n");
2227 Write Length object.
2229 xref[object++]=TellBlob(image);
2230 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
2231 (void) WriteBlobString(image,buffer);
2232 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",
2233 (unsigned long) offset);
2234 (void) WriteBlobString(image,buffer);
2235 (void) WriteBlobString(image,"endobj\n");
2236 xref[object++]=TellBlob(image);
2237 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
2238 (void) WriteBlobString(image,buffer);
2239 if ((image->storage_class != DirectClass) && (image->colors <= 256) &&
2240 (compression != FaxCompression) && (compression != Group4Compression))
2243 Write Colormap object.
2245 (void) WriteBlobString(image,"<<\n");
2246 if (compression == NoCompression)
2247 (void) WriteBlobString(image,"/Filter [ /ASCII85Decode ]\n");
2248 (void) FormatMagickString(buffer,MaxTextExtent,"/Length %lu 0 R\n",
2250 (void) WriteBlobString(image,buffer);
2251 (void) WriteBlobString(image,">>\n");
2252 (void) WriteBlobString(image,"stream\n");
2253 offset=TellBlob(image);
2254 if (compression == NoCompression)
2255 Ascii85Initialize(image);
2256 for (i=0; i < (long) image->colors; i++)
2258 if (compression == NoCompression)
2260 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].red));
2261 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].green));
2262 Ascii85Encode(image,ScaleQuantumToChar(image->colormap[i].blue));
2265 (void) WriteBlobByte(image,
2266 ScaleQuantumToChar(image->colormap[i].red));
2267 (void) WriteBlobByte(image,
2268 ScaleQuantumToChar(image->colormap[i].green));
2269 (void) WriteBlobByte(image,
2270 ScaleQuantumToChar(image->colormap[i].blue));
2272 if (compression == NoCompression)
2273 Ascii85Flush(image);
2274 offset=TellBlob(image)-offset;
2275 (void) WriteBlobString(image,"\nendstream\n");
2277 (void) WriteBlobString(image,"endobj\n");
2279 Write Length object.
2281 xref[object++]=TellBlob(image);
2282 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
2283 (void) WriteBlobString(image,buffer);
2284 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",
2285 (unsigned long) offset);
2286 (void) WriteBlobString(image,buffer);
2287 (void) WriteBlobString(image,"endobj\n");
2289 Write softmask object.
2291 xref[object++]=TellBlob(image);
2292 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
2293 (void) WriteBlobString(image,buffer);
2294 (void) WriteBlobString(image,"<<\n");
2295 if (image->matte == MagickFalse)
2296 (void) WriteBlobString(image,">>\n");
2299 (void) WriteBlobString(image,"/Type /XObject\n");
2300 (void) WriteBlobString(image,"/Subtype /Image\n");
2301 (void) FormatMagickString(buffer,MaxTextExtent,"/Name /Ma%lu\n",
2303 (void) WriteBlobString(image,buffer);
2304 switch (compression)
2308 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,
2312 case LZWCompression:
2314 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,"LZWDecode");
2317 case ZipCompression:
2319 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,
2325 (void) FormatMagickString(buffer,MaxTextExtent,CFormat,
2330 (void) WriteBlobString(image,buffer);
2331 (void) FormatMagickString(buffer,MaxTextExtent,"/Width %lu\n",
2333 (void) WriteBlobString(image,buffer);
2334 (void) FormatMagickString(buffer,MaxTextExtent,"/Height %lu\n",
2336 (void) WriteBlobString(image,buffer);
2337 (void) WriteBlobString(image,"/ColorSpace /DeviceGray\n");
2338 (void) FormatMagickString(buffer,MaxTextExtent,"/BitsPerComponent %d\n",
2339 (compression == FaxCompression) || (compression == Group4Compression)
2341 (void) WriteBlobString(image,buffer);
2342 (void) FormatMagickString(buffer,MaxTextExtent,"/Length %lu 0 R\n",
2344 (void) WriteBlobString(image,buffer);
2345 (void) WriteBlobString(image,">>\n");
2346 (void) WriteBlobString(image,"stream\n");
2347 offset=TellBlob(image);
2348 number_pixels=(MagickSizeType) image->columns*image->rows;
2349 switch (compression)
2351 case RLECompression:
2355 Allocate pixel array.
2357 length=(size_t) number_pixels;
2358 pixels=(unsigned char *) AcquireQuantumMemory(length,
2360 if (pixels == (unsigned char *) NULL)
2362 image=DestroyImage(image);
2363 ThrowWriterException(ResourceLimitError,
2364 "MemoryAllocationFailed");
2367 Dump Runlength encoded pixels.
2370 for (y=0; y < (long) image->rows; y++)
2372 p=GetVirtualPixels(image,0,y,image->columns,1,
2374 if (p == (const PixelPacket *) NULL)
2376 for (x=0; x < (long) image->columns; x++)
2378 *q++=ScaleQuantumToChar((Quantum) (QuantumRange-p->opacity));
2382 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2383 if (compression == ZipCompression)
2384 status=ZLIBEncodeImage(image,length,pixels);
2387 if (compression == LZWCompression)
2388 status=LZWEncodeImage(image,length,pixels);
2390 status=PackbitsEncodeImage(image,length,pixels);
2391 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
2392 if (status == MagickFalse)
2394 (void) CloseBlob(image);
2395 return(MagickFalse);
2402 Dump uncompressed PseudoColor packets.
2404 Ascii85Initialize(image);
2405 for (y=0; y < (long) image->rows; y++)
2407 p=GetVirtualPixels(image,0,y,image->columns,1,
2409 if (p == (const PixelPacket *) NULL)
2411 for (x=0; x < (long) image->columns; x++)
2413 Ascii85Encode(image,ScaleQuantumToChar((Quantum) (QuantumRange-
2418 Ascii85Flush(image);
2422 offset=TellBlob(image)-offset;
2423 (void) WriteBlobString(image,"\nendstream\n");
2425 (void) WriteBlobString(image,"endobj\n");
2427 Write Length object.
2429 xref[object++]=TellBlob(image);
2430 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
2431 (void) WriteBlobString(image,buffer);
2432 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",(unsigned long)
2434 (void) WriteBlobString(image,buffer);
2435 (void) WriteBlobString(image,"endobj\n");
2436 if (GetNextImageInList(image) == (Image *) NULL)
2438 image=SyncNextImageInList(image);
2439 status=SetImageProgress(image,SaveImagesTag,scene++,
2440 GetImageListLength(image));
2441 if (status == MagickFalse)
2443 } while (image_info->adjoin != MagickFalse);
2445 Write Metadata object.
2447 xref[object++]=TellBlob(image);
2449 (void) FormatMagickString(buffer,MaxTextExtent,"%lu 0 obj\n",object);
2450 (void) WriteBlobString(image,buffer);
2451 (void) WriteBlobString(image,"<<\n");
2452 (void) FormatMagickString(buffer,MaxTextExtent,"/Title (%s)\n",
2453 EscapeParenthesis(image->filename));
2454 (void) WriteBlobString(image,buffer);
2455 seconds=time((time_t *) NULL);
2456 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
2457 (void) localtime_r(&seconds,&local_time);
2459 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
2461 (void) FormatMagickString(date,MaxTextExtent,"D:%04d%02d%02d%02d%02d%02d",
2462 local_time.tm_year+1900,local_time.tm_mon+1,local_time.tm_mday,
2463 local_time.tm_hour,local_time.tm_min,local_time.tm_sec);
2464 (void) FormatMagickString(buffer,MaxTextExtent,"/CreationDate (%s)\n",date);
2465 (void) WriteBlobString(image,buffer);
2466 (void) FormatMagickString(buffer,MaxTextExtent,"/ModDate (%s)\n",date);
2467 (void) WriteBlobString(image,buffer);
2468 (void) FormatMagickString(buffer,MaxTextExtent,"/Producer (%s)\n",
2469 EscapeParenthesis(GetMagickVersion((unsigned long *) NULL)));
2470 (void) WriteBlobString(image,buffer);
2471 (void) WriteBlobString(image,">>\n");
2472 (void) WriteBlobString(image,"endobj\n");
2476 offset=TellBlob(image)-xref[0]+10;
2477 (void) WriteBlobString(image,"xref\n");
2478 (void) FormatMagickString(buffer,MaxTextExtent,"0 %lu\n",object+1);
2479 (void) WriteBlobString(image,buffer);
2480 (void) WriteBlobString(image,"0000000000 65535 f \n");
2481 for (i=0; i < (long) object; i++)
2483 (void) FormatMagickString(buffer,MaxTextExtent,"%010lu 00000 n \n",
2484 (unsigned long) xref[i]);
2485 (void) WriteBlobString(image,buffer);
2487 (void) WriteBlobString(image,"trailer\n");
2488 (void) WriteBlobString(image,"<<\n");
2489 (void) FormatMagickString(buffer,MaxTextExtent,"/Size %lu\n",object+1);
2490 (void) WriteBlobString(image,buffer);
2491 (void) FormatMagickString(buffer,MaxTextExtent,"/Info %lu 0 R\n",info_id);
2492 (void) WriteBlobString(image,buffer);
2493 (void) FormatMagickString(buffer,MaxTextExtent,"/Root %lu 0 R\n",root_id);
2494 (void) WriteBlobString(image,buffer);
2495 (void) WriteBlobString(image,">>\n");
2496 (void) WriteBlobString(image,"startxref\n");
2497 (void) FormatMagickString(buffer,MaxTextExtent,"%lu\n",
2498 (unsigned long) offset);
2499 (void) WriteBlobString(image,buffer);
2500 (void) WriteBlobString(image,"%%EOF\n");
2501 xref=(MagickOffsetType *) RelinquishMagickMemory(xref);
2502 (void) CloseBlob(image);