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)
319 image->storage_class=PseudoClass;
320 image->colors=sun_info.maplength;
321 if (sun_info.maptype == RMT_NONE)
322 image->colors=1 << 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 < (long) 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 < (long) 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 < (long) 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 < (long) image->rows; y++)
442 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
443 if (q == (PixelPacket *) NULL)
445 indexes=GetAuthenticIndexQueue(image);
446 for (x=0; x < ((long) image->columns-7); x+=8)
448 for (bit=7; bit >= 0; bit--)
449 indexes[x+7-bit]=(IndexPacket) ((*p) & (0x01 << bit) ? 0x00 : 0x01);
452 if ((image->columns % 8) != 0)
454 for (bit=7; bit >= (long) (8-(image->columns % 8)); bit--)
455 indexes[x+7-bit]=(IndexPacket)
456 ((*p) & (0x01 << bit) ? 0x00 : 0x01);
459 if ((((image->columns/8)+(image->columns % 8 ? 1 : 0)) % 2) != 0)
461 if (SyncAuthenticPixels(image,exception) == MagickFalse)
463 if (image->previous == (Image *) NULL)
465 status=SetImageProgress(image,LoadImageTag,y,image->rows);
466 if (status == MagickFalse)
471 if (image->storage_class == PseudoClass)
473 length=image->rows*(image->columns+image->columns % 2);
474 if (((sun_info.type == RT_ENCODED) &&
475 (length > (bytes_per_line*image->rows))) ||
476 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
477 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
478 for (y=0; y < (long) image->rows; y++)
480 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
481 if (q == (PixelPacket *) NULL)
483 indexes=GetAuthenticIndexQueue(image);
484 for (x=0; x < (long) image->columns; x++)
485 indexes[x]=(IndexPacket) (*p++);
486 if ((image->columns % 2) != 0)
488 if (SyncAuthenticPixels(image,exception) == MagickFalse)
490 if (image->previous == (Image *) NULL)
492 status=SetImageProgress(image,LoadImageTag,y,image->rows);
493 if (status == MagickFalse)
504 if (image->matte != MagickFalse)
506 length=image->rows*((bytes_per_line*image->columns)+
508 if (((sun_info.type == RT_ENCODED) &&
509 (length > (bytes_per_line*image->rows))) ||
510 ((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
511 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
512 for (y=0; y < (long) image->rows; y++)
514 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
515 if (q == (PixelPacket *) NULL)
517 for (x=0; x < (long) image->columns; x++)
519 if (image->matte != MagickFalse)
520 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++));
521 if (sun_info.type == RT_STANDARD)
523 q->blue=ScaleCharToQuantum(*p++);
524 q->green=ScaleCharToQuantum(*p++);
525 q->red=ScaleCharToQuantum(*p++);
529 q->red=ScaleCharToQuantum(*p++);
530 q->green=ScaleCharToQuantum(*p++);
531 q->blue=ScaleCharToQuantum(*p++);
533 if (image->colors != 0)
535 q->red=image->colormap[(long) q->red].red;
536 q->green=image->colormap[(long) q->green].green;
537 q->blue=image->colormap[(long) q->blue].blue;
541 if (((bytes_per_pixel*image->columns) % 2) != 0)
543 if (SyncAuthenticPixels(image,exception) == MagickFalse)
545 if (image->previous == (Image *) NULL)
547 status=SetImageProgress(image,LoadImageTag,y,image->rows);
548 if (status == MagickFalse)
553 if (image->storage_class == PseudoClass)
554 (void) SyncImage(image);
555 sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
556 if (EOFBlob(image) != MagickFalse)
558 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
563 Proceed to next image.
565 if (image_info->number_scenes != 0)
566 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
568 sun_info.magic=ReadBlobMSBLong(image);
569 if (sun_info.magic == 0x59a66a95)
572 Allocate next image structure.
574 AcquireNextImage(image_info,image);
575 if (GetNextImageInList(image) == (Image *) NULL)
577 image=DestroyImageList(image);
578 return((Image *) NULL);
580 image=SyncNextImageInList(image);
581 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
583 if (status == MagickFalse)
586 } while (sun_info.magic == 0x59a66a95);
587 (void) CloseBlob(image);
588 return(GetFirstImageInList(image));
592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
596 % R e g i s t e r S U N I m a g e %
600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
602 % RegisterSUNImage() adds attributes for the SUN image format to
603 % the list of supported formats. The attributes include the image format
604 % tag, a method to read and/or write the format, whether the format
605 % supports the saving of more than one frame to the same file or blob,
606 % whether the format supports native in-memory I/O, and a brief
607 % description of the format.
609 % The format of the RegisterSUNImage method is:
611 % unsigned long RegisterSUNImage(void)
614 ModuleExport unsigned long RegisterSUNImage(void)
619 entry=SetMagickInfo("RAS");
620 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
621 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
622 entry->magick=(IsImageFormatHandler *) IsSUN;
623 entry->description=ConstantString("SUN Rasterfile");
624 entry->module=ConstantString("SUN");
625 (void) RegisterMagickInfo(entry);
626 entry=SetMagickInfo("SUN");
627 entry->decoder=(DecodeImageHandler *) ReadSUNImage;
628 entry->encoder=(EncodeImageHandler *) WriteSUNImage;
629 entry->description=ConstantString("SUN Rasterfile");
630 entry->module=ConstantString("SUN");
631 (void) RegisterMagickInfo(entry);
632 return(MagickImageCoderSignature);
636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
640 % U n r e g i s t e r S U N I m a g e %
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 % UnregisterSUNImage() removes format registrations made by the
647 % SUN module from the list of supported formats.
649 % The format of the UnregisterSUNImage method is:
651 % UnregisterSUNImage(void)
654 ModuleExport void UnregisterSUNImage(void)
656 (void) UnregisterMagickInfo("RAS");
657 (void) UnregisterMagickInfo("SUN");
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 % W r i t e S U N I m a g e %
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 % WriteSUNImage() writes an image in the SUN rasterfile format.
673 % The format of the WriteSUNImage method is:
675 % MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
677 % A description of each parameter follows.
679 % o image_info: the image info.
681 % o image: The image.
684 static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
686 #define RMT_EQUAL_RGB 1
689 #define RT_STANDARD 1
690 #define RT_FORMAT_RGB 3
692 typedef struct _SUNInfo
717 register const IndexPacket
720 register const PixelPacket
733 Open output image file.
735 assert(image_info != (const ImageInfo *) NULL);
736 assert(image_info->signature == MagickSignature);
737 assert(image != (Image *) NULL);
738 assert(image->signature == MagickSignature);
739 if (image->debug != MagickFalse)
740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
741 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
742 if (status == MagickFalse)
748 Initialize SUN raster file header.
750 if (image->colorspace != RGBColorspace)
751 (void) TransformImageColorspace(image,RGBColorspace);
752 sun_info.magic=0x59a66a95;
753 if ((image->columns != (unsigned int) image->columns) ||
754 (image->rows != (unsigned int) image->rows))
755 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
756 sun_info.width=(unsigned int) image->columns;
757 sun_info.height=(unsigned int) image->rows;
758 sun_info.type=(unsigned int)
759 (image->storage_class == DirectClass ? RT_FORMAT_RGB : RT_STANDARD);
760 sun_info.maptype=RMT_NONE;
761 sun_info.maplength=0;
762 number_pixels=(MagickSizeType) image->columns*image->rows;
763 if ((4*number_pixels) != (size_t) (4*number_pixels))
764 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
765 if (image->storage_class == DirectClass)
768 Full color SUN raster.
770 sun_info.depth=image->matte ? 32U : 24U;
771 sun_info.length=(unsigned int) ((image->matte ? 4 : 3)*number_pixels);
772 sun_info.length+=sun_info.length & 0x01 ? image->rows : 0;
775 if (IsMonochromeImage(image,&image->exception))
778 Monochrome SUN raster.
781 sun_info.length=(unsigned int) (((image->columns+7) >> 3)*
783 sun_info.length+=((image->columns/8)+(image->columns % 8 ? 1 : 0)) %
789 Colormapped SUN raster.
792 sun_info.length=(unsigned int) number_pixels;
793 sun_info.length+=image->columns & 0x01 ? image->rows : 0;
794 sun_info.maptype=RMT_EQUAL_RGB;
795 sun_info.maplength=(unsigned int) (3*image->colors);
800 (void) WriteBlobMSBLong(image,sun_info.magic);
801 (void) WriteBlobMSBLong(image,sun_info.width);
802 (void) WriteBlobMSBLong(image,sun_info.height);
803 (void) WriteBlobMSBLong(image,sun_info.depth);
804 (void) WriteBlobMSBLong(image,sun_info.length);
805 (void) WriteBlobMSBLong(image,sun_info.type);
806 (void) WriteBlobMSBLong(image,sun_info.maptype);
807 (void) WriteBlobMSBLong(image,sun_info.maplength);
809 Convert MIFF to SUN raster pixels.
813 if (image->storage_class == DirectClass)
815 register unsigned char
826 Allocate memory for pixels.
829 if (image->matte != MagickFalse)
831 length=image->columns;
832 pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels));
833 if (pixels == (unsigned char *) NULL)
834 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
836 Convert DirectClass packet to SUN RGB pixel.
838 for (y=0; y < (long) image->rows; y++)
840 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
841 if (p == (const PixelPacket *) NULL)
844 for (x=0; x < (long) image->columns; x++)
846 if (image->matte != MagickFalse)
847 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
848 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
849 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
850 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
853 if (((bytes_per_pixel*image->columns) & 0x01) != 0)
854 *q++='\0'; /* pad scanline */
855 (void) WriteBlob(image,(size_t) (q-pixels),pixels);
856 if (image->previous == (Image *) NULL)
858 status=SetImageProgress(image,SaveImageTag,y,image->rows);
859 if (status == MagickFalse)
863 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
866 if (IsMonochromeImage(image,&image->exception))
868 register unsigned char
873 Convert PseudoClass image to a SUN monochrome image.
875 (void) SetImageType(image,BilevelType);
876 for (y=0; y < (long) image->rows; y++)
878 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
879 if (p == (const PixelPacket *) NULL)
881 indexes=GetVirtualIndexQueue(image);
884 for (x=0; x < (long) image->columns; x++)
887 if (PixelIntensity(p) < (MagickRealType) (QuantumRange/2.0))
892 (void) WriteBlobByte(image,byte);
899 (void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
900 if ((((image->columns/8)+
901 (image->columns % 8 ? 1 : 0)) % 2) != 0)
902 (void) WriteBlobByte(image,0); /* pad scanline */
903 if (image->previous == (Image *) NULL)
905 status=SetImageProgress(image,SaveImageTag,y,image->rows);
906 if (status == MagickFalse)
914 Dump colormap to file.
916 for (i=0; i < (long) image->colors; i++)
917 (void) WriteBlobByte(image,
918 ScaleQuantumToChar(image->colormap[i].red));
919 for (i=0; i < (long) image->colors; i++)
920 (void) WriteBlobByte(image,
921 ScaleQuantumToChar(image->colormap[i].green));
922 for (i=0; i < (long) image->colors; i++)
923 (void) WriteBlobByte(image,
924 ScaleQuantumToChar(image->colormap[i].blue));
926 Convert PseudoClass packet to SUN colormapped pixel.
928 for (y=0; y < (long) image->rows; y++)
930 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
931 if (p == (const PixelPacket *) NULL)
933 indexes=GetVirtualIndexQueue(image);
934 for (x=0; x < (long) image->columns; x++)
936 (void) WriteBlobByte(image,(unsigned char) indexes[x]);
939 if (image->columns & 0x01)
940 (void) WriteBlobByte(image,0); /* pad scanline */
941 if (image->previous == (Image *) NULL)
943 status=SetImageProgress(image,SaveImageTag,y,image->rows);
944 if (status == MagickFalse)
949 if (GetNextImageInList(image) == (Image *) NULL)
951 image=SyncNextImageInList(image);
952 status=SetImageProgress(image,SaveImagesTag,scene++,
953 GetImageListLength(image));
954 if (status == MagickFalse)
956 } while (image_info->adjoin != MagickFalse);
957 (void) CloseBlob(image);