2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Irix RGB 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/property.h"
60 #include "magick/quantum-private.h"
61 #include "magick/static.h"
62 #include "magick/string_.h"
63 #include "magick/module.h"
66 Typedef declaractions.
68 typedef struct _SGIInfo
101 static MagickBooleanType
102 WriteSGIImage(const ImageInfo *,Image *);
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % IsSGI() returns MagickTrue if the image format type, identified by the
115 % magick string, is SGI.
117 % The format of the IsSGI method is:
119 % MagickBooleanType IsSGI(const unsigned char *magick,const size_t length)
121 % A description of each parameter follows:
123 % o magick: compare image format pattern against these bytes.
125 % o length: Specifies the length of the magick string.
129 static MagickBooleanType IsSGI(const unsigned char *magick,const size_t length)
133 if (memcmp(magick,"\001\332",2) == 0)
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 % R e a d S G I I m a g e %
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % ReadSGIImage() reads a SGI RGB image file and returns it. It
150 % allocates the memory necessary for the new Image structure and returns a
151 % pointer to the new image.
153 % The format of the ReadSGIImage method is:
155 % Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
157 % A description of each parameter follows:
159 % o image_info: the image info.
161 % o exception: return any errors or warnings in this structure.
165 static inline size_t MagickMin(const size_t x,const size_t y)
172 static MagickBooleanType SGIDecode(const size_t bytes_per_pixel,
173 long number_packets,unsigned char *packets,long number_pixels,
174 unsigned char *pixels)
176 register unsigned char
188 if (bytes_per_pixel == 2)
190 for ( ; number_pixels > 0; )
192 if (number_packets-- == 0)
194 pixel=(unsigned long) (*p++) << 8;
196 count=(ssize_t) (pixel & 0x7f);
199 if (count > (ssize_t) number_pixels)
201 number_pixels-=count;
202 if ((pixel & 0x80) != 0)
203 for ( ; count != 0; count--)
205 if (number_packets-- == 0)
213 pixel=(unsigned long) (*p++) << 8;
215 for ( ; count != 0; count--)
217 if (number_packets-- == 0)
219 *q=(unsigned char) (pixel >> 8);
220 *(q+1)=(unsigned char) pixel;
227 for ( ; number_pixels > 0; )
229 if (number_packets-- == 0)
231 pixel=(unsigned long) (*p++);
232 count=(ssize_t) (pixel & 0x7f);
235 if (count > (ssize_t) number_pixels)
237 number_pixels-=count;
238 if ((pixel & 0x80) != 0)
239 for ( ; count != 0; count--)
241 if (number_packets-- == 0)
248 if (number_packets-- == 0)
250 pixel=(unsigned long) (*p++);
251 for ( ; count != 0; count--)
253 *q=(unsigned char) pixel;
261 static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception)
286 register unsigned char
307 assert(image_info != (const ImageInfo *) NULL);
308 assert(image_info->signature == MagickSignature);
309 if (image_info->debug != MagickFalse)
310 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
311 image_info->filename);
312 assert(exception != (ExceptionInfo *) NULL);
313 assert(exception->signature == MagickSignature);
314 image=AcquireImage(image_info);
315 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
316 if (status == MagickFalse)
318 image=DestroyImageList(image);
319 return((Image *) NULL);
322 Read SGI raster header.
324 iris_info.magic=ReadBlobMSBShort(image);
328 Verify SGI identifier.
330 if (iris_info.magic != 0x01DA)
331 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
332 iris_info.storage=(unsigned char) ReadBlobByte(image);
333 switch (iris_info.storage)
335 case 0x00: image->compression=NoCompression; break;
336 case 0x01: image->compression=RLECompression; break;
338 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
340 iris_info.bytes_per_pixel=(unsigned char) ReadBlobByte(image);
341 if ((iris_info.bytes_per_pixel == 0) || (iris_info.bytes_per_pixel > 2))
342 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
343 iris_info.dimension=ReadBlobMSBShort(image);
344 iris_info.columns=ReadBlobMSBShort(image);
345 iris_info.rows=ReadBlobMSBShort(image);
346 iris_info.depth=ReadBlobMSBShort(image);
347 if ((iris_info.depth == 0) || (iris_info.depth > 4))
348 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
349 iris_info.minimum_value=ReadBlobMSBLong(image);
350 iris_info.maximum_value=ReadBlobMSBLong(image);
351 iris_info.sans=ReadBlobMSBLong(image);
352 (void) ReadBlob(image,sizeof(iris_info.name),(unsigned char *)
354 iris_info.name[sizeof(iris_info.name)-1]='\0';
355 if (*iris_info.name != '\0')
356 (void) SetImageProperty(image,"label",iris_info.name);
357 iris_info.pixel_format=ReadBlobMSBLong(image);
358 if (iris_info.pixel_format != 0)
359 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
360 count=ReadBlob(image,sizeof(iris_info.filler),iris_info.filler);
361 image->columns=iris_info.columns;
362 image->rows=iris_info.rows;
363 image->depth=(unsigned long) MagickMin(iris_info.depth,MAGICKCORE_QUANTUM_DEPTH);
364 if (iris_info.pixel_format == 0)
365 image->depth=(unsigned long) MagickMin((size_t) 8*
366 iris_info.bytes_per_pixel,MAGICKCORE_QUANTUM_DEPTH);
367 if (iris_info.depth < 3)
369 image->storage_class=PseudoClass;
372 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
373 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
378 bytes_per_pixel=(size_t) iris_info.bytes_per_pixel;
379 number_pixels=(MagickSizeType) iris_info.columns*iris_info.rows;
380 if ((4*bytes_per_pixel*number_pixels) != ((MagickSizeType) (size_t)
381 (4*bytes_per_pixel*number_pixels)))
382 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
383 iris_pixels=(unsigned char *) AcquireQuantumMemory(iris_info.columns,
384 iris_info.rows*4*bytes_per_pixel*sizeof(*iris_pixels));
385 if (iris_pixels == (unsigned char *) NULL)
386 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
387 if ((int) iris_info.storage != 0x01)
393 Read standard image format.
395 scanline=(unsigned char *) AcquireQuantumMemory(iris_info.columns,
396 bytes_per_pixel*sizeof(*scanline));
397 if (scanline == (unsigned char *) NULL)
398 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
399 for (z=0; z < (long) iris_info.depth; z++)
401 p=iris_pixels+bytes_per_pixel*z;
402 for (y=0; y < (long) iris_info.rows; y++)
404 count=ReadBlob(image,bytes_per_pixel*iris_info.columns,scanline);
405 if (EOFBlob(image) != MagickFalse)
407 if (bytes_per_pixel == 2)
408 for (x=0; x < (long) iris_info.columns; x++)
411 *(p+1)=scanline[2*x+1];
415 for (x=0; x < (long) iris_info.columns; x++)
422 scanline=(unsigned char *) RelinquishMagickMemory(scanline);
440 Read runlength-encoded image format.
442 offsets=(ssize_t *) AcquireQuantumMemory((size_t) iris_info.rows,
443 iris_info.depth*sizeof(*offsets));
444 packets=(unsigned char *) AcquireQuantumMemory((size_t)
445 iris_info.columns+10UL,4UL*sizeof(*packets));
446 runlength=(unsigned long *) AcquireQuantumMemory(iris_info.rows,
447 iris_info.depth*sizeof(*runlength));
448 if ((offsets == (ssize_t *) NULL) ||
449 (packets == (unsigned char *) NULL) ||
450 (runlength == (unsigned long *) NULL))
451 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
452 for (i=0; i < (long) (iris_info.rows*iris_info.depth); i++)
453 offsets[i]=(ssize_t) ReadBlobMSBLong(image);
454 for (i=0; i < (long) (iris_info.rows*iris_info.depth); i++)
456 runlength[i]=ReadBlobMSBLong(image);
457 if (runlength[i] > (4*(size_t) iris_info.columns+10))
458 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
465 for (y=0; ((y < (long) iris_info.rows) && (data_order == 0)); y++)
466 for (z=0; ((z < (long) iris_info.depth) && (data_order == 0)); z++)
468 if (offsets[y+z*iris_info.rows] < offset)
470 offset=offsets[y+z*iris_info.rows];
472 offset=(ssize_t) TellBlob(image);
475 for (z=0; z < (long) iris_info.depth; z++)
478 for (y=0; y < (long) iris_info.rows; y++)
480 if (offset != offsets[y+z*iris_info.rows])
482 offset=offsets[y+z*iris_info.rows];
483 offset=(ssize_t) SeekBlob(image,(long) offset,SEEK_SET);
485 count=ReadBlob(image,(size_t) runlength[y+z*iris_info.rows],
487 if (EOFBlob(image) != MagickFalse)
489 offset+=runlength[y+z*iris_info.rows];
490 status=SGIDecode(bytes_per_pixel,(long)
491 (runlength[y+z*iris_info.rows]/bytes_per_pixel),packets,
492 1L*iris_info.columns,p+bytes_per_pixel*z);
493 if (status == MagickFalse)
494 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
495 p+=(iris_info.columns*4*bytes_per_pixel);
504 position=TellBlob(image);
506 for (y=0; y < (long) iris_info.rows; y++)
508 for (z=0; z < (long) iris_info.depth; z++)
510 if (offset != offsets[y+z*iris_info.rows])
512 offset=offsets[y+z*iris_info.rows];
513 offset=(ssize_t) SeekBlob(image,(long) offset,SEEK_SET);
515 count=ReadBlob(image,(size_t) runlength[y+z*iris_info.rows],
517 if (EOFBlob(image) != MagickFalse)
519 offset+=runlength[y+z*iris_info.rows];
520 status=SGIDecode(bytes_per_pixel,(long)
521 (runlength[y+z*iris_info.rows]/bytes_per_pixel),packets,
522 1L*iris_info.columns,p+bytes_per_pixel*z);
523 if (status == MagickFalse)
524 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
526 p+=(iris_info.columns*4*bytes_per_pixel);
528 offset=(ssize_t) SeekBlob(image,position,SEEK_SET);
530 runlength=(unsigned long *) RelinquishMagickMemory(runlength);
531 packets=(unsigned char *) RelinquishMagickMemory(packets);
532 offsets=(ssize_t *) RelinquishMagickMemory(offsets);
535 Initialize image structure.
537 image->matte=iris_info.depth == 4 ? MagickTrue : MagickFalse;
538 image->columns=iris_info.columns;
539 image->rows=iris_info.rows;
541 Convert SGI raster image to pixel packets.
543 if (image->storage_class == DirectClass)
546 Convert SGI image to DirectClass pixel packets.
548 if (bytes_per_pixel == 2)
550 for (y=0; y < (long) image->rows; y++)
552 p=iris_pixels+(image->rows-y-1)*8*image->columns;
553 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
554 if (q == (PixelPacket *) NULL)
556 for (x=0; x < (long) image->columns; x++)
558 q->red=ScaleShortToQuantum((unsigned short)
559 ((*(p+0) << 8) | (*(p+1))));
560 q->green=ScaleShortToQuantum((unsigned short)
561 ((*(p+2) << 8) | (*(p+3))));
562 q->blue=ScaleShortToQuantum((unsigned short)
563 ((*(p+4) << 8) | (*(p+5))));
564 SetOpacityPixelComponent(q,OpaqueOpacity);
565 if (image->matte != MagickFalse)
566 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
567 (unsigned short) ((*(p+6) << 8) | (*(p+7)))));
571 if (SyncAuthenticPixels(image,exception) == MagickFalse)
573 if (image->previous == (Image *) NULL)
575 status=SetImageProgress(image,LoadImageTag,y,image->rows);
576 if (status == MagickFalse)
582 for (y=0; y < (long) image->rows; y++)
584 p=iris_pixels+(image->rows-y-1)*4*image->columns;
585 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
586 if (q == (PixelPacket *) NULL)
588 for (x=0; x < (long) image->columns; x++)
590 q->red=ScaleCharToQuantum(*p);
591 q->green=ScaleCharToQuantum(*(p+1));
592 q->blue=ScaleCharToQuantum(*(p+2));
593 SetOpacityPixelComponent(q,OpaqueOpacity);
594 if (image->matte != MagickFalse)
595 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*(p+3)));
599 if (SyncAuthenticPixels(image,exception) == MagickFalse)
601 if (image->previous == (Image *) NULL)
603 status=SetImageProgress(image,LoadImageTag,y,image->rows);
604 if (status == MagickFalse)
612 Create grayscale map.
614 if (AcquireImageColormap(image,image->colors) == MagickFalse)
615 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
617 Convert SGI image to PseudoClass pixel packets.
619 if (bytes_per_pixel == 2)
621 for (y=0; y < (long) image->rows; y++)
623 p=iris_pixels+(image->rows-y-1)*8*image->columns;
624 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
625 if (q == (PixelPacket *) NULL)
627 indexes=GetAuthenticIndexQueue(image);
628 for (x=0; x < (long) image->columns; x++)
632 indexes[x]=(IndexPacket) quantum;
636 if (SyncAuthenticPixels(image,exception) == MagickFalse)
638 if (image->previous == (Image *) NULL)
640 status=SetImageProgress(image,LoadImageTag,y,image->rows);
641 if (status == MagickFalse)
647 for (y=0; y < (long) image->rows; y++)
649 p=iris_pixels+(image->rows-y-1)*4*image->columns;
650 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
651 if (q == (PixelPacket *) NULL)
653 indexes=GetAuthenticIndexQueue(image);
654 for (x=0; x < (long) image->columns; x++)
656 indexes[x]=(IndexPacket) (*p);
660 if (SyncAuthenticPixels(image,exception) == MagickFalse)
662 if (image->previous == (Image *) NULL)
664 status=SetImageProgress(image,LoadImageTag,y,image->rows);
665 if (status == MagickFalse)
669 (void) SyncImage(image);
671 iris_pixels=(unsigned char *) RelinquishMagickMemory(iris_pixels);
672 if (EOFBlob(image) != MagickFalse)
674 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
679 Proceed to next image.
681 if (image_info->number_scenes != 0)
682 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
684 iris_info.magic=ReadBlobMSBShort(image);
685 if (iris_info.magic == 0x01DA)
688 Allocate next image structure.
690 AcquireNextImage(image_info,image);
691 if (GetNextImageInList(image) == (Image *) NULL)
693 image=DestroyImageList(image);
694 return((Image *) NULL);
696 image=SyncNextImageInList(image);
697 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
699 if (status == MagickFalse)
702 } while (iris_info.magic == 0x01DA);
703 (void) CloseBlob(image);
704 return(GetFirstImageInList(image));
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 % R e g i s t e r S G I I m a g e %
716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
718 % RegisterSGIImage() adds properties for the SGI image format to
719 % the list of supported formats. The properties include the image format
720 % tag, a method to read and/or write the format, whether the format
721 % supports the saving of more than one frame to the same file or blob,
722 % whether the format supports native in-memory I/O, and a brief
723 % description of the format.
725 % The format of the RegisterSGIImage method is:
727 % unsigned long RegisterSGIImage(void)
730 ModuleExport unsigned long RegisterSGIImage(void)
735 entry=SetMagickInfo("SGI");
736 entry->decoder=(DecodeImageHandler *) ReadSGIImage;
737 entry->encoder=(EncodeImageHandler *) WriteSGIImage;
738 entry->magick=(IsImageFormatHandler *) IsSGI;
739 entry->description=ConstantString("Irix RGB image");
740 entry->module=ConstantString("SGI");
741 entry->seekable_stream=MagickTrue;
742 (void) RegisterMagickInfo(entry);
743 return(MagickImageCoderSignature);
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % U n r e g i s t e r S G I I m a g e %
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % UnregisterSGIImage() removes format registrations made by the
758 % SGI module from the list of supported formats.
760 % The format of the UnregisterSGIImage method is:
762 % UnregisterSGIImage(void)
765 ModuleExport void UnregisterSGIImage(void)
767 (void) UnregisterMagickInfo("SGI");
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775 % W r i t e S G I I m a g e %
779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
781 % WriteSGIImage() writes an image in SGI RGB encoded image format.
783 % The format of the WriteSGIImage method is:
785 % MagickBooleanType WriteSGIImage(const ImageInfo *image_info,Image *image)
787 % A description of each parameter follows.
789 % o image_info: the image info.
791 % o image: The image.
795 static size_t SGIEncode(unsigned char *pixels,size_t length,
796 unsigned char *packets)
801 register unsigned char
816 while ((p < limit) && ((*(p-8) != *(p-4)) || (*(p-4) != *p)))
819 length=(size_t) (p-mark) >> 2;
822 runlength=(short) (length > 126 ? 126 : length);
824 *q++=(unsigned char) (0x80 | runlength);
825 for ( ; runlength > 0; runlength--)
833 while ((p < limit) && (*p == *mark))
835 length=(size_t) (p-mark) >> 2;
838 runlength=(short) (length > 126 ? 126 : length);
840 *q++=(unsigned char) runlength;
845 return((size_t) (q-packets));
848 static MagickBooleanType WriteSGIImage(const ImageInfo *image_info,Image *image)
872 register const PixelPacket
879 register unsigned char
887 Open output image file.
889 assert(image_info != (const ImageInfo *) NULL);
890 assert(image_info->signature == MagickSignature);
891 assert(image != (Image *) NULL);
892 assert(image->signature == MagickSignature);
893 if (image->debug != MagickFalse)
894 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
895 if ((image->columns > 65535UL) || (image->rows > 65535UL))
896 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
897 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
898 if (status == MagickFalse)
904 Initialize SGI raster file header.
906 if (image->colorspace != RGBColorspace)
907 (void) TransformImageColorspace(image,RGBColorspace);
908 (void) ResetMagickMemory(&iris_info,0,sizeof(iris_info));
909 iris_info.magic=0x01DA;
910 compression=image->compression;
911 if (image_info->compression != UndefinedCompression)
912 compression=image_info->compression;
913 if (image->depth > 8)
914 compression=NoCompression;
915 if (compression == NoCompression)
916 iris_info.storage=(unsigned char) 0x00;
918 iris_info.storage=(unsigned char) 0x01;
919 iris_info.bytes_per_pixel=(unsigned char) (image->depth > 8 ? 2 : 1);
920 iris_info.dimension=3;
921 iris_info.columns=(unsigned short) image->columns;
922 iris_info.rows=(unsigned short) image->rows;
923 if (image->matte != MagickFalse)
927 if ((image_info->type != TrueColorType) &&
928 (IsGrayImage(image,&image->exception) != MagickFalse))
930 iris_info.dimension=2;
936 iris_info.minimum_value=0;
937 iris_info.maximum_value=(unsigned long) (image->depth <= 8 ?
938 1UL*ScaleQuantumToChar((Quantum) QuantumRange) :
939 1UL*ScaleQuantumToShort((Quantum) QuantumRange));
943 (void) WriteBlobMSBShort(image,iris_info.magic);
944 (void) WriteBlobByte(image,iris_info.storage);
945 (void) WriteBlobByte(image,iris_info.bytes_per_pixel);
946 (void) WriteBlobMSBShort(image,iris_info.dimension);
947 (void) WriteBlobMSBShort(image,iris_info.columns);
948 (void) WriteBlobMSBShort(image,iris_info.rows);
949 (void) WriteBlobMSBShort(image,iris_info.depth);
950 (void) WriteBlobMSBLong(image,iris_info.minimum_value);
951 (void) WriteBlobMSBLong(image,iris_info.maximum_value);
952 (void) WriteBlobMSBLong(image,iris_info.sans);
953 value=GetImageProperty(image,"label");
954 if (value != (const char *) NULL)
955 (void) CopyMagickString(iris_info.name,value,sizeof(iris_info.name));
956 (void) WriteBlob(image,sizeof(iris_info.name),(unsigned char *)
958 (void) WriteBlobMSBLong(image,iris_info.pixel_format);
959 (void) WriteBlob(image,sizeof(iris_info.filler),iris_info.filler);
963 number_pixels=(MagickSizeType) image->columns*image->rows;
964 if ((4*iris_info.bytes_per_pixel*number_pixels) !=
965 ((MagickSizeType) (size_t) (4*iris_info.bytes_per_pixel*number_pixels)))
966 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
967 iris_pixels=(unsigned char *) AcquireQuantumMemory((size_t) number_pixels,
968 4*iris_info.bytes_per_pixel*sizeof(*iris_pixels));
969 if (iris_pixels == (unsigned char *) NULL)
970 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
972 Convert image pixels to uncompressed SGI pixels.
974 for (y=0; y < (long) image->rows; y++)
976 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
977 if (p == (const PixelPacket *) NULL)
979 if (image->depth <= 8)
980 for (x=0; x < (long) image->columns; x++)
982 register unsigned char
985 q=(unsigned char *) iris_pixels;
986 q+=((iris_info.rows-1)-y)*(4*iris_info.columns)+4*x;
987 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
988 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
989 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
990 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
994 for (x=0; x < (long) image->columns; x++)
996 register unsigned short
999 q=(unsigned short *) iris_pixels;
1000 q+=((iris_info.rows-1)-y)*(4*iris_info.columns)+4*x;
1001 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
1002 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
1003 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
1004 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
1007 if (image->previous == (Image *) NULL)
1009 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1010 if (status == MagickFalse)
1014 switch (compression)
1019 Write uncompressed SGI pixels.
1021 for (z=0; z < (long) iris_info.depth; z++)
1023 for (y=0; y < (long) iris_info.rows; y++)
1025 if (image->depth <= 8)
1026 for (x=0; x < (long) iris_info.columns; x++)
1028 register unsigned char
1031 q=(unsigned char *) iris_pixels;
1032 q+=y*(4*iris_info.columns)+4*x+z;
1033 (void) WriteBlobByte(image,*q);
1036 for (x=0; x < (long) iris_info.columns; x++)
1038 register unsigned short
1041 q=(unsigned short *) iris_pixels;
1042 q+=y*(4*iris_info.columns)+4*x+z;
1043 (void) WriteBlobMSBShort(image,*q);
1063 Convert SGI uncompressed pixels.
1065 offsets=(ssize_t *) AcquireQuantumMemory(iris_info.rows*iris_info.depth,
1067 packets=(unsigned char *) AcquireQuantumMemory((2*(size_t)
1068 iris_info.columns+10)*image->rows,4*sizeof(*packets));
1069 runlength=(unsigned long *) AcquireQuantumMemory(iris_info.rows,
1070 iris_info.depth*sizeof(*runlength));
1071 if ((offsets == (ssize_t *) NULL) ||
1072 (packets == (unsigned char *) NULL) ||
1073 (runlength == (unsigned long *) NULL))
1074 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1075 offset=512+4*2*((ssize_t) iris_info.rows*iris_info.depth);
1078 for (y=0; y < (long) iris_info.rows; y++)
1080 for (z=0; z < (long) iris_info.depth; z++)
1082 length=SGIEncode(q+z,(size_t) iris_info.columns,packets+
1084 number_packets+=length;
1085 offsets[y+z*iris_info.rows]=offset;
1086 runlength[y+z*iris_info.rows]=(unsigned long) length;
1087 offset+=(ssize_t) length;
1089 q+=(iris_info.columns*4);
1092 Write out line start and length tables and runlength-encoded pixels.
1094 for (i=0; i < (long) (iris_info.rows*iris_info.depth); i++)
1095 (void) WriteBlobMSBLong(image,(unsigned long) offsets[i]);
1096 for (i=0; i < (long) (iris_info.rows*iris_info.depth); i++)
1097 (void) WriteBlobMSBLong(image,runlength[i]);
1098 (void) WriteBlob(image,number_packets,packets);
1100 Relinquish resources.
1102 runlength=(unsigned long *) RelinquishMagickMemory(runlength);
1103 packets=(unsigned char *) RelinquishMagickMemory(packets);
1104 offsets=(ssize_t *) RelinquishMagickMemory(offsets);
1108 iris_pixels=(unsigned char *) RelinquishMagickMemory(iris_pixels);
1109 if (GetNextImageInList(image) == (Image *) NULL)
1111 image=SyncNextImageInList(image);
1112 status=SetImageProgress(image,SaveImagesTag,scene++,
1113 GetImageListLength(image));
1114 if (status == MagickFalse)
1116 } while (image_info->adjoin != MagickFalse);
1117 (void) CloseBlob(image);