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 "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
254 register unsigned char
276 assert(image_info != (const ImageInfo *) NULL);
277 assert(image_info->signature == MagickSignature);
278 if (image_info->debug != MagickFalse)
279 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
280 image_info->filename);
281 assert(exception != (ExceptionInfo *) NULL);
282 assert(exception->signature == MagickSignature);
283 image=AcquireImage(image_info);
284 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
285 if (status == MagickFalse)
287 image=DestroyImageList(image);
288 return((Image *) NULL);
291 Read SUN raster header.
293 (void) ResetMagickMemory(&sun_info,0,sizeof(sun_info));
294 sun_info.magic=ReadBlobMSBLong(image);
298 Verify SUN identifier.
300 if (sun_info.magic != 0x59a66a95)
301 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
302 sun_info.width=ReadBlobMSBLong(image);
303 sun_info.height=ReadBlobMSBLong(image);
304 sun_info.depth=ReadBlobMSBLong(image);
305 sun_info.length=ReadBlobMSBLong(image);
306 sun_info.type=ReadBlobMSBLong(image);
307 sun_info.maptype=ReadBlobMSBLong(image);
308 sun_info.maplength=ReadBlobMSBLong(image);
309 image->columns=sun_info.width;
310 image->rows=sun_info.height;
311 if ((sun_info.depth == 0) || (sun_info.depth > 32))
312 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
313 image->depth=sun_info.depth <= 8 ? sun_info.depth :
314 MAGICKCORE_QUANTUM_DEPTH;
315 if (sun_info.depth < 24)
320 image->storage_class=PseudoClass;
321 image->colors=sun_info.maplength;
323 if (sun_info.maptype == RMT_NONE)
324 image->colors=one << sun_info.depth;
325 if (sun_info.maptype == RMT_EQUAL_RGB)
326 image->colors=sun_info.maplength/3;
328 switch (sun_info.maptype)
332 if (sun_info.depth < 24)
335 Create linear color ramp.
337 if (AcquireImageColormap(image,image->colors) == MagickFalse)
338 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
348 Read SUN raster colormap.
350 if (AcquireImageColormap(image,image->colors) == MagickFalse)
351 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
352 sun_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
353 sizeof(*sun_colormap));
354 if (sun_colormap == (unsigned char *) NULL)
355 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
356 count=ReadBlob(image,image->colors,sun_colormap);
357 for (i=0; i < (ssize_t) image->colors; i++)
358 image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);
359 count=ReadBlob(image,image->colors,sun_colormap);
360 for (i=0; i < (ssize_t) image->colors; i++)
361 image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);
362 count=ReadBlob(image,image->colors,sun_colormap);
363 for (i=0; i < (ssize_t) image->colors; i++)
364 image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);
365 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
374 Read SUN raster colormap.
376 sun_colormap=(unsigned char *) AcquireQuantumMemory(sun_info.maplength,
377 sizeof(*sun_colormap));
378 if (sun_colormap == (unsigned char *) NULL)
379 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
380 count=ReadBlob(image,sun_info.maplength,sun_colormap);
381 sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
385 ThrowReaderException(CoderError,"ColormapTypeNotSupported");
387 image->matte=sun_info.depth == 32 ? MagickTrue : MagickFalse;
388 image->columns=sun_info.width;
389 image->rows=sun_info.height;
390 if (image_info->ping != MagickFalse)
392 (void) CloseBlob(image);
393 return(GetFirstImageInList(image));
395 if ((sun_info.length*sizeof(*sun_data))/sizeof(*sun_data) !=
396 sun_info.length || !sun_info.length)
397 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
398 number_pixels=(MagickSizeType) image->columns*image->rows;
399 if ((sun_info.depth >= 8) &&
400 ((number_pixels*((sun_info.depth+7)/8)) > sun_info.length))
401 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
402 sun_data=(unsigned char *) AcquireQuantumMemory((size_t) sun_info.length,
404 if (sun_data == (unsigned char *) NULL)
405 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
406 count=(ssize_t) ReadBlob(image,sun_info.length,sun_data);
407 if ((count == 0) && (sun_info.type != RT_ENCODED))
408 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
411 if (sun_info.type == RT_ENCODED)
417 Read run-length encoded raster pixels.
419 height=sun_info.height;
420 bytes_per_line=sun_info.width*sun_info.depth;
421 if ((height == 0) || (sun_info.width == 0) || (sun_info.depth == 0) ||
422 ((bytes_per_line/sun_info.depth) != sun_info.width))
423 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
426 if ((bytes_per_line >> 1) != (sun_info.width*sun_info.depth+15))
427 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
429 sun_pixels=(unsigned char *) AcquireQuantumMemory(height,
430 bytes_per_line*sizeof(*sun_pixels));
431 if (sun_pixels == (unsigned char *) NULL)
432 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
433 (void) DecodeImage(sun_data,sun_info.length,sun_pixels,
434 bytes_per_line*height);
435 sun_data=(unsigned char *) RelinquishMagickMemory(sun_data);
438 Convert SUN raster image to pixel packets.
441 if (sun_info.depth == 1)
442 for (y=0; y < (ssize_t) image->rows; y++)
444 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
445 if (q == (PixelPacket *) NULL)
447 indexes=GetAuthenticIndexQueue(image);
448 for (x=0; x < ((ssize_t) image->columns-7); x+=8)
450 for (bit=7; bit >= 0; bit--)
451 indexes[x+7-bit]=(IndexPacket) ((*p) & (0x01 << bit) ? 0x00 : 0x01);
454 if ((image->columns % 8) != 0)
456 for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--)
457 indexes[x+7-bit]=(IndexPacket)
458 ((*p) & (0x01 << bit) ? 0x00 : 0x01);
461 if ((((image->columns/8)+(image->columns % 8 ? 1 : 0)) % 2) != 0)
463 if (SyncAuthenticPixels(image,exception) == MagickFalse)
465 if (image->previous == (Image *) NULL)
467 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
469 if (status == MagickFalse)
474 if (image->storage_class == PseudoClass)
476 length=image->rows*(image->columns+image->columns % 2);
477 if (((sun_info.type == RT_ENCODED) &&
478 (length > (bytes_per_line*image->rows))) ||
479 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
480 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
481 for (y=0; y < (ssize_t) image->rows; y++)
483 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
484 if (q == (PixelPacket *) NULL)
486 indexes=GetAuthenticIndexQueue(image);
487 for (x=0; x < (ssize_t) image->columns; x++)
488 indexes[x]=(IndexPacket) (*p++);
489 if ((image->columns % 2) != 0)
491 if (SyncAuthenticPixels(image,exception) == MagickFalse)
493 if (image->previous == (Image *) NULL)
495 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
497 if (status == MagickFalse)
508 if (image->matte != MagickFalse)
510 length=image->rows*((bytes_per_line*image->columns)+
512 if (((sun_info.type == RT_ENCODED) &&
513 (length > (bytes_per_line*image->rows))) ||
514 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
515 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
516 for (y=0; y < (ssize_t) image->rows; y++)
518 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
519 if (q == (PixelPacket *) NULL)
521 for (x=0; x < (ssize_t) image->columns; x++)
523 if (image->matte != MagickFalse)
524 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++));
525 if (sun_info.type == RT_STANDARD)
527 q->blue=ScaleCharToQuantum(*p++);
528 q->green=ScaleCharToQuantum(*p++);
529 q->red=ScaleCharToQuantum(*p++);
533 q->red=ScaleCharToQuantum(*p++);
534 q->green=ScaleCharToQuantum(*p++);
535 q->blue=ScaleCharToQuantum(*p++);
537 if (image->colors != 0)
539 q->red=image->colormap[(ssize_t) q->red].red;
540 q->green=image->colormap[(ssize_t) q->green].green;
541 q->blue=image->colormap[(ssize_t) q->blue].blue;
545 if (((bytes_per_pixel*image->columns) % 2) != 0)
547 if (SyncAuthenticPixels(image,exception) == MagickFalse)
549 if (image->previous == (Image *) NULL)
551 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
553 if (status == MagickFalse)
558 if (image->storage_class == PseudoClass)
559 (void) SyncImage(image);
560 sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
561 if (EOFBlob(image) != MagickFalse)
563 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
568 Proceed to next image.
570 if (image_info->number_scenes != 0)
571 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
573 sun_info.magic=ReadBlobMSBLong(image);
574 if (sun_info.magic == 0x59a66a95)
577 Allocate next image structure.
579 AcquireNextImage(image_info,image);
580 if (GetNextImageInList(image) == (Image *) NULL)
582 image=DestroyImageList(image);
583 return((Image *) NULL);
585 image=SyncNextImageInList(image);
586 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
588 if (status == MagickFalse)
591 } while (sun_info.magic == 0x59a66a95);
592 (void) CloseBlob(image);
593 return(GetFirstImageInList(image));
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % R e g i s t e r S U N I m a g e %
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607 % RegisterSUNImage() adds attributes for the SUN image format to
608 % the list of supported formats. The attributes include the image format
609 % tag, a method to read and/or write the format, whether the format
610 % supports the saving of more than one frame to the same file or blob,
611 % whether the format supports native in-memory I/O, and a brief
612 % description of the format.
614 % The format of the RegisterSUNImage method is:
616 % size_t RegisterSUNImage(void)
619 ModuleExport size_t RegisterSUNImage(void)
624 entry=SetMagickInfo("RAS");
625 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
626 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
627 entry->magick=(IsImageFormatHandler *) IsSUN;
628 entry->description=ConstantString("SUN Rasterfile");
629 entry->module=ConstantString("SUN");
630 (void) RegisterMagickInfo(entry);
631 entry=SetMagickInfo("SUN");
632 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
633 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
634 entry->description=ConstantString("SUN Rasterfile");
635 entry->module=ConstantString("SUN");
636 (void) RegisterMagickInfo(entry);
637 return(MagickImageCoderSignature);
641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
645 % U n r e g i s t e r S U N I m a g e %
649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651 % UnregisterSUNImage() removes format registrations made by the
652 % SUN module from the list of supported formats.
654 % The format of the UnregisterSUNImage method is:
656 % UnregisterSUNImage(void)
659 ModuleExport void UnregisterSUNImage(void)
661 (void) UnregisterMagickInfo("RAS");
662 (void) UnregisterMagickInfo("SUN");
666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 % W r i t e S U N I m a g e %
674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676 % WriteSUNImage() writes an image in the SUN rasterfile format.
678 % The format of the WriteSUNImage method is:
680 % MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
682 % A description of each parameter follows.
684 % o image_info: the image info.
686 % o image: The image.
689 static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
691 #define RMT_EQUAL_RGB 1
694 #define RT_STANDARD 1
695 #define RT_FORMAT_RGB 3
697 typedef struct _SUNInfo
719 register const IndexPacket
722 register const PixelPacket
736 Open output image file.
738 assert(image_info != (const ImageInfo *) NULL);
739 assert(image_info->signature == MagickSignature);
740 assert(image != (Image *) NULL);
741 assert(image->signature == MagickSignature);
742 if (image->debug != MagickFalse)
743 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
744 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
745 if (status == MagickFalse)
751 Initialize SUN raster file header.
753 if (image->colorspace != RGBColorspace)
754 (void) TransformImageColorspace(image,RGBColorspace);
755 sun_info.magic=0x59a66a95;
756 if ((image->columns != (unsigned int) image->columns) ||
757 (image->rows != (unsigned int) image->rows))
758 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
759 sun_info.width=(unsigned int) image->columns;
760 sun_info.height=(unsigned int) image->rows;
761 sun_info.type=(unsigned int)
762 (image->storage_class == DirectClass ? RT_FORMAT_RGB : RT_STANDARD);
763 sun_info.maptype=RMT_NONE;
764 sun_info.maplength=0;
765 number_pixels=(MagickSizeType) image->columns*image->rows;
766 if ((4*number_pixels) != (size_t) (4*number_pixels))
767 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
768 if (image->storage_class == DirectClass)
771 Full color SUN raster.
773 sun_info.depth=(unsigned int) image->matte ? 32U : 24U;
774 sun_info.length=(unsigned int) ((image->matte ? 4 : 3)*number_pixels);
775 sun_info.length+=sun_info.length & 0x01 ? (unsigned int) image->rows :
779 if (IsMonochromeImage(image,&image->exception))
782 Monochrome SUN raster.
785 sun_info.length=(unsigned int) (((image->columns+7) >> 3)*
787 sun_info.length+=(unsigned int) (((image->columns/8)+(image->columns %
788 8 ? 1 : 0)) % 2 ? image->rows : 0);
793 Colormapped SUN raster.
796 sun_info.length=(unsigned int) number_pixels;
797 sun_info.length+=(unsigned int) (image->columns & 0x01 ? image->rows :
799 sun_info.maptype=RMT_EQUAL_RGB;
800 sun_info.maplength=(unsigned int) (3*image->colors);
805 (void) WriteBlobMSBLong(image,sun_info.magic);
806 (void) WriteBlobMSBLong(image,sun_info.width);
807 (void) WriteBlobMSBLong(image,sun_info.height);
808 (void) WriteBlobMSBLong(image,sun_info.depth);
809 (void) WriteBlobMSBLong(image,sun_info.length);
810 (void) WriteBlobMSBLong(image,sun_info.type);
811 (void) WriteBlobMSBLong(image,sun_info.maptype);
812 (void) WriteBlobMSBLong(image,sun_info.maplength);
814 Convert MIFF to SUN raster pixels.
818 if (image->storage_class == DirectClass)
820 register unsigned char
831 Allocate memory for pixels.
834 if (image->matte != MagickFalse)
836 length=image->columns;
837 pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels));
838 if (pixels == (unsigned char *) NULL)
839 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
841 Convert DirectClass packet to SUN RGB pixel.
843 for (y=0; y < (ssize_t) image->rows; y++)
845 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
846 if (p == (const PixelPacket *) NULL)
849 for (x=0; x < (ssize_t) image->columns; x++)
851 if (image->matte != MagickFalse)
852 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
853 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
854 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
855 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
858 if (((bytes_per_pixel*image->columns) & 0x01) != 0)
859 *q++='\0'; /* pad scanline */
860 (void) WriteBlob(image,(size_t) (q-pixels),pixels);
861 if (image->previous == (Image *) NULL)
863 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
865 if (status == MagickFalse)
869 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
872 if (IsMonochromeImage(image,&image->exception))
874 register unsigned char
879 Convert PseudoClass image to a SUN monochrome image.
881 (void) SetImageType(image,BilevelType);
882 for (y=0; y < (ssize_t) image->rows; y++)
884 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
885 if (p == (const PixelPacket *) NULL)
887 indexes=GetVirtualIndexQueue(image);
890 for (x=0; x < (ssize_t) image->columns; x++)
893 if (PixelIntensity(p) < (MagickRealType) (QuantumRange/2.0))
898 (void) WriteBlobByte(image,byte);
905 (void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
906 if ((((image->columns/8)+
907 (image->columns % 8 ? 1 : 0)) % 2) != 0)
908 (void) WriteBlobByte(image,0); /* pad scanline */
909 if (image->previous == (Image *) NULL)
911 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
913 if (status == MagickFalse)
921 Dump colormap to file.
923 for (i=0; i < (ssize_t) image->colors; i++)
924 (void) WriteBlobByte(image,
925 ScaleQuantumToChar(image->colormap[i].red));
926 for (i=0; i < (ssize_t) image->colors; i++)
927 (void) WriteBlobByte(image,
928 ScaleQuantumToChar(image->colormap[i].green));
929 for (i=0; i < (ssize_t) image->colors; i++)
930 (void) WriteBlobByte(image,
931 ScaleQuantumToChar(image->colormap[i].blue));
933 Convert PseudoClass packet to SUN colormapped pixel.
935 for (y=0; y < (ssize_t) image->rows; y++)
937 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
938 if (p == (const PixelPacket *) NULL)
940 indexes=GetVirtualIndexQueue(image);
941 for (x=0; x < (ssize_t) image->columns; x++)
943 (void) WriteBlobByte(image,(unsigned char) indexes[x]);
946 if (image->columns & 0x01)
947 (void) WriteBlobByte(image,0); /* pad scanline */
948 if (image->previous == (Image *) NULL)
950 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
952 if (status == MagickFalse)
957 if (GetNextImageInList(image) == (Image *) NULL)
959 image=SyncNextImageInList(image);
960 status=SetImageProgress(image,SaveImagesTag,scene++,
961 GetImageListLength(image));
962 if (status == MagickFalse)
964 } while (image_info->adjoin != MagickFalse);
965 (void) CloseBlob(image);