2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Palm Database ImageViewer Image Format %
20 % Copyright 1999-2015 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % 20071202 TS * rewrote RLE decoder - old version could cause buffer overflows
38 % * failure of RLE decoding now thows error RLEDecoderError
39 % * fixed bug in RLE decoding - now all rows are decoded, not just
41 % * fixed bug in reader - record offsets now handled correctly
42 % * fixed bug in reader - only bits 0..2 indicate compression type
43 % * in writer: now using image color count instead of depth
49 #include "MagickCore/studio.h"
50 #include "MagickCore/attribute.h"
51 #include "MagickCore/blob.h"
52 #include "MagickCore/blob-private.h"
53 #include "MagickCore/cache.h"
54 #include "MagickCore/colormap-private.h"
55 #include "MagickCore/color-private.h"
56 #include "MagickCore/colormap.h"
57 #include "MagickCore/colorspace.h"
58 #include "MagickCore/colorspace-private.h"
59 #include "MagickCore/constitute.h"
60 #include "MagickCore/exception.h"
61 #include "MagickCore/exception-private.h"
62 #include "MagickCore/image.h"
63 #include "MagickCore/image-private.h"
64 #include "MagickCore/list.h"
65 #include "MagickCore/magick.h"
66 #include "MagickCore/memory_.h"
67 #include "MagickCore/monitor.h"
68 #include "MagickCore/monitor-private.h"
69 #include "MagickCore/pixel-accessor.h"
70 #include "MagickCore/property.h"
71 #include "MagickCore/quantum-private.h"
72 #include "MagickCore/quantum-private.h"
73 #include "MagickCore/static.h"
74 #include "MagickCore/string_.h"
75 #include "MagickCore/module.h"
80 typedef struct _PDBInfo
98 type[4], /* database type identifier "vIMG" */
99 id[4]; /* database creator identifier "View" */
109 typedef struct _PDBImage
138 Forward declarations.
140 static MagickBooleanType
141 WritePDBImage(const ImageInfo *,Image *,ExceptionInfo *);
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % D e c o d e I m a g e %
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 % DecodeImage unpacks the packed image pixels into runlength-encoded
157 % The format of the DecodeImage method is:
159 % MagickBooleanType DecodeImage(Image *image,unsigned char *pixels,
160 % const size_t length)
162 % A description of each parameter follows:
164 % o image: the address of a structure of type Image.
166 % o pixels: The address of a byte (8 bits) array of pixel data created by
167 % the decoding process.
169 % o length: Number of bytes to read into buffer 'pixels'.
172 static MagickBooleanType DecodeImage(Image *image, unsigned char *pixels,
175 #define RLE_MODE_NONE -1
176 #define RLE_MODE_COPY 0
177 #define RLE_MODE_RUN 1
179 int data = 0, count = 0;
181 int mode = RLE_MODE_NONE;
183 for (p = pixels; p < pixels + length; p++) {
185 data = ReadBlobByte( image );
186 if (-1 == data) return MagickFalse;
189 count = data - 128 + 1;
190 data = ReadBlobByte( image );
191 if (-1 == data) return MagickFalse;
193 mode = RLE_MODE_COPY;
198 if (RLE_MODE_COPY == mode) {
199 data = ReadBlobByte( image );
200 if (-1 == data) return MagickFalse;
202 *p = (unsigned char)data;
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 % IsPDB() returns MagickTrue if the image format type, identified by the
220 % magick string, is PDB.
222 % The format of the ReadPDBImage method is:
224 % MagickBooleanType IsPDB(const unsigned char *magick,const size_t length)
226 % A description of each parameter follows:
228 % o magick: compare image format pattern against these bytes.
230 % o length: Specifies the length of the magick string.
233 static MagickBooleanType IsPDB(const unsigned char *magick,const size_t length)
237 if (memcmp(magick+60,"vIMGView",8) == 0)
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % R e a d P D B I m a g e %
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % ReadPDBImage() reads an Pilot image file and returns it. It
254 % allocates the memory necessary for the new Image structure and returns a
255 % pointer to the new image.
257 % The format of the ReadPDBImage method is:
259 % Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
261 % A description of each parameter follows:
263 % o image_info: the image info.
265 % o exception: return any errors or warnings in this structure.
268 static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
295 register unsigned char
316 assert(image_info != (const ImageInfo *) NULL);
317 assert(image_info->signature == MagickSignature);
318 if (image_info->debug != MagickFalse)
319 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
320 image_info->filename);
321 assert(exception != (ExceptionInfo *) NULL);
322 assert(exception->signature == MagickSignature);
323 image=AcquireImage(image_info,exception);
324 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
325 if (status == MagickFalse)
327 image=DestroyImageList(image);
328 return((Image *) NULL);
331 Determine if this a PDB image file.
333 count=ReadBlob(image,32,(unsigned char *) pdb_info.name);
334 pdb_info.attributes=(short) ReadBlobMSBShort(image);
335 pdb_info.version=(short) ReadBlobMSBShort(image);
336 pdb_info.create_time=ReadBlobMSBLong(image);
337 pdb_info.modify_time=ReadBlobMSBLong(image);
338 pdb_info.archive_time=ReadBlobMSBLong(image);
339 pdb_info.modify_number=ReadBlobMSBLong(image);
340 pdb_info.application_info=ReadBlobMSBLong(image);
341 pdb_info.sort_info=ReadBlobMSBLong(image);
342 count=ReadBlob(image,4,(unsigned char *) pdb_info.type);
343 count=ReadBlob(image,4,(unsigned char *) pdb_info.id);
344 if ((count == 0) || (memcmp(pdb_info.type,"vIMG",4) != 0) ||
345 (memcmp(pdb_info.id,"View",4) != 0))
346 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
347 pdb_info.seed=ReadBlobMSBLong(image);
348 pdb_info.next_record=ReadBlobMSBLong(image);
349 pdb_info.number_records=(short) ReadBlobMSBShort(image);
350 if (pdb_info.next_record != 0)
351 ThrowReaderException(CoderError,"MultipleRecordListNotSupported");
355 img_offset=(ssize_t) ((int) ReadBlobMSBLong(image));
356 attributes=(unsigned char) ReadBlobByte(image);
358 count=ReadBlob(image,3,(unsigned char *) tag);
359 if (count != 3 || memcmp(tag,"\x6f\x80\x00",3) != 0)
360 ThrowReaderException(CorruptImageError,"CorruptImage");
361 if (pdb_info.number_records > 1)
363 comment_offset=(ssize_t) ((int) ReadBlobMSBLong(image));
364 attributes=(unsigned char) ReadBlobByte(image);
365 count=ReadBlob(image,3,(unsigned char *) tag);
366 if (count != 3 || memcmp(tag,"\x6f\x80\x01",3) != 0)
367 ThrowReaderException(CorruptImageError,"CorruptImage");
369 num_pad_bytes = (size_t) (img_offset - TellBlob( image ));
370 while (num_pad_bytes--) ReadBlobByte( image );
374 count=ReadBlob(image,32,(unsigned char *) pdb_image.name);
375 pdb_image.version=ReadBlobByte(image);
376 pdb_image.type=(unsigned char) ((int) ReadBlobByte(image));
377 pdb_image.reserved_1=ReadBlobMSBLong(image);
378 pdb_image.note=ReadBlobMSBLong(image);
379 pdb_image.x_last=(short) ReadBlobMSBShort(image);
380 pdb_image.y_last=(short) ReadBlobMSBShort(image);
381 pdb_image.reserved_2=ReadBlobMSBLong(image);
382 pdb_image.x_anchor=ReadBlobMSBShort(image);
383 pdb_image.y_anchor=ReadBlobMSBShort(image);
384 pdb_image.width=(short) ReadBlobMSBShort(image);
385 pdb_image.height=(short) ReadBlobMSBShort(image);
387 Initialize image structure.
389 image->columns=(size_t) pdb_image.width;
390 image->rows=(size_t) pdb_image.height;
392 status=SetImageExtent(image,image->columns,image->rows,exception);
393 if (status == MagickFalse)
394 return(DestroyImageList(image));
395 image->storage_class=PseudoClass;
396 bits_per_pixel=pdb_image.type == 0 ? 2UL : pdb_image.type == 2 ? 4UL : 1UL;
398 if (AcquireImageColormap(image,one << bits_per_pixel,exception) == MagickFalse)
399 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
400 if (image_info->ping != MagickFalse)
402 (void) CloseBlob(image);
403 return(GetFirstImageInList(image));
405 packets=(bits_per_pixel*image->columns+7)/8;
406 pixels=(unsigned char *) AcquireQuantumMemory(packets+256UL,image->rows*
408 if (pixels == (unsigned char *) NULL)
409 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
410 switch (pdb_image.version & 0x07)
414 image->compression=NoCompression;
415 count=(ssize_t) ReadBlob(image, packets * image -> rows, pixels);
420 image->compression=RLECompression;
421 if (!DecodeImage(image, pixels, packets * image -> rows))
422 ThrowReaderException( CorruptImageError, "RLEDecoderError" );
426 ThrowReaderException(CorruptImageError,
427 "UnrecognizedImageCompressionType" );
430 switch (bits_per_pixel)
438 Read 1-bit PDB image.
440 for (y=0; y < (ssize_t) image->rows; y++)
442 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
443 if (q == (Quantum *) NULL)
445 for (x=0; x < ((ssize_t) image->columns-7); x+=8)
447 for (bit=0; bit < 8; bit++)
449 index=(Quantum) (*p & (0x80 >> bit) ? 0x00 : 0x01);
450 SetPixelIndex(image,index,q);
451 q+=GetPixelChannels(image);
455 if (SyncAuthenticPixels(image,exception) == MagickFalse)
457 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
459 if (status == MagickFalse)
462 (void) SyncImage(image,exception);
468 Read 2-bit PDB image.
470 for (y=0; y < (ssize_t) image->rows; y++)
472 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
473 if (q == (Quantum *) NULL)
475 for (x=0; x < (ssize_t) image->columns; x+=4)
477 index=ConstrainColormapIndex(image,3UL-((*p >> 6) & 0x03),exception);
478 SetPixelIndex(image,index,q);
479 q+=GetPixelChannels(image);
480 index=ConstrainColormapIndex(image,3UL-((*p >> 4) & 0x03),exception);
481 SetPixelIndex(image,index,q);
482 q+=GetPixelChannels(image);
483 index=ConstrainColormapIndex(image,3UL-((*p >> 2) & 0x03),exception);
484 SetPixelIndex(image,index,q);
485 q+=GetPixelChannels(image);
486 index=ConstrainColormapIndex(image,3UL-((*p) & 0x03),exception);
487 SetPixelIndex(image,index,q);
489 q+=GetPixelChannels(image);
491 if (SyncAuthenticPixels(image,exception) == MagickFalse)
493 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
495 if (status == MagickFalse)
498 (void) SyncImage(image,exception);
504 Read 4-bit PDB image.
506 for (y=0; y < (ssize_t) image->rows; y++)
508 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
509 if (q == (Quantum *) NULL)
511 for (x=0; x < (ssize_t) image->columns; x+=2)
513 index=ConstrainColormapIndex(image,15UL-((*p >> 4) & 0x0f),exception);
514 SetPixelIndex(image,index,q);
515 q+=GetPixelChannels(image);
516 index=ConstrainColormapIndex(image,15UL-((*p) & 0x0f),exception);
517 SetPixelIndex(image,index,q);
519 q+=GetPixelChannels(image);
521 if (SyncAuthenticPixels(image,exception) == MagickFalse)
523 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
525 if (status == MagickFalse)
528 (void) SyncImage(image,exception);
532 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
534 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
535 if (EOFBlob(image) != MagickFalse)
536 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
538 if (pdb_info.number_records > 1)
552 num_pad_bytes = (size_t) (comment_offset - TellBlob( image ));
553 while (num_pad_bytes--) ReadBlobByte( image );
558 c=ReadBlobByte(image);
559 length=MaxTextExtent;
560 comment=AcquireString((char *) NULL);
561 for (p=comment; c != EOF; p++)
563 if ((size_t) (p-comment+MaxTextExtent) >= length)
567 length+=MaxTextExtent;
568 comment=(char *) ResizeQuantumMemory(comment,length+MaxTextExtent,
570 if (comment == (char *) NULL)
572 p=comment+strlen(comment);
575 c=ReadBlobByte(image);
578 if (comment == (char *) NULL)
579 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
580 (void) SetImageProperty(image,"comment",comment,exception);
581 comment=DestroyString(comment);
583 (void) CloseBlob(image);
584 return(GetFirstImageInList(image));
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
592 % R e g i s t e r P D B I m a g e %
596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598 % RegisterPDBImage() adds properties for the PDB image format to
599 % the list of supported formats. The properties include the image format
600 % tag, a method to read and/or write the format, whether the format
601 % supports the saving of more than one frame to the same file or blob,
602 % whether the format supports native in-memory I/O, and a brief
603 % description of the format.
605 % The format of the RegisterPDBImage method is:
607 % size_t RegisterPDBImage(void)
610 ModuleExport size_t RegisterPDBImage(void)
615 entry=SetMagickInfo("PDB");
616 entry->decoder=(DecodeImageHandler *) ReadPDBImage;
617 entry->encoder=(EncodeImageHandler *) WritePDBImage;
618 entry->magick=(IsImageFormatHandler *) IsPDB;
619 entry->description=ConstantString("Palm Database ImageViewer Format");
620 entry->module=ConstantString("PDB");
621 (void) RegisterMagickInfo(entry);
622 return(MagickImageCoderSignature);
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 % U n r e g i s t e r P D B I m a g e %
634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636 % UnregisterPDBImage() removes format registrations made by the
637 % PDB module from the list of supported formats.
639 % The format of the UnregisterPDBImage method is:
641 % UnregisterPDBImage(void)
644 ModuleExport void UnregisterPDBImage(void)
646 (void) UnregisterMagickInfo("PDB");
650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % W r i t e P D B I m a g e %
658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660 % WritePDBImage() writes an image
662 % The format of the WritePDBImage method is:
664 % MagickBooleanType WritePDBImage(const ImageInfo *image_info,
665 % Image *image,ExceptionInfo *exception)
667 % A description of each parameter follows.
669 % o image_info: the image info.
671 % o image: The image.
673 % o exception: return any errors or warnings in this structure.
677 static unsigned char *EncodeRLE(unsigned char *destination,
678 unsigned char *source,size_t literal,size_t repeat)
681 *destination++=(unsigned char) (literal-1);
682 (void) CopyMagickMemory(destination,source,literal);
683 destination+=literal;
686 *destination++=(unsigned char) (0x80 | (repeat-1));
687 *destination++=source[literal];
692 static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
693 ExceptionInfo *exception)
713 register const Quantum
719 register unsigned char
738 Open output image file.
740 assert(image_info != (const ImageInfo *) NULL);
741 assert(image_info->signature == MagickSignature);
742 assert(image != (Image *) NULL);
743 assert(image->signature == MagickSignature);
744 if (image->debug != MagickFalse)
745 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
746 assert(exception != (ExceptionInfo *) NULL);
747 assert(exception->signature == MagickSignature);
748 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
749 if (status == MagickFalse)
751 (void) TransformImageColorspace(image,sRGBColorspace,exception);
752 if ((image->colors <= 2) ||
753 (GetImageType(image,exception ) == BilevelType)) {
755 } else if (image->colors <= 4) {
757 } else if (image->colors <= 8) {
762 (void) ResetMagickMemory(pdb_info.name,0,32);
763 (void) CopyMagickString(pdb_info.name,image_info->filename,32);
764 pdb_info.attributes=0;
766 pdb_info.create_time=time(NULL);
767 pdb_info.modify_time=pdb_info.create_time;
768 pdb_info.archive_time=0;
769 pdb_info.modify_number=0;
770 pdb_info.application_info=0;
771 pdb_info.sort_info=0;
772 (void) CopyMagickMemory(pdb_info.type,"vIMG",4);
773 (void) CopyMagickMemory(pdb_info.id,"View",4);
775 pdb_info.next_record=0;
776 comment=GetImageProperty(image,"comment",exception);
777 pdb_info.number_records=(comment == (const char *) NULL ? 1 : 2);
778 (void) WriteBlob(image,32,(unsigned char *) pdb_info.name);
779 (void) WriteBlobMSBShort(image,(unsigned short) pdb_info.attributes);
780 (void) WriteBlobMSBShort(image,(unsigned short) pdb_info.version);
781 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.create_time);
782 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_time);
783 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.archive_time);
784 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_number);
785 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.application_info);
786 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.sort_info);
787 (void) WriteBlob(image,4,(unsigned char *) pdb_info.type);
788 (void) WriteBlob(image,4,(unsigned char *) pdb_info.id);
789 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.seed);
790 (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.next_record);
791 (void) WriteBlobMSBShort(image,(unsigned short) pdb_info.number_records);
792 (void) CopyMagickString(pdb_image.name,pdb_info.name,32);
793 pdb_image.version=1; /* RLE Compressed */
794 switch (bits_per_pixel)
796 case 1: pdb_image.type=(unsigned char) 0xff; break; /* monochrome */
797 case 2: pdb_image.type=(unsigned char) 0x00; break; /* 2 bit gray */
798 default: pdb_image.type=(unsigned char) 0x02; /* 4 bit gray */
800 pdb_image.reserved_1=0;
804 pdb_image.reserved_2=0;
805 pdb_image.x_anchor=(unsigned short) 0xffff;
806 pdb_image.y_anchor=(unsigned short) 0xffff;
807 pdb_image.width=(short) image->columns;
808 if (image->columns % 16)
809 pdb_image.width=(short) (16*(image->columns/16+1));
810 pdb_image.height=(short) image->rows;
811 packets=((bits_per_pixel*image->columns+7)/8)*image->rows;
812 runlength=(unsigned char *) AcquireQuantumMemory(2UL*packets,
814 if (runlength == (unsigned char *) NULL)
815 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
816 buffer=(unsigned char *) AcquireQuantumMemory(256UL,sizeof(*buffer));
817 if (buffer == (unsigned char *) NULL)
818 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
819 packet_size=(size_t) (image->depth > 8 ? 2: 1);
820 scanline=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
822 if (scanline == (unsigned char *) NULL)
823 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
824 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
825 (void) TransformImageColorspace(image,sRGBColorspace,exception);
827 Convert to GRAY raster scanline.
829 quantum_info=AcquireQuantumInfo(image_info,image);
830 if (quantum_info == (QuantumInfo *) NULL)
831 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
832 bits=8/(int) bits_per_pixel-1; /* start at most significant bits */
837 for (y=0; y < (ssize_t) image->rows; y++)
839 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
840 if (p == (const Quantum *) NULL)
842 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
843 GrayQuantum,scanline,exception);
844 for (x=0; x < (ssize_t) pdb_image.width; x++)
846 if (x < (ssize_t) image->columns)
847 buffer[literal+repeat]|=(0xff-scanline[x*packet_size]) >>
848 (8-bits_per_pixel) << bits*bits_per_pixel;
852 if (((literal+repeat) > 0) &&
853 (buffer[literal+repeat] == buffer[literal+repeat-1]))
863 q=EncodeRLE(q,buffer,literal,repeat);
874 q=EncodeRLE(q,buffer,literal,repeat);
875 buffer[0]=buffer[literal+repeat];
882 q=EncodeRLE(q,buffer,(literal < 0x80 ? literal : 0x80),0);
883 (void) CopyMagickMemory(buffer,buffer+literal+repeat,0x80);
887 bits=8/(int) bits_per_pixel-1;
888 buffer[literal+repeat]=0x00;
891 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
893 if (status == MagickFalse)
896 q=EncodeRLE(q,buffer,literal,repeat);
897 scanline=(unsigned char *) RelinquishMagickMemory(scanline);
898 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
899 quantum_info=DestroyQuantumInfo(quantum_info);
901 Write the Image record header.
903 (void) WriteBlobMSBLong(image,(unsigned int)
904 (TellBlob(image)+8*pdb_info.number_records));
905 (void) WriteBlobByte(image,0x40);
906 (void) WriteBlobByte(image,0x6f);
907 (void) WriteBlobByte(image,0x80);
908 (void) WriteBlobByte(image,0);
909 if (pdb_info.number_records > 1)
912 Write the comment record header.
914 (void) WriteBlobMSBLong(image,(unsigned int) (TellBlob(image)+8+58+q-
916 (void) WriteBlobByte(image,0x40);
917 (void) WriteBlobByte(image,0x6f);
918 (void) WriteBlobByte(image,0x80);
919 (void) WriteBlobByte(image,1);
922 Write the Image data.
924 (void) WriteBlob(image,32,(unsigned char *) pdb_image.name);
925 (void) WriteBlobByte(image,(unsigned char) pdb_image.version);
926 (void) WriteBlobByte(image,pdb_image.type);
927 (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_1);
928 (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.note);
929 (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_last);
930 (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_last);
931 (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_2);
932 (void) WriteBlobMSBShort(image,pdb_image.x_anchor);
933 (void) WriteBlobMSBShort(image,pdb_image.y_anchor);
934 (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.width);
935 (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.height);
936 (void) WriteBlob(image,(size_t) (q-runlength),runlength);
937 runlength=(unsigned char *) RelinquishMagickMemory(runlength);
938 if (pdb_info.number_records > 1)
939 (void) WriteBlobString(image,comment);
940 (void) CloseBlob(image);