2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Sun Rasterfile Image 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/colormap.h"
49 #include "magick/colorspace.h"
50 #include "magick/exception.h"
51 #include "magick/exception-private.h"
52 #include "magick/image.h"
53 #include "magick/image-private.h"
54 #include "magick/list.h"
55 #include "magick/magick.h"
56 #include "magick/memory_.h"
57 #include "magick/monitor.h"
58 #include "magick/monitor-private.h"
59 #include "magick/quantum-private.h"
60 #include "magick/static.h"
61 #include "magick/string_.h"
62 #include "magick/module.h"
67 static MagickBooleanType
68 WriteSUNImage(const ImageInfo *,Image *);
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % IsSUN() returns MagickTrue if the image format type, identified by the
82 % magick string, is SUN.
84 % The format of the IsSUN method is:
86 % MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
88 % A description of each parameter follows:
90 % o magick: compare image format pattern against these bytes.
92 % o length: Specifies the length of the magick string.
95 static MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
99 if (memcmp(magick,"\131\246\152\225",4) == 0)
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 % D e c o d e I m a g e %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % DecodeImage unpacks the packed image pixels into runlength-encoded pixel
118 % The format of the DecodeImage method is:
120 % MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
121 % const size_t length,unsigned char *pixels)
123 % A description of each parameter follows:
125 % o compressed_pixels: The address of a byte (8 bits) array of compressed
128 % o length: An integer value that is the total number of bytes of the
129 % source image (as just read by ReadBlob)
131 % o pixels: The address of a byte (8 bits) array of pixel data created by
132 % the uncompression process. The number of bytes in this array
133 % must be at least equal to the number columns times the number of rows
134 % of the source pixels.
137 static MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
138 const size_t length,unsigned char *pixels,size_t maxpixels)
140 register const unsigned char
143 register unsigned char
152 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
153 assert(compressed_pixels != (unsigned char *) NULL);
154 assert(pixels != (unsigned char *) NULL);
158 while (((size_t) (p-compressed_pixels) < length) && (q < l))
166 Runlength-encoded packet: <count><byte>
168 count=(ssize_t) (*p++);
171 while ((count >= 0) && (q < l))
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 % R e a d S U N I m a g e %
190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 % ReadSUNImage() reads a SUN image file and returns it. It allocates
193 % the memory necessary for the new Image structure and returns a pointer to
196 % The format of the ReadSUNImage method is:
198 % Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
200 % A description of each parameter follows:
202 % o image_info: the image info.
204 % o exception: return any errors or warnings in this structure.
207 static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
209 #define RMT_EQUAL_RGB 1
212 #define RT_STANDARD 1
214 #define RT_FORMAT_RGB 3
216 typedef struct _SUNInfo
256 register unsigned char
278 assert(image_info != (const ImageInfo *) NULL);
279 assert(image_info->signature == MagickSignature);
280 if (image_info->debug != MagickFalse)
281 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
282 image_info->filename);
283 assert(exception != (ExceptionInfo *) NULL);
284 assert(exception->signature == MagickSignature);
285 image=AcquireImage(image_info);
286 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
287 if (status == MagickFalse)
289 image=DestroyImageList(image);
290 return((Image *) NULL);
293 Read SUN raster header.
295 (void) ResetMagickMemory(&sun_info,0,sizeof(sun_info));
296 sun_info.magic=ReadBlobMSBLong(image);
300 Verify SUN identifier.
302 if (sun_info.magic != 0x59a66a95)
303 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
304 sun_info.width=ReadBlobMSBLong(image);
305 sun_info.height=ReadBlobMSBLong(image);
306 sun_info.depth=ReadBlobMSBLong(image);
307 sun_info.length=ReadBlobMSBLong(image);
308 sun_info.type=ReadBlobMSBLong(image);
309 sun_info.maptype=ReadBlobMSBLong(image);
310 sun_info.maplength=ReadBlobMSBLong(image);
311 image->columns=sun_info.width;
312 image->rows=sun_info.height;
313 if ((sun_info.depth == 0) || (sun_info.depth > 32))
314 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
315 image->depth=sun_info.depth <= 8 ? sun_info.depth :
316 MAGICKCORE_QUANTUM_DEPTH;
317 if (sun_info.depth < 24)
322 image->storage_class=PseudoClass;
323 image->colors=sun_info.maplength;
325 if (sun_info.maptype == RMT_NONE)
326 image->colors=one << sun_info.depth;
327 if (sun_info.maptype == RMT_EQUAL_RGB)
328 image->colors=sun_info.maplength/3;
330 switch (sun_info.maptype)
334 if (sun_info.depth < 24)
337 Create linear color ramp.
339 if (AcquireImageColormap(image,image->colors) == MagickFalse)
340 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
350 Read SUN raster colormap.
352 if (AcquireImageColormap(image,image->colors) == MagickFalse)
353 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
354 sun_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
355 sizeof(*sun_colormap));
356 if (sun_colormap == (unsigned char *) NULL)
357 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
358 count=ReadBlob(image,image->colors,sun_colormap);
359 for (i=0; i < (ssize_t) image->colors; i++)
360 image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);
361 count=ReadBlob(image,image->colors,sun_colormap);
362 for (i=0; i < (ssize_t) image->colors; i++)
363 image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);
364 count=ReadBlob(image,image->colors,sun_colormap);
365 for (i=0; i < (ssize_t) image->colors; i++)
366 image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);
367 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
376 Read SUN raster colormap.
378 sun_colormap=(unsigned char *) AcquireQuantumMemory(sun_info.maplength,
379 sizeof(*sun_colormap));
380 if (sun_colormap == (unsigned char *) NULL)
381 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
382 count=ReadBlob(image,sun_info.maplength,sun_colormap);
383 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
387 ThrowReaderException(CoderError,"ColormapTypeNotSupported");
389 image->matte=sun_info.depth == 32 ? MagickTrue : MagickFalse;
390 image->columns=sun_info.width;
391 image->rows=sun_info.height;
392 if (image_info->ping != MagickFalse)
394 (void) CloseBlob(image);
395 return(GetFirstImageInList(image));
397 if ((sun_info.length*sizeof(*sun_data))/sizeof(*sun_data) !=
398 sun_info.length || !sun_info.length)
399 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
400 number_pixels=(MagickSizeType) image->columns*image->rows;
401 if ((sun_info.depth >= 8) &&
402 ((number_pixels*((sun_info.depth+7)/8)) > sun_info.length))
403 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
404 sun_data=(unsigned char *) AcquireQuantumMemory((size_t) sun_info.length,
406 if (sun_data == (unsigned char *) NULL)
407 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
408 count=(ssize_t) ReadBlob(image,sun_info.length,sun_data);
409 if ((count == 0) && (sun_info.type != RT_ENCODED))
410 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
413 if (sun_info.type == RT_ENCODED)
419 Read run-length encoded raster pixels.
421 height=sun_info.height;
422 bytes_per_line=sun_info.width*sun_info.depth;
423 if ((height == 0) || (sun_info.width == 0) || (sun_info.depth == 0) ||
424 ((bytes_per_line/sun_info.depth) != sun_info.width))
425 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
428 if ((bytes_per_line >> 1) != (sun_info.width*sun_info.depth+15))
429 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
431 sun_pixels=(unsigned char *) AcquireQuantumMemory(height,
432 bytes_per_line*sizeof(*sun_pixels));
433 if (sun_pixels == (unsigned char *) NULL)
434 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
435 (void) DecodeImage(sun_data,sun_info.length,sun_pixels,
436 bytes_per_line*height);
437 sun_data=(unsigned char *) RelinquishMagickMemory(sun_data);
440 Convert SUN raster image to pixel packets.
443 if (sun_info.depth == 1)
444 for (y=0; y < (ssize_t) image->rows; y++)
446 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
447 if (q == (PixelPacket *) NULL)
449 indexes=GetAuthenticIndexQueue(image);
450 for (x=0; x < ((ssize_t) image->columns-7); x+=8)
452 for (bit=7; bit >= 0; bit--)
453 indexes[x+7-bit]=(IndexPacket) ((*p) & (0x01 << bit) ? 0x00 : 0x01);
456 if ((image->columns % 8) != 0)
458 for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--)
459 indexes[x+7-bit]=(IndexPacket)
460 ((*p) & (0x01 << bit) ? 0x00 : 0x01);
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 == (PixelPacket *) NULL)
488 indexes=GetAuthenticIndexQueue(image);
489 for (x=0; x < (ssize_t) image->columns; x++)
490 indexes[x]=(IndexPacket) (*p++);
491 if ((image->columns % 2) != 0)
493 if (SyncAuthenticPixels(image,exception) == MagickFalse)
495 if (image->previous == (Image *) NULL)
497 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
499 if (status == MagickFalse)
510 if (image->matte != MagickFalse)
512 length=image->rows*((bytes_per_line*image->columns)+
514 if (((sun_info.type == RT_ENCODED) &&
515 (length > (bytes_per_line*image->rows))) ||
516 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
517 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
518 for (y=0; y < (ssize_t) image->rows; y++)
520 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
521 if (q == (PixelPacket *) NULL)
523 for (x=0; x < (ssize_t) image->columns; x++)
525 if (image->matte != MagickFalse)
526 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++));
527 if (sun_info.type == RT_STANDARD)
529 q->blue=ScaleCharToQuantum(*p++);
530 q->green=ScaleCharToQuantum(*p++);
531 q->red=ScaleCharToQuantum(*p++);
535 q->red=ScaleCharToQuantum(*p++);
536 q->green=ScaleCharToQuantum(*p++);
537 q->blue=ScaleCharToQuantum(*p++);
539 if (image->colors != 0)
541 q->red=image->colormap[(ssize_t) q->red].red;
542 q->green=image->colormap[(ssize_t) q->green].green;
543 q->blue=image->colormap[(ssize_t) q->blue].blue;
547 if (((bytes_per_pixel*image->columns) % 2) != 0)
549 if (SyncAuthenticPixels(image,exception) == MagickFalse)
551 if (image->previous == (Image *) NULL)
553 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
555 if (status == MagickFalse)
560 if (image->storage_class == PseudoClass)
561 (void) SyncImage(image);
562 sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
563 if (EOFBlob(image) != MagickFalse)
565 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
570 Proceed to next image.
572 if (image_info->number_scenes != 0)
573 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
575 sun_info.magic=ReadBlobMSBLong(image);
576 if (sun_info.magic == 0x59a66a95)
579 Allocate next image structure.
581 AcquireNextImage(image_info,image);
582 if (GetNextImageInList(image) == (Image *) NULL)
584 image=DestroyImageList(image);
585 return((Image *) NULL);
587 image=SyncNextImageInList(image);
588 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
590 if (status == MagickFalse)
593 } while (sun_info.magic == 0x59a66a95);
594 (void) CloseBlob(image);
595 return(GetFirstImageInList(image));
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 % R e g i s t e r S U N I m a g e %
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609 % RegisterSUNImage() adds attributes for the SUN image format to
610 % the list of supported formats. The attributes include the image format
611 % tag, a method to read and/or write the format, whether the format
612 % supports the saving of more than one frame to the same file or blob,
613 % whether the format supports native in-memory I/O, and a brief
614 % description of the format.
616 % The format of the RegisterSUNImage method is:
618 % size_t RegisterSUNImage(void)
621 ModuleExport size_t RegisterSUNImage(void)
626 entry=SetMagickInfo("RAS");
627 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
628 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
629 entry->magick=(IsImageFormatHandler *) IsSUN;
630 entry->description=ConstantString("SUN Rasterfile");
631 entry->module=ConstantString("SUN");
632 (void) RegisterMagickInfo(entry);
633 entry=SetMagickInfo("SUN");
634 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
635 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
636 entry->description=ConstantString("SUN Rasterfile");
637 entry->module=ConstantString("SUN");
638 (void) RegisterMagickInfo(entry);
639 return(MagickImageCoderSignature);
643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
647 % U n r e g i s t e r S U N I m a g e %
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 % UnregisterSUNImage() removes format registrations made by the
654 % SUN module from the list of supported formats.
656 % The format of the UnregisterSUNImage method is:
658 % UnregisterSUNImage(void)
661 ModuleExport void UnregisterSUNImage(void)
663 (void) UnregisterMagickInfo("RAS");
664 (void) UnregisterMagickInfo("SUN");
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672 % W r i t e S U N I m a g e %
676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678 % WriteSUNImage() writes an image in the SUN rasterfile format.
680 % The format of the WriteSUNImage method is:
682 % MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
684 % A description of each parameter follows.
686 % o image_info: the image info.
688 % o image: The image.
691 static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
693 #define RMT_EQUAL_RGB 1
696 #define RT_STANDARD 1
697 #define RT_FORMAT_RGB 3
699 typedef struct _SUNInfo
724 register const IndexPacket
727 register const PixelPacket
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 (IsMonochromeImage(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 PixelPacket *) NULL)
853 for (x=0; x < (ssize_t) image->columns; x++)
855 if (image->matte != MagickFalse)
856 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
857 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
858 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
859 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
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 (IsMonochromeImage(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 PixelPacket *) NULL)
891 indexes=GetVirtualIndexQueue(image);
894 for (x=0; x < (ssize_t) image->columns; x++)
897 if (PixelIntensity(p) < (MagickRealType) (QuantumRange/2.0))
902 (void) WriteBlobByte(image,byte);
909 (void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
910 if ((((image->columns/8)+
911 (image->columns % 8 ? 1 : 0)) % 2) != 0)
912 (void) WriteBlobByte(image,0); /* pad scanline */
913 if (image->previous == (Image *) NULL)
915 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
917 if (status == MagickFalse)
925 Dump colormap to file.
927 for (i=0; i < (ssize_t) image->colors; i++)
928 (void) WriteBlobByte(image,
929 ScaleQuantumToChar(image->colormap[i].red));
930 for (i=0; i < (ssize_t) image->colors; i++)
931 (void) WriteBlobByte(image,
932 ScaleQuantumToChar(image->colormap[i].green));
933 for (i=0; i < (ssize_t) image->colors; i++)
934 (void) WriteBlobByte(image,
935 ScaleQuantumToChar(image->colormap[i].blue));
937 Convert PseudoClass packet to SUN colormapped pixel.
939 for (y=0; y < (ssize_t) image->rows; y++)
941 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
942 if (p == (const PixelPacket *) NULL)
944 indexes=GetVirtualIndexQueue(image);
945 for (x=0; x < (ssize_t) image->columns; x++)
947 (void) WriteBlobByte(image,(unsigned char) indexes[x]);
950 if (image->columns & 0x01)
951 (void) WriteBlobByte(image,0); /* pad scanline */
952 if (image->previous == (Image *) NULL)
954 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
956 if (status == MagickFalse)
961 if (GetNextImageInList(image) == (Image *) NULL)
963 image=SyncNextImageInList(image);
964 status=SetImageProgress(image,SaveImagesTag,scene++,
965 GetImageListLength(image));
966 if (status == MagickFalse)
968 } while (image_info->adjoin != MagickFalse);
969 (void) CloseBlob(image);