2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Photo CD Image Format %
20 % Copyright 1999-2011 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/property.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/client.h"
48 #include "MagickCore/colorspace.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/decorate.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/gem.h"
55 #include "MagickCore/geometry.h"
56 #include "MagickCore/image.h"
57 #include "MagickCore/image-private.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/monitor-private.h"
63 #include "MagickCore/montage.h"
64 #include "MagickCore/pixel-accessor.h"
65 #include "MagickCore/resize.h"
66 #include "MagickCore/shear.h"
67 #include "MagickCore/quantum-private.h"
68 #include "MagickCore/static.h"
69 #include "MagickCore/string_.h"
70 #include "MagickCore/module.h"
71 #include "MagickCore/transform.h"
72 #include "MagickCore/utility.h"
77 static MagickBooleanType
78 WritePCDImage(const ImageInfo *,Image *);
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % D e c o d e I m a g e %
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 % DecodeImage recovers the Huffman encoded luminance and chrominance
94 % The format of the DecodeImage method is:
96 % MagickBooleanType DecodeImage(Image *image,unsigned char *luma,
97 % unsigned char *chroma1,unsigned char *chroma2)
99 % A description of each parameter follows:
101 % o image: the address of a structure of type Image.
103 % o luma: the address of a character buffer that contains the
104 % luminance information.
106 % o chroma1: the address of a character buffer that contains the
107 % chrominance information.
109 % o chroma2: the address of a character buffer that contains the
110 % chrominance information.
113 static MagickBooleanType DecodeImage(Image *image,unsigned char *luma,
114 unsigned char *chroma1,unsigned char *chroma2)
116 #define IsSync ((sum & 0xffffff00UL) == 0xfffffe00UL)
117 #define PCDGetBits(n) \
119 sum=(sum << n) & 0xffffffff; \
123 if (p >= (buffer+0x800)) \
125 count=ReadBlob(image,0x800,buffer); \
128 sum|=((unsigned int) (*p) << (24-bits)); \
132 if (EOFBlob(image) != MagickFalse) \
136 typedef struct PCDTable
159 register unsigned char
179 Initialize Huffman tables.
181 assert(image != (const Image *) NULL);
182 assert(image->signature == MagickSignature);
183 if (image->debug != MagickFalse)
184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
185 assert(luma != (unsigned char *) NULL);
186 assert(chroma1 != (unsigned char *) NULL);
187 assert(chroma2 != (unsigned char *) NULL);
188 buffer=(unsigned char *) AcquireQuantumMemory(0x800,sizeof(*buffer));
189 if (buffer == (unsigned char *) NULL)
190 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
195 for (i=0; i < (image->columns > 1536 ? 3 : 1); i++)
198 length=(sum & 0xff)+1;
199 pcd_table[i]=(PCDTable *) AcquireQuantumMemory(length,
200 sizeof(*pcd_table[i]));
201 if (pcd_table[i] == (PCDTable *) NULL)
203 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
204 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
208 for (j=0; j < (ssize_t) length; j++)
211 r->length=(unsigned int) (sum & 0xff)+1;
214 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
218 r->sequence=(unsigned int) (sum & 0xffff) << 16;
220 r->key=(unsigned char) (sum & 0xff);
221 r->mask=(~((1U << (32-r->length))-1));
224 pcd_length[i]=(size_t) length;
227 Search for Sync byte.
229 for (i=0; i < 1; i++)
231 for (i=0; i < 1; i++)
233 while ((sum & 0x00fff000UL) != 0x00fff000UL)
238 Recover the Huffman encoded luminance and chrominance deltas.
250 Determine plane and row number.
253 row=((sum >> 9) & 0x1fff);
254 if (row == image->rows)
263 q=luma+row*image->columns;
264 count=(ssize_t) image->columns;
269 q=chroma1+(row >> 1)*image->columns;
270 count=(ssize_t) (image->columns >> 1);
276 q=chroma2+(row >> 1)*image->columns;
277 count=(ssize_t) (image->columns >> 1);
283 ThrowBinaryException(CorruptImageError,"CorruptImage",
287 length=pcd_length[plane];
291 Decode luminance or chrominance deltas.
294 for (i=0; ((i < (ssize_t) length) && ((sum & r->mask) != r->sequence)); i++)
296 if ((row > image->rows) || (r == (PCDTable *) NULL))
298 (void) ThrowMagickException(&image->exception,GetMagickModule(),
299 CorruptImageWarning,"SkipToSyncByte","`%s'",image->filename);
300 while ((sum & 0x00fff000) != 0x00fff000)
307 quantum=(ssize_t) (*q)+r->key;
309 quantum=(ssize_t) (*q)+r->key-256;
310 *q=(unsigned char) ((quantum < 0) ? 0 : (quantum > 255) ? 255 : quantum);
312 PCDGetBits(r->length);
316 Relinquish resources.
318 for (i=0; i < (image->columns > 1536 ? 3 : 1); i++)
319 pcd_table[i]=(PCDTable *) RelinquishMagickMemory(pcd_table[i]);
320 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % IsPCD() returns MagickTrue if the image format type, identified by the
336 % magick string, is PCD.
338 % The format of the IsPCD method is:
340 % MagickBooleanType IsPCD(const unsigned char *magick,const size_t length)
342 % A description of each parameter follows:
344 % o magick: compare image format pattern against these bytes.
346 % o length: Specifies the length of the magick string.
349 static MagickBooleanType IsPCD(const unsigned char *magick,const size_t length)
353 if (LocaleNCompare((const char *) magick+2048,"PCD_",4) == 0)
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % R e a d P C D I m a g e %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 % ReadPCDImage() reads a Photo CD image file and returns it. It
370 % allocates the memory necessary for the new Image structure and returns a
371 % pointer to the new image. Much of the PCD decoder was derived from
372 % the program hpcdtoppm(1) by Hadmut Danisch.
374 % The format of the ReadPCDImage method is:
376 % image=ReadPCDImage(image_info)
378 % A description of each parameter follows:
380 % o image_info: the image info.
382 % o exception: return any errors or warnings in this structure.
386 static inline size_t MagickMin(const size_t x,const size_t y)
393 static Image *OverviewImage(const ImageInfo *image_info,Image *image,
394 ExceptionInfo *exception)
406 Create the PCD Overview image.
408 for (p=image; p != (Image *) NULL; p=p->next)
410 (void) DeleteImageProperty(p,"label");
411 (void) SetImageProperty(p,"label",DefaultTileLabel);
413 montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
414 (void) CopyMagickString(montage_info->filename,image_info->filename,
416 montage_image=MontageImageList(image_info,montage_info,image,exception);
417 montage_info=DestroyMontageInfo(montage_info);
418 if (montage_image == (Image *) NULL)
419 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
420 image=DestroyImage(image);
421 return(montage_image);
424 static void Upsample(const size_t width,const size_t height,
425 const size_t scaled_width,unsigned char *pixels)
431 register unsigned char
437 Create a new image that is a integral size greater than an existing one.
439 assert(pixels != (unsigned char *) NULL);
440 for (y=0; y < (ssize_t) height; y++)
442 p=pixels+(height-1-y)*scaled_width+(width-1);
443 q=pixels+((height-1-y) << 1)*scaled_width+((width-1) << 1);
446 for (x=1; x < (ssize_t) width; x++)
451 *(q+1)=(unsigned char) ((((size_t) *p)+((size_t) *(p+1))+1) >> 1);
454 for (y=0; y < (ssize_t) (height-1); y++)
456 p=pixels+((size_t) y << 1)*scaled_width;
459 for (x=0; x < (ssize_t) (width-1); x++)
461 *q=(unsigned char) ((((size_t) *p)+((size_t) *r)+1) >> 1);
462 *(q+1)=(unsigned char) ((((size_t) *p)+((size_t) *(p+2))+
463 ((size_t) *r)+((size_t) *(r+2))+2) >> 2);
468 *q++=(unsigned char) ((((size_t) *p++)+((size_t) *r++)+1) >> 1);
469 *q++=(unsigned char) ((((size_t) *p++)+((size_t) *r++)+1) >> 1);
471 p=pixels+(2*height-2)*scaled_width;
472 q=pixels+(2*height-1)*scaled_width;
473 (void) CopyMagickMemory(q,p,(size_t) (2*width));
476 static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
497 register unsigned char
525 assert(image_info != (const ImageInfo *) NULL);
526 assert(image_info->signature == MagickSignature);
527 if (image_info->debug != MagickFalse)
528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
529 image_info->filename);
530 assert(exception != (ExceptionInfo *) NULL);
531 assert(exception->signature == MagickSignature);
532 image=AcquireImage(image_info);
533 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
534 if (status == MagickFalse)
536 image=DestroyImageList(image);
537 return((Image *) NULL);
540 Determine if this a PCD file.
542 header=(unsigned char *) AcquireQuantumMemory(0x800,3UL*sizeof(*header));
543 if (header == (unsigned char *) NULL)
544 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
545 count=ReadBlob(image,3*0x800,header);
546 overview=LocaleNCompare((char *) header,"PCD_OPA",7) == 0;
548 ((LocaleNCompare((char *) header+0x800,"PCD",3) != 0) && !overview))
549 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
550 rotate=header[0x0e02] & 0x03;
551 number_images=(header[10] << 8) | header[11];
552 header=(unsigned char *) RelinquishMagickMemory(header);
554 Determine resolution by scene specification.
556 if ((image->columns == 0) || (image->rows == 0))
562 for (scene=1; scene < 6; scene++)
564 if ((width >= image->columns) && (height >= image->rows))
570 if (image_info->number_scenes != 0)
571 scene=(size_t) MagickMin(image_info->scene,6);
575 Initialize image structure.
579 for (i=1; i < (ssize_t) MagickMin(scene,3); i++)
584 image->columns=width;
587 for ( ; i < (ssize_t) scene; i++)
593 Allocate luma and chroma memory.
595 number_pixels=(MagickSizeType) image->columns*image->rows;
596 if (number_pixels != (size_t) number_pixels)
597 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
598 chroma1=(unsigned char *) AcquireQuantumMemory(image->columns+1UL,image->rows*
600 chroma2=(unsigned char *) AcquireQuantumMemory(image->columns+1UL,image->rows*
602 luma=(unsigned char *) AcquireQuantumMemory(image->columns+1UL,image->rows*
604 if ((chroma1 == (unsigned char *) NULL) ||
605 (chroma2 == (unsigned char *) NULL) || (luma == (unsigned char *) NULL))
606 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
608 Advance to image data.
619 for (i=0; i < (ssize_t) (offset*0x800); i++)
620 (void) ReadBlobByte(image);
626 MagickProgressMonitor
633 Read thumbnails from overview image.
635 for (j=1; j <= (ssize_t) number_images; j++)
637 progress_monitor=SetImageProgressMonitor(image,
638 (MagickProgressMonitor) NULL,image->client_data);
639 (void) FormatLocaleString(image->filename,MaxTextExtent,
640 "images/img%04ld.pcd",(long) j);
641 (void) FormatLocaleString(image->magick_filename,MaxTextExtent,
642 "images/img%04ld.pcd",(long) j);
643 image->scene=(size_t) j;
644 image->columns=width;
650 for (y=0; y < (ssize_t) height; y+=2)
652 count=ReadBlob(image,width,yy);
654 count=ReadBlob(image,width,yy);
656 count=ReadBlob(image,width >> 1,c1);
658 count=ReadBlob(image,width >> 1,c2);
661 Upsample(image->columns >> 1,image->rows >> 1,image->columns,chroma1);
662 Upsample(image->columns >> 1,image->rows >> 1,image->columns,chroma2);
664 Transfer luminance and chrominance channels.
669 for (y=0; y < (ssize_t) image->rows; y++)
671 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
672 if (q == (const Quantum *) NULL)
674 for (x=0; x < (ssize_t) image->columns; x++)
676 SetPixelRed(image,ScaleCharToQuantum(*yy++),q);
677 SetPixelGreen(image,ScaleCharToQuantum(*c1++),q);
678 SetPixelBlue(image,ScaleCharToQuantum(*c2++),q);
679 q+=GetPixelChannels(image);
681 if (SyncAuthenticPixels(image,exception) == MagickFalse)
684 image->colorspace=YCCColorspace;
685 if (LocaleCompare(image_info->magick,"PCDS") == 0)
686 image->colorspace=sRGBColorspace;
687 if (j < (ssize_t) number_images)
690 Allocate next image structure.
692 AcquireNextImage(image_info,image);
693 if (GetNextImageInList(image) == (Image *) NULL)
695 image=DestroyImageList(image);
696 return((Image *) NULL);
698 image=SyncNextImageInList(image);
700 (void) SetImageProgressMonitor(image,progress_monitor,
702 if (image->previous == (Image *) NULL)
704 status=SetImageProgress(image,LoadImageTag,j-1,number_images);
705 if (status == MagickFalse)
709 chroma2=(unsigned char *) RelinquishMagickMemory(chroma2);
710 chroma1=(unsigned char *) RelinquishMagickMemory(chroma1);
711 luma=(unsigned char *) RelinquishMagickMemory(luma);
712 image=GetFirstImageInList(image);
713 overview_image=OverviewImage(image_info,image,exception);
714 return(overview_image);
717 Read interleaved image.
722 for (y=0; y < (ssize_t) height; y+=2)
724 count=ReadBlob(image,width,yy);
726 count=ReadBlob(image,width,yy);
728 count=ReadBlob(image,width >> 1,c1);
730 count=ReadBlob(image,width >> 1,c2);
736 Recover luminance deltas for 1536x1024 image.
738 Upsample(768,512,image->columns,luma);
739 Upsample(384,256,image->columns,chroma1);
740 Upsample(384,256,image->columns,chroma2);
742 for (i=0; i < (4*0x800); i++)
743 (void) ReadBlobByte(image);
744 status=DecodeImage(image,luma,chroma1,chroma2);
745 if ((scene >= 5) && status)
748 Recover luminance deltas for 3072x2048 image.
750 Upsample(1536,1024,image->columns,luma);
751 Upsample(768,512,image->columns,chroma1);
752 Upsample(768,512,image->columns,chroma2);
754 offset=TellBlob(image)/0x800+12;
755 offset=SeekBlob(image,offset*0x800,SEEK_SET);
756 status=DecodeImage(image,luma,chroma1,chroma2);
757 if ((scene >= 6) && (status != MagickFalse))
760 Recover luminance deltas for 6144x4096 image (vaporware).
762 Upsample(3072,2048,image->columns,luma);
763 Upsample(1536,1024,image->columns,chroma1);
764 Upsample(1536,1024,image->columns,chroma2);
769 Upsample(image->columns >> 1,image->rows >> 1,image->columns,chroma1);
770 Upsample(image->columns >> 1,image->rows >> 1,image->columns,chroma2);
772 Transfer luminance and chrominance channels.
777 for (y=0; y < (ssize_t) image->rows; y++)
779 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
780 if (q == (const Quantum *) NULL)
782 for (x=0; x < (ssize_t) image->columns; x++)
784 SetPixelRed(image,ScaleCharToQuantum(*yy++),q);
785 SetPixelGreen(image,ScaleCharToQuantum(*c1++),q);
786 SetPixelBlue(image,ScaleCharToQuantum(*c2++),q);
787 q+=GetPixelChannels(image);
789 if (SyncAuthenticPixels(image,exception) == MagickFalse)
791 if (image->previous == (Image *) NULL)
793 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
795 if (status == MagickFalse)
799 chroma2=(unsigned char *) RelinquishMagickMemory(chroma2);
800 chroma1=(unsigned char *) RelinquishMagickMemory(chroma1);
801 luma=(unsigned char *) RelinquishMagickMemory(luma);
802 if (EOFBlob(image) != MagickFalse)
803 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
805 (void) CloseBlob(image);
806 if (image_info->ping == MagickFalse)
807 if ((rotate == 1) || (rotate == 3))
818 degrees=rotate == 1 ? -90.0 : 90.0;
819 rotate_image=RotateImage(image,degrees,exception);
820 if (rotate_image != (Image *) NULL)
822 image=DestroyImage(image);
827 Set CCIR 709 primaries with a D65 white point.
829 image->chromaticity.red_primary.x=0.6400f;
830 image->chromaticity.red_primary.y=0.3300f;
831 image->chromaticity.green_primary.x=0.3000f;
832 image->chromaticity.green_primary.y=0.6000f;
833 image->chromaticity.blue_primary.x=0.1500f;
834 image->chromaticity.blue_primary.y=0.0600f;
835 image->chromaticity.white_point.x=0.3127f;
836 image->chromaticity.white_point.y=0.3290f;
837 image->gamma=1.000f/2.200f;
838 image->colorspace=YCCColorspace;
839 if (LocaleCompare(image_info->magick,"PCDS") == 0)
840 image->colorspace=sRGBColorspace;
841 return(GetFirstImageInList(image));
845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
849 % R e g i s t e r P C D I m a g e %
853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
855 % RegisterPCDImage() adds attributes for the PCD image format to
856 % the list of supported formats. The attributes include the image format
857 % tag, a method to read and/or write the format, whether the format
858 % supports the saving of more than one frame to the same file or blob,
859 % whether the format supports native in-memory I/O, and a brief
860 % description of the format.
862 % The format of the RegisterPCDImage method is:
864 % size_t RegisterPCDImage(void)
867 ModuleExport size_t RegisterPCDImage(void)
872 entry=SetMagickInfo("PCD");
873 entry->decoder=(DecodeImageHandler *) ReadPCDImage;
874 entry->encoder=(EncodeImageHandler *) WritePCDImage;
875 entry->magick=(IsImageFormatHandler *) IsPCD;
876 entry->adjoin=MagickFalse;
877 entry->seekable_stream=MagickTrue;
878 entry->description=ConstantString("Photo CD");
879 entry->module=ConstantString("PCD");
880 (void) RegisterMagickInfo(entry);
881 entry=SetMagickInfo("PCDS");
882 entry->decoder=(DecodeImageHandler *) ReadPCDImage;
883 entry->encoder=(EncodeImageHandler *) WritePCDImage;
884 entry->adjoin=MagickFalse;
885 entry->seekable_stream=MagickTrue;
886 entry->description=ConstantString("Photo CD");
887 entry->module=ConstantString("PCD");
888 (void) RegisterMagickInfo(entry);
889 return(MagickImageCoderSignature);
893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897 % U n r e g i s t e r P C D I m a g e %
901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 % UnregisterPCDImage() removes format registrations made by the
904 % PCD module from the list of supported formats.
906 % The format of the UnregisterPCDImage method is:
908 % UnregisterPCDImage(void)
911 ModuleExport void UnregisterPCDImage(void)
913 (void) UnregisterMagickInfo("PCD");
914 (void) UnregisterMagickInfo("PCDS");
918 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
922 % W r i t e P C D I m a g e %
926 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
928 % WritePCDImage() writes an image in the Photo CD encoded image format.
930 % The format of the WritePCDImage method is:
932 % MagickBooleanType WritePCDImage(const ImageInfo *image_info,Image *image)
934 % A description of each parameter follows.
936 % o image_info: the image info.
938 % o image: The image.
942 static MagickBooleanType WritePCDTile(Image *image,const char *page_geometry,
943 const char *tile_geometry)
961 register const Quantum
973 Scale image to tile size.
975 SetGeometry(image,&geometry);
976 (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y,
977 &geometry.width,&geometry.height);
978 if ((geometry.width % 2) != 0)
980 if ((geometry.height % 2) != 0)
982 tile_image=ResizeImage(image,geometry.width,geometry.height,TriangleFilter,
983 1.0,&image->exception);
984 if (tile_image == (Image *) NULL)
986 flags=ParseGeometry(page_geometry,&geometry_info);
987 geometry.width=(size_t) geometry_info.rho;
988 geometry.height=(size_t) geometry_info.sigma;
989 if ((flags & SigmaValue) == 0)
990 geometry.height=geometry.width;
991 if ((tile_image->columns != geometry.width) ||
992 (tile_image->rows != geometry.height))
1001 Put a border around the image.
1003 border_info.width=(geometry.width-tile_image->columns+1) >> 1;
1004 border_info.height=(geometry.height-tile_image->rows+1) >> 1;
1005 bordered_image=BorderImage(tile_image,&border_info,&image->exception);
1006 if (bordered_image == (Image *) NULL)
1007 return(MagickFalse);
1008 tile_image=DestroyImage(tile_image);
1009 tile_image=bordered_image;
1011 (void) TransformImage(&tile_image,(char *) NULL,tile_geometry);
1012 if (IsRGBColorspace(image->colorspace) == MagickFalse)
1013 (void) TransformImageColorspace(tile_image,YCCColorspace);
1014 downsample_image=ResizeImage(tile_image,tile_image->columns/2,
1015 tile_image->rows/2,TriangleFilter,1.0,&image->exception);
1016 if (downsample_image == (Image *) NULL)
1017 return(MagickFalse);
1019 Write tile to PCD file.
1021 for (y=0; y < (ssize_t) tile_image->rows; y+=2)
1023 p=GetVirtualPixels(tile_image,0,y,tile_image->columns,2,
1024 &tile_image->exception);
1025 if (p == (const Quantum *) NULL)
1027 for (x=0; x < (ssize_t) (tile_image->columns << 1); x++)
1029 (void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelRed(tile_image,p)));
1030 p+=GetPixelChannels(tile_image);
1032 q=GetVirtualPixels(downsample_image,0,y >> 1,downsample_image->columns,
1033 1,&downsample_image->exception);
1034 if (q == (const Quantum *) NULL)
1036 for (x=0; x < (ssize_t) downsample_image->columns; x++)
1038 (void) WriteBlobByte(image,ScaleQuantumToChar(
1039 GetPixelGreen(tile_image,q)));
1042 q=GetVirtualPixels(downsample_image,0,y >> 1,downsample_image->columns,
1043 1,&downsample_image->exception);
1044 if (q == (const Quantum *) NULL)
1046 for (x=0; x < (ssize_t) downsample_image->columns; x++)
1048 (void) WriteBlobByte(image,ScaleQuantumToChar(
1049 GetPixelBlue(tile_image,q)));
1052 status=SetImageProgress(image,SaveImageTag,y,tile_image->rows);
1053 if (status == MagickFalse)
1056 for (i=0; i < 0x800; i++)
1057 (void) WriteBlobByte(image,'\0');
1058 downsample_image=DestroyImage(downsample_image);
1059 tile_image=DestroyImage(tile_image);
1063 static MagickBooleanType WritePCDImage(const ImageInfo *image_info,Image *image)
1074 assert(image_info != (const ImageInfo *) NULL);
1075 assert(image_info->signature == MagickSignature);
1076 assert(image != (Image *) NULL);
1077 assert(image->signature == MagickSignature);
1078 if (image->debug != MagickFalse)
1079 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1081 if (image->columns < image->rows)
1087 Rotate portrait to landscape.
1089 rotate_image=RotateImage(image,90.0,&image->exception);
1090 if (rotate_image == (Image *) NULL)
1091 return(MagickFalse);
1092 pcd_image=rotate_image;
1095 Open output image file.
1097 status=OpenBlob(image_info,pcd_image,WriteBinaryBlobMode,&image->exception);
1098 if (status == MagickFalse)
1100 if (IsRGBColorspace(image->colorspace) == MagickFalse)
1101 (void) TransformImageColorspace(pcd_image,RGBColorspace);
1103 Write PCD image header.
1105 for (i=0; i < 32; i++)
1106 (void) WriteBlobByte(pcd_image,0xff);
1107 for (i=0; i < 4; i++)
1108 (void) WriteBlobByte(pcd_image,0x0e);
1109 for (i=0; i < 8; i++)
1110 (void) WriteBlobByte(pcd_image,'\0');
1111 for (i=0; i < 4; i++)
1112 (void) WriteBlobByte(pcd_image,0x01);
1113 for (i=0; i < 4; i++)
1114 (void) WriteBlobByte(pcd_image,0x05);
1115 for (i=0; i < 8; i++)
1116 (void) WriteBlobByte(pcd_image,'\0');
1117 for (i=0; i < 4; i++)
1118 (void) WriteBlobByte(pcd_image,0x0A);
1119 for (i=0; i < 36; i++)
1120 (void) WriteBlobByte(pcd_image,'\0');
1121 for (i=0; i < 4; i++)
1122 (void) WriteBlobByte(pcd_image,0x01);
1123 for (i=0; i < 1944; i++)
1124 (void) WriteBlobByte(pcd_image,'\0');
1125 (void) WriteBlob(pcd_image,7,(const unsigned char *) "PCD_IPI");
1126 (void) WriteBlobByte(pcd_image,0x06);
1127 for (i=0; i < 1530; i++)
1128 (void) WriteBlobByte(pcd_image,'\0');
1129 if (image->columns < image->rows)
1130 (void) WriteBlobByte(pcd_image,'\1');
1132 (void) WriteBlobByte(pcd_image,'\0');
1133 for (i=0; i < (3*0x800-1539); i++)
1134 (void) WriteBlobByte(pcd_image,'\0');
1138 status=WritePCDTile(pcd_image,"768x512>","192x128");
1139 status=WritePCDTile(pcd_image,"768x512>","384x256");
1140 status=WritePCDTile(pcd_image,"768x512>","768x512");
1141 (void) CloseBlob(pcd_image);
1142 if (pcd_image != image)
1143 pcd_image=DestroyImage(pcd_image);