2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Sun Rasterfile 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/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colormap.h"
50 #include "MagickCore/colorspace.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/image.h"
54 #include "MagickCore/image-private.h"
55 #include "MagickCore/list.h"
56 #include "MagickCore/magick.h"
57 #include "MagickCore/memory_.h"
58 #include "MagickCore/monitor.h"
59 #include "MagickCore/monitor-private.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/quantum-private.h"
62 #include "MagickCore/static.h"
63 #include "MagickCore/string_.h"
64 #include "MagickCore/module.h"
69 static MagickBooleanType
70 WriteSUNImage(const ImageInfo *,Image *);
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 % IsSUN() returns MagickTrue if the image format type, identified by the
84 % magick string, is SUN.
86 % The format of the IsSUN method is:
88 % MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
90 % A description of each parameter follows:
92 % o magick: compare image format pattern against these bytes.
94 % o length: Specifies the length of the magick string.
97 static MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
101 if (memcmp(magick,"\131\246\152\225",4) == 0)
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 % D e c o d e I m a g e %
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 % DecodeImage unpacks the packed image pixels into runlength-encoded pixel
120 % The format of the DecodeImage method is:
122 % MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
123 % const size_t length,unsigned char *pixels)
125 % A description of each parameter follows:
127 % o compressed_pixels: The address of a byte (8 bits) array of compressed
130 % o length: An integer value that is the total number of bytes of the
131 % source image (as just read by ReadBlob)
133 % o pixels: The address of a byte (8 bits) array of pixel data created by
134 % the uncompression process. The number of bytes in this array
135 % must be at least equal to the number columns times the number of rows
136 % of the source pixels.
139 static MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
140 const size_t length,unsigned char *pixels,size_t maxpixels)
142 register const unsigned char
146 register unsigned char
155 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
156 assert(compressed_pixels != (unsigned char *) NULL);
157 assert(pixels != (unsigned char *) NULL);
161 while (((size_t) (p-compressed_pixels) < length) && (q < l))
169 Runlength-encoded packet: <count><byte>
171 count=(ssize_t) (*p++);
174 while ((count >= 0) && (q < l))
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 % R e a d S U N I m a g e %
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 % ReadSUNImage() reads a SUN image file and returns it. It allocates
196 % the memory necessary for the new Image structure and returns a pointer to
199 % The format of the ReadSUNImage method is:
201 % Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
203 % A description of each parameter follows:
205 % o image_info: the image info.
207 % o exception: return any errors or warnings in this structure.
210 static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
212 #define RMT_EQUAL_RGB 1
215 #define RT_STANDARD 1
217 #define RT_FORMAT_RGB 3
219 typedef struct _SUNInfo
251 register unsigned char
274 assert(image_info != (const ImageInfo *) NULL);
275 assert(image_info->signature == MagickSignature);
276 if (image_info->debug != MagickFalse)
277 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
278 image_info->filename);
279 assert(exception != (ExceptionInfo *) NULL);
280 assert(exception->signature == MagickSignature);
281 image=AcquireImage(image_info);
282 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
283 if (status == MagickFalse)
285 image=DestroyImageList(image);
286 return((Image *) NULL);
289 Read SUN raster header.
291 (void) ResetMagickMemory(&sun_info,0,sizeof(sun_info));
292 sun_info.magic=ReadBlobMSBLong(image);
296 Verify SUN identifier.
298 if (sun_info.magic != 0x59a66a95)
299 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
300 sun_info.width=ReadBlobMSBLong(image);
301 sun_info.height=ReadBlobMSBLong(image);
302 sun_info.depth=ReadBlobMSBLong(image);
303 sun_info.length=ReadBlobMSBLong(image);
304 sun_info.type=ReadBlobMSBLong(image);
305 sun_info.maptype=ReadBlobMSBLong(image);
306 sun_info.maplength=ReadBlobMSBLong(image);
307 image->columns=sun_info.width;
308 image->rows=sun_info.height;
309 if ((sun_info.depth == 0) || (sun_info.depth > 32))
310 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
311 image->depth=sun_info.depth <= 8 ? sun_info.depth :
312 MAGICKCORE_QUANTUM_DEPTH;
313 if (sun_info.depth < 24)
318 image->storage_class=PseudoClass;
319 image->colors=sun_info.maplength;
321 if (sun_info.maptype == RMT_NONE)
322 image->colors=one << sun_info.depth;
323 if (sun_info.maptype == RMT_EQUAL_RGB)
324 image->colors=sun_info.maplength/3;
326 switch (sun_info.maptype)
330 if (sun_info.depth < 24)
333 Create linear color ramp.
335 if (AcquireImageColormap(image,image->colors) == MagickFalse)
336 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
346 Read SUN raster colormap.
348 if (AcquireImageColormap(image,image->colors) == MagickFalse)
349 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
350 sun_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
351 sizeof(*sun_colormap));
352 if (sun_colormap == (unsigned char *) NULL)
353 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
354 count=ReadBlob(image,image->colors,sun_colormap);
355 for (i=0; i < (ssize_t) image->colors; i++)
356 image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);
357 count=ReadBlob(image,image->colors,sun_colormap);
358 for (i=0; i < (ssize_t) image->colors; i++)
359 image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);
360 count=ReadBlob(image,image->colors,sun_colormap);
361 for (i=0; i < (ssize_t) image->colors; i++)
362 image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);
363 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
372 Read SUN raster colormap.
374 sun_colormap=(unsigned char *) AcquireQuantumMemory(sun_info.maplength,
375 sizeof(*sun_colormap));
376 if (sun_colormap == (unsigned char *) NULL)
377 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
378 count=ReadBlob(image,sun_info.maplength,sun_colormap);
379 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
383 ThrowReaderException(CoderError,"ColormapTypeNotSupported");
385 image->matte=sun_info.depth == 32 ? MagickTrue : MagickFalse;
386 image->columns=sun_info.width;
387 image->rows=sun_info.height;
388 if (image_info->ping != MagickFalse)
390 (void) CloseBlob(image);
391 return(GetFirstImageInList(image));
393 if ((sun_info.length*sizeof(*sun_data))/sizeof(*sun_data) !=
394 sun_info.length || !sun_info.length)
395 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
396 number_pixels=(MagickSizeType) image->columns*image->rows;
397 if ((sun_info.depth >= 8) &&
398 ((number_pixels*((sun_info.depth+7)/8)) > sun_info.length))
399 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
400 sun_data=(unsigned char *) AcquireQuantumMemory((size_t) sun_info.length,
402 if (sun_data == (unsigned char *) NULL)
403 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
404 count=(ssize_t) ReadBlob(image,sun_info.length,sun_data);
405 if ((count == 0) && (sun_info.type != RT_ENCODED))
406 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
409 if (sun_info.type == RT_ENCODED)
415 Read run-length encoded raster pixels.
417 height=sun_info.height;
418 bytes_per_line=sun_info.width*sun_info.depth;
419 if ((height == 0) || (sun_info.width == 0) || (sun_info.depth == 0) ||
420 ((bytes_per_line/sun_info.depth) != sun_info.width))
421 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
424 if ((bytes_per_line >> 1) != (sun_info.width*sun_info.depth+15))
425 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
427 sun_pixels=(unsigned char *) AcquireQuantumMemory(height,
428 bytes_per_line*sizeof(*sun_pixels));
429 if (sun_pixels == (unsigned char *) NULL)
430 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
431 (void) DecodeImage(sun_data,sun_info.length,sun_pixels,
432 bytes_per_line*height);
433 sun_data=(unsigned char *) RelinquishMagickMemory(sun_data);
436 Convert SUN raster image to pixel packets.
439 if (sun_info.depth == 1)
440 for (y=0; y < (ssize_t) image->rows; y++)
442 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
443 if (q == (const Quantum *) NULL)
445 for (x=0; x < ((ssize_t) image->columns-7); x+=8)
447 for (bit=7; bit >= 0; bit--)
449 SetPixelIndex(image,((*p) & (0x01 << bit) ? 0x00 : 0x01),q);
450 q+=GetPixelChannels(image);
454 if ((image->columns % 8) != 0)
456 for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--)
458 SetPixelIndex(image,(*p) & (0x01 << bit) ? 0x00 : 0x01,q);
459 q+=GetPixelChannels(image);
463 if ((((image->columns/8)+(image->columns % 8 ? 1 : 0)) % 2) != 0)
465 if (SyncAuthenticPixels(image,exception) == MagickFalse)
467 if (image->previous == (Image *) NULL)
469 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
471 if (status == MagickFalse)
476 if (image->storage_class == PseudoClass)
478 length=image->rows*(image->columns+image->columns % 2);
479 if (((sun_info.type == RT_ENCODED) &&
480 (length > (bytes_per_line*image->rows))) ||
481 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
482 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
483 for (y=0; y < (ssize_t) image->rows; y++)
485 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
486 if (q == (const Quantum *) NULL)
488 for (x=0; x < (ssize_t) image->columns; x++)
490 SetPixelIndex(image,*p++,q);
491 q+=GetPixelChannels(image);
493 if ((image->columns % 2) != 0)
495 if (SyncAuthenticPixels(image,exception) == MagickFalse)
497 if (image->previous == (Image *) NULL)
499 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
501 if (status == MagickFalse)
512 if (image->matte != MagickFalse)
514 length=image->rows*((bytes_per_line*image->columns)+
516 if (((sun_info.type == RT_ENCODED) &&
517 (length > (bytes_per_line*image->rows))) ||
518 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
519 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
520 for (y=0; y < (ssize_t) image->rows; y++)
522 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
523 if (q == (const Quantum *) NULL)
525 for (x=0; x < (ssize_t) image->columns; x++)
527 if (image->matte != MagickFalse)
528 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
529 if (sun_info.type == RT_STANDARD)
531 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
532 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
533 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
537 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
538 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
539 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
541 if (image->colors != 0)
543 SetPixelRed(image,image->colormap[(ssize_t)
544 GetPixelRed(image,q)].red,q);
545 SetPixelGreen(image,image->colormap[(ssize_t)
546 GetPixelGreen(image,q)].green,q);
547 SetPixelBlue(image,image->colormap[(ssize_t)
548 GetPixelBlue(image,q)].blue,q);
550 q+=GetPixelChannels(image);
552 if (((bytes_per_pixel*image->columns) % 2) != 0)
554 if (SyncAuthenticPixels(image,exception) == MagickFalse)
556 if (image->previous == (Image *) NULL)
558 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
560 if (status == MagickFalse)
565 if (image->storage_class == PseudoClass)
566 (void) SyncImage(image);
567 sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
568 if (EOFBlob(image) != MagickFalse)
570 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
575 Proceed to next image.
577 if (image_info->number_scenes != 0)
578 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
580 sun_info.magic=ReadBlobMSBLong(image);
581 if (sun_info.magic == 0x59a66a95)
584 Allocate next image structure.
586 AcquireNextImage(image_info,image);
587 if (GetNextImageInList(image) == (Image *) NULL)
589 image=DestroyImageList(image);
590 return((Image *) NULL);
592 image=SyncNextImageInList(image);
593 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
595 if (status == MagickFalse)
598 } while (sun_info.magic == 0x59a66a95);
599 (void) CloseBlob(image);
600 return(GetFirstImageInList(image));
604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608 % R e g i s t e r S U N I m a g e %
612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614 % RegisterSUNImage() adds attributes for the SUN image format to
615 % the list of supported formats. The attributes include the image format
616 % tag, a method to read and/or write the format, whether the format
617 % supports the saving of more than one frame to the same file or blob,
618 % whether the format supports native in-memory I/O, and a brief
619 % description of the format.
621 % The format of the RegisterSUNImage method is:
623 % size_t RegisterSUNImage(void)
626 ModuleExport size_t RegisterSUNImage(void)
631 entry=SetMagickInfo("RAS");
632 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
633 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
634 entry->magick=(IsImageFormatHandler *) IsSUN;
635 entry->description=ConstantString("SUN Rasterfile");
636 entry->module=ConstantString("SUN");
637 (void) RegisterMagickInfo(entry);
638 entry=SetMagickInfo("SUN");
639 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
640 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
641 entry->description=ConstantString("SUN Rasterfile");
642 entry->module=ConstantString("SUN");
643 (void) RegisterMagickInfo(entry);
644 return(MagickImageCoderSignature);
648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 % U n r e g i s t e r S U N I m a g e %
656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658 % UnregisterSUNImage() removes format registrations made by the
659 % SUN module from the list of supported formats.
661 % The format of the UnregisterSUNImage method is:
663 % UnregisterSUNImage(void)
666 ModuleExport void UnregisterSUNImage(void)
668 (void) UnregisterMagickInfo("RAS");
669 (void) UnregisterMagickInfo("SUN");
673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677 % W r i t e S U N I m a g e %
681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683 % WriteSUNImage() writes an image in the SUN rasterfile format.
685 % The format of the WriteSUNImage method is:
687 % MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
689 % A description of each parameter follows.
691 % o image_info: the image info.
693 % o image: The image.
696 static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
698 #define RMT_EQUAL_RGB 1
701 #define RT_STANDARD 1
702 #define RT_FORMAT_RGB 3
704 typedef struct _SUNInfo
726 register const Quantum
740 Open output image file.
742 assert(image_info != (const ImageInfo *) NULL);
743 assert(image_info->signature == MagickSignature);
744 assert(image != (Image *) NULL);
745 assert(image->signature == MagickSignature);
746 if (image->debug != MagickFalse)
747 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
748 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
749 if (status == MagickFalse)
755 Initialize SUN raster file header.
757 if (image->colorspace != RGBColorspace)
758 (void) TransformImageColorspace(image,RGBColorspace);
759 sun_info.magic=0x59a66a95;
760 if ((image->columns != (unsigned int) image->columns) ||
761 (image->rows != (unsigned int) image->rows))
762 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
763 sun_info.width=(unsigned int) image->columns;
764 sun_info.height=(unsigned int) image->rows;
765 sun_info.type=(unsigned int)
766 (image->storage_class == DirectClass ? RT_FORMAT_RGB : RT_STANDARD);
767 sun_info.maptype=RMT_NONE;
768 sun_info.maplength=0;
769 number_pixels=(MagickSizeType) image->columns*image->rows;
770 if ((4*number_pixels) != (size_t) (4*number_pixels))
771 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
772 if (image->storage_class == DirectClass)
775 Full color SUN raster.
777 sun_info.depth=(unsigned int) image->matte ? 32U : 24U;
778 sun_info.length=(unsigned int) ((image->matte ? 4 : 3)*number_pixels);
779 sun_info.length+=sun_info.length & 0x01 ? (unsigned int) image->rows :
783 if (IsImageMonochrome(image,&image->exception))
786 Monochrome SUN raster.
789 sun_info.length=(unsigned int) (((image->columns+7) >> 3)*
791 sun_info.length+=(unsigned int) (((image->columns/8)+(image->columns %
792 8 ? 1 : 0)) % 2 ? image->rows : 0);
797 Colormapped SUN raster.
800 sun_info.length=(unsigned int) number_pixels;
801 sun_info.length+=(unsigned int) (image->columns & 0x01 ? image->rows :
803 sun_info.maptype=RMT_EQUAL_RGB;
804 sun_info.maplength=(unsigned int) (3*image->colors);
809 (void) WriteBlobMSBLong(image,sun_info.magic);
810 (void) WriteBlobMSBLong(image,sun_info.width);
811 (void) WriteBlobMSBLong(image,sun_info.height);
812 (void) WriteBlobMSBLong(image,sun_info.depth);
813 (void) WriteBlobMSBLong(image,sun_info.length);
814 (void) WriteBlobMSBLong(image,sun_info.type);
815 (void) WriteBlobMSBLong(image,sun_info.maptype);
816 (void) WriteBlobMSBLong(image,sun_info.maplength);
818 Convert MIFF to SUN raster pixels.
822 if (image->storage_class == DirectClass)
824 register unsigned char
835 Allocate memory for pixels.
838 if (image->matte != MagickFalse)
840 length=image->columns;
841 pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels));
842 if (pixels == (unsigned char *) NULL)
843 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
845 Convert DirectClass packet to SUN RGB pixel.
847 for (y=0; y < (ssize_t) image->rows; y++)
849 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
850 if (p == (const Quantum *) NULL)
853 for (x=0; x < (ssize_t) image->columns; x++)
855 if (image->matte != MagickFalse)
856 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
857 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
858 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
859 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
860 p+=GetPixelChannels(image);
862 if (((bytes_per_pixel*image->columns) & 0x01) != 0)
863 *q++='\0'; /* pad scanline */
864 (void) WriteBlob(image,(size_t) (q-pixels),pixels);
865 if (image->previous == (Image *) NULL)
867 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
869 if (status == MagickFalse)
873 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
876 if (IsImageMonochrome(image,&image->exception))
878 register unsigned char
883 Convert PseudoClass image to a SUN monochrome image.
885 (void) SetImageType(image,BilevelType);
886 for (y=0; y < (ssize_t) image->rows; y++)
888 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
889 if (p == (const Quantum *) NULL)
893 for (x=0; x < (ssize_t) image->columns; x++)
896 if (GetPixelIntensity(image,p) < (MagickRealType) (QuantumRange/2.0))
901 (void) WriteBlobByte(image,byte);
905 p+=GetPixelChannels(image);
908 (void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
909 if ((((image->columns/8)+
910 (image->columns % 8 ? 1 : 0)) % 2) != 0)
911 (void) WriteBlobByte(image,0); /* pad scanline */
912 if (image->previous == (Image *) NULL)
914 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
916 if (status == MagickFalse)
924 Dump colormap to file.
926 for (i=0; i < (ssize_t) image->colors; i++)
927 (void) WriteBlobByte(image,ScaleQuantumToChar(
928 image->colormap[i].red));
929 for (i=0; i < (ssize_t) image->colors; i++)
930 (void) WriteBlobByte(image,ScaleQuantumToChar(
931 image->colormap[i].green));
932 for (i=0; i < (ssize_t) image->colors; i++)
933 (void) WriteBlobByte(image,ScaleQuantumToChar(
934 image->colormap[i].blue));
936 Convert PseudoClass packet to SUN colormapped pixel.
938 for (y=0; y < (ssize_t) image->rows; y++)
940 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
941 if (p == (const Quantum *) NULL)
943 for (x=0; x < (ssize_t) image->columns; x++)
945 (void) WriteBlobByte(image,(unsigned char)
946 GetPixelIndex(image,p));
947 p+=GetPixelChannels(image);
949 if (image->columns & 0x01)
950 (void) WriteBlobByte(image,0); /* pad scanline */
951 if (image->previous == (Image *) NULL)
953 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
955 if (status == MagickFalse)
960 if (GetNextImageInList(image) == (Image *) NULL)
962 image=SyncNextImageInList(image);
963 status=SetImageProgress(image,SaveImagesTag,scene++,
964 GetImageListLength(image));
965 if (status == MagickFalse)
967 } while (image_info->adjoin != MagickFalse);
968 (void) CloseBlob(image);