cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % SSSSS GGGG IIIII % |
| 7 | % SS G I % |
| 8 | % SSS G GG I % |
| 9 | % SS G G I % |
| 10 | % SSSSS GGG IIIII % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Irix RGB Image Format % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 51 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 52 | #include "MagickCore/exception.h" |
| 53 | #include "MagickCore/exception-private.h" |
| 54 | #include "MagickCore/image.h" |
| 55 | #include "MagickCore/image-private.h" |
| 56 | #include "MagickCore/list.h" |
| 57 | #include "MagickCore/magick.h" |
| 58 | #include "MagickCore/memory_.h" |
| 59 | #include "MagickCore/monitor.h" |
| 60 | #include "MagickCore/monitor-private.h" |
| 61 | #include "MagickCore/pixel-accessor.h" |
| 62 | #include "MagickCore/property.h" |
| 63 | #include "MagickCore/quantum-private.h" |
| 64 | #include "MagickCore/static.h" |
| 65 | #include "MagickCore/string_.h" |
| 66 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | Typedef declaractions. |
| 70 | */ |
| 71 | typedef struct _SGIInfo |
| 72 | { |
| 73 | unsigned short |
| 74 | magic; |
| 75 | |
| 76 | unsigned char |
| 77 | storage, |
| 78 | bytes_per_pixel; |
| 79 | |
| 80 | unsigned short |
| 81 | dimension, |
| 82 | columns, |
| 83 | rows, |
| 84 | depth; |
| 85 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 86 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 87 | minimum_value, |
| 88 | maximum_value, |
| 89 | sans; |
| 90 | |
| 91 | char |
| 92 | name[80]; |
| 93 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 94 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 95 | pixel_format; |
| 96 | |
| 97 | unsigned char |
| 98 | filler[404]; |
| 99 | } SGIInfo; |
| 100 | |
| 101 | /* |
| 102 | Forward declarations. |
| 103 | */ |
| 104 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 105 | WriteSGIImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | /* |
| 107 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 108 | % % |
| 109 | % % |
| 110 | % % |
| 111 | % I s S G I % |
| 112 | % % |
| 113 | % % |
| 114 | % % |
| 115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 116 | % |
| 117 | % IsSGI() returns MagickTrue if the image format type, identified by the |
| 118 | % magick string, is SGI. |
| 119 | % |
| 120 | % The format of the IsSGI method is: |
| 121 | % |
| 122 | % MagickBooleanType IsSGI(const unsigned char *magick,const size_t length) |
| 123 | % |
| 124 | % A description of each parameter follows: |
| 125 | % |
| 126 | % o magick: compare image format pattern against these bytes. |
| 127 | % |
| 128 | % o length: Specifies the length of the magick string. |
| 129 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 130 | */ |
| 131 | static MagickBooleanType IsSGI(const unsigned char *magick,const size_t length) |
| 132 | { |
| 133 | if (length < 2) |
| 134 | return(MagickFalse); |
| 135 | if (memcmp(magick,"\001\332",2) == 0) |
| 136 | return(MagickTrue); |
| 137 | return(MagickFalse); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 142 | % % |
| 143 | % % |
| 144 | % % |
| 145 | % R e a d S G I I m a g e % |
| 146 | % % |
| 147 | % % |
| 148 | % % |
| 149 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 150 | % |
| 151 | % ReadSGIImage() reads a SGI RGB image file and returns it. It |
| 152 | % allocates the memory necessary for the new Image structure and returns a |
| 153 | % pointer to the new image. |
| 154 | % |
| 155 | % The format of the ReadSGIImage method is: |
| 156 | % |
| 157 | % Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 158 | % |
| 159 | % A description of each parameter follows: |
| 160 | % |
| 161 | % o image_info: the image info. |
| 162 | % |
| 163 | % o exception: return any errors or warnings in this structure. |
| 164 | % |
| 165 | */ |
| 166 | |
| 167 | static inline size_t MagickMin(const size_t x,const size_t y) |
| 168 | { |
| 169 | if (x < y) |
| 170 | return(x); |
| 171 | return(y); |
| 172 | } |
| 173 | |
| 174 | static MagickBooleanType SGIDecode(const size_t bytes_per_pixel, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 175 | ssize_t number_packets,unsigned char *packets,ssize_t number_pixels, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | unsigned char *pixels) |
| 177 | { |
| 178 | register unsigned char |
| 179 | *p, |
| 180 | *q; |
| 181 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 182 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | pixel; |
| 184 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 185 | ssize_t |
| 186 | count; |
| 187 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | p=packets; |
| 189 | q=pixels; |
| 190 | if (bytes_per_pixel == 2) |
| 191 | { |
| 192 | for ( ; number_pixels > 0; ) |
| 193 | { |
| 194 | if (number_packets-- == 0) |
| 195 | return(MagickFalse); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 196 | pixel=(size_t) (*p++) << 8; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 197 | pixel|=(*p++); |
| 198 | count=(ssize_t) (pixel & 0x7f); |
| 199 | if (count == 0) |
| 200 | break; |
| 201 | if (count > (ssize_t) number_pixels) |
| 202 | return(MagickFalse); |
| 203 | number_pixels-=count; |
| 204 | if ((pixel & 0x80) != 0) |
| 205 | for ( ; count != 0; count--) |
| 206 | { |
| 207 | if (number_packets-- == 0) |
| 208 | return(MagickFalse); |
| 209 | *q=(*p++); |
| 210 | *(q+1)=(*p++); |
| 211 | q+=8; |
| 212 | } |
| 213 | else |
| 214 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 215 | pixel=(size_t) (*p++) << 8; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | pixel|=(*p++); |
| 217 | for ( ; count != 0; count--) |
| 218 | { |
| 219 | if (number_packets-- == 0) |
| 220 | return(MagickFalse); |
| 221 | *q=(unsigned char) (pixel >> 8); |
| 222 | *(q+1)=(unsigned char) pixel; |
| 223 | q+=8; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | return(MagickTrue); |
| 228 | } |
| 229 | for ( ; number_pixels > 0; ) |
| 230 | { |
| 231 | if (number_packets-- == 0) |
| 232 | return(MagickFalse); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 233 | pixel=(size_t) (*p++); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | count=(ssize_t) (pixel & 0x7f); |
| 235 | if (count == 0) |
| 236 | break; |
| 237 | if (count > (ssize_t) number_pixels) |
| 238 | return(MagickFalse); |
| 239 | number_pixels-=count; |
| 240 | if ((pixel & 0x80) != 0) |
| 241 | for ( ; count != 0; count--) |
| 242 | { |
| 243 | if (number_packets-- == 0) |
| 244 | return(MagickFalse); |
| 245 | *q=(*p++); |
| 246 | q+=4; |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | if (number_packets-- == 0) |
| 251 | return(MagickFalse); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 252 | pixel=(size_t) (*p++); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 253 | for ( ; count != 0; count--) |
| 254 | { |
| 255 | *q=(unsigned char) pixel; |
| 256 | q+=4; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | return(MagickTrue); |
| 261 | } |
| 262 | |
| 263 | static Image *ReadSGIImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 264 | { |
| 265 | Image |
| 266 | *image; |
| 267 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 268 | MagickBooleanType |
| 269 | status; |
| 270 | |
| 271 | MagickSizeType |
| 272 | number_pixels; |
| 273 | |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 274 | MemoryInfo |
| 275 | *pixel_info; |
| 276 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 277 | register Quantum |
cristy | 667a892 | 2010-12-29 13:43:35 +0000 | [diff] [blame] | 278 | *q; |
| 279 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 280 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 281 | i, |
| 282 | x; |
| 283 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 284 | register unsigned char |
| 285 | *p; |
| 286 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 287 | SGIInfo |
| 288 | iris_info; |
| 289 | |
| 290 | size_t |
cristy | 667a892 | 2010-12-29 13:43:35 +0000 | [diff] [blame] | 291 | bytes_per_pixel, |
| 292 | quantum; |
| 293 | |
| 294 | ssize_t |
| 295 | count, |
| 296 | y, |
| 297 | z; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 298 | |
| 299 | unsigned char |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 300 | *pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 301 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 302 | /* |
| 303 | Open image file. |
| 304 | */ |
| 305 | assert(image_info != (const ImageInfo *) NULL); |
| 306 | assert(image_info->signature == MagickSignature); |
| 307 | if (image_info->debug != MagickFalse) |
| 308 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 309 | image_info->filename); |
| 310 | assert(exception != (ExceptionInfo *) NULL); |
| 311 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 312 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 314 | if (status == MagickFalse) |
| 315 | { |
| 316 | image=DestroyImageList(image); |
| 317 | return((Image *) NULL); |
| 318 | } |
| 319 | /* |
| 320 | Read SGI raster header. |
| 321 | */ |
| 322 | iris_info.magic=ReadBlobMSBShort(image); |
| 323 | do |
| 324 | { |
| 325 | /* |
| 326 | Verify SGI identifier. |
| 327 | */ |
| 328 | if (iris_info.magic != 0x01DA) |
| 329 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 330 | iris_info.storage=(unsigned char) ReadBlobByte(image); |
| 331 | switch (iris_info.storage) |
| 332 | { |
| 333 | case 0x00: image->compression=NoCompression; break; |
| 334 | case 0x01: image->compression=RLECompression; break; |
| 335 | default: |
| 336 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 337 | } |
| 338 | iris_info.bytes_per_pixel=(unsigned char) ReadBlobByte(image); |
| 339 | if ((iris_info.bytes_per_pixel == 0) || (iris_info.bytes_per_pixel > 2)) |
| 340 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 341 | iris_info.dimension=ReadBlobMSBShort(image); |
| 342 | iris_info.columns=ReadBlobMSBShort(image); |
| 343 | iris_info.rows=ReadBlobMSBShort(image); |
| 344 | iris_info.depth=ReadBlobMSBShort(image); |
| 345 | if ((iris_info.depth == 0) || (iris_info.depth > 4)) |
| 346 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 347 | iris_info.minimum_value=ReadBlobMSBLong(image); |
| 348 | iris_info.maximum_value=ReadBlobMSBLong(image); |
| 349 | iris_info.sans=ReadBlobMSBLong(image); |
| 350 | (void) ReadBlob(image,sizeof(iris_info.name),(unsigned char *) |
| 351 | iris_info.name); |
| 352 | iris_info.name[sizeof(iris_info.name)-1]='\0'; |
| 353 | if (*iris_info.name != '\0') |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 354 | (void) SetImageProperty(image,"label",iris_info.name,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 355 | iris_info.pixel_format=ReadBlobMSBLong(image); |
| 356 | if (iris_info.pixel_format != 0) |
| 357 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 358 | count=ReadBlob(image,sizeof(iris_info.filler),iris_info.filler); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 359 | (void) count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 360 | image->columns=iris_info.columns; |
| 361 | image->rows=iris_info.rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 362 | image->depth=(size_t) MagickMin(iris_info.depth,MAGICKCORE_QUANTUM_DEPTH); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | if (iris_info.pixel_format == 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 364 | image->depth=(size_t) MagickMin((size_t) 8* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | iris_info.bytes_per_pixel,MAGICKCORE_QUANTUM_DEPTH); |
| 366 | if (iris_info.depth < 3) |
| 367 | { |
| 368 | image->storage_class=PseudoClass; |
cristy | 667a892 | 2010-12-29 13:43:35 +0000 | [diff] [blame] | 369 | image->colors=iris_info.bytes_per_pixel > 1 ? 65535 : 256; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 370 | } |
| 371 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 372 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 373 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 374 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 375 | if (status == MagickFalse) |
| 376 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 377 | /* |
| 378 | Allocate SGI pixels. |
| 379 | */ |
| 380 | bytes_per_pixel=(size_t) iris_info.bytes_per_pixel; |
| 381 | number_pixels=(MagickSizeType) iris_info.columns*iris_info.rows; |
| 382 | if ((4*bytes_per_pixel*number_pixels) != ((MagickSizeType) (size_t) |
| 383 | (4*bytes_per_pixel*number_pixels))) |
| 384 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 385 | pixel_info=AcquireVirtualMemory(iris_info.columns,iris_info.rows*4* |
| 386 | bytes_per_pixel*sizeof(*pixels)); |
| 387 | if (pixel_info == (MemoryInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 389 | pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 390 | if ((int) iris_info.storage != 0x01) |
| 391 | { |
| 392 | unsigned char |
| 393 | *scanline; |
| 394 | |
| 395 | /* |
| 396 | Read standard image format. |
| 397 | */ |
| 398 | scanline=(unsigned char *) AcquireQuantumMemory(iris_info.columns, |
| 399 | bytes_per_pixel*sizeof(*scanline)); |
| 400 | if (scanline == (unsigned char *) NULL) |
| 401 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 402 | for (z=0; z < (ssize_t) iris_info.depth; z++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 403 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 404 | p=pixels+bytes_per_pixel*z; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 405 | for (y=0; y < (ssize_t) iris_info.rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 406 | { |
| 407 | count=ReadBlob(image,bytes_per_pixel*iris_info.columns,scanline); |
| 408 | if (EOFBlob(image) != MagickFalse) |
| 409 | break; |
| 410 | if (bytes_per_pixel == 2) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 411 | for (x=0; x < (ssize_t) iris_info.columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 412 | { |
| 413 | *p=scanline[2*x]; |
| 414 | *(p+1)=scanline[2*x+1]; |
| 415 | p+=8; |
| 416 | } |
| 417 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 418 | for (x=0; x < (ssize_t) iris_info.columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | { |
| 420 | *p=scanline[x]; |
| 421 | p+=4; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | scanline=(unsigned char *) RelinquishMagickMemory(scanline); |
| 426 | } |
| 427 | else |
| 428 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 429 | MemoryInfo |
| 430 | *packet_info; |
| 431 | |
cristy | 667a892 | 2010-12-29 13:43:35 +0000 | [diff] [blame] | 432 | size_t |
| 433 | *runlength; |
| 434 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 435 | ssize_t |
| 436 | offset, |
| 437 | *offsets; |
| 438 | |
| 439 | unsigned char |
| 440 | *packets; |
| 441 | |
| 442 | unsigned int |
| 443 | data_order; |
| 444 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 445 | /* |
| 446 | Read runlength-encoded image format. |
| 447 | */ |
| 448 | offsets=(ssize_t *) AcquireQuantumMemory((size_t) iris_info.rows, |
| 449 | iris_info.depth*sizeof(*offsets)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 450 | runlength=(size_t *) AcquireQuantumMemory(iris_info.rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | iris_info.depth*sizeof(*runlength)); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 452 | packet_info=AcquireVirtualMemory((size_t) iris_info.columns+10UL,4UL* |
| 453 | sizeof(*packets)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 454 | if ((offsets == (ssize_t *) NULL) || |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 455 | (runlength == (size_t *) NULL) || |
| 456 | (packet_info == (MemoryInfo *) NULL)) |
| 457 | { |
| 458 | if (offsets == (ssize_t *) NULL) |
| 459 | offsets=(ssize_t *) RelinquishMagickMemory(offsets); |
| 460 | if (runlength == (size_t *) NULL) |
| 461 | runlength=(size_t *) RelinquishMagickMemory(runlength); |
| 462 | if (packet_info == (MemoryInfo *) NULL) |
| 463 | packet_info=RelinquishVirtualMemory(packet_info); |
| 464 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 465 | } |
| 466 | packets=(unsigned char *) GetVirtualMemoryBlob(packet_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 467 | for (i=0; i < (ssize_t) (iris_info.rows*iris_info.depth); i++) |
cristy | 6cff05d | 2010-09-02 11:22:46 +0000 | [diff] [blame] | 468 | offsets[i]=(int) ReadBlobMSBLong(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 469 | for (i=0; i < (ssize_t) (iris_info.rows*iris_info.depth); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 470 | { |
| 471 | runlength[i]=ReadBlobMSBLong(image); |
| 472 | if (runlength[i] > (4*(size_t) iris_info.columns+10)) |
| 473 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 474 | } |
| 475 | /* |
| 476 | Check data order. |
| 477 | */ |
| 478 | offset=0; |
| 479 | data_order=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 480 | for (y=0; ((y < (ssize_t) iris_info.rows) && (data_order == 0)); y++) |
| 481 | for (z=0; ((z < (ssize_t) iris_info.depth) && (data_order == 0)); z++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 482 | { |
| 483 | if (offsets[y+z*iris_info.rows] < offset) |
| 484 | data_order=1; |
| 485 | offset=offsets[y+z*iris_info.rows]; |
| 486 | } |
| 487 | offset=(ssize_t) TellBlob(image); |
| 488 | if (data_order == 1) |
| 489 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 490 | for (z=0; z < (ssize_t) iris_info.depth; z++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 491 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 492 | p=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 493 | for (y=0; y < (ssize_t) iris_info.rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 494 | { |
| 495 | if (offset != offsets[y+z*iris_info.rows]) |
| 496 | { |
| 497 | offset=offsets[y+z*iris_info.rows]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 498 | offset=(ssize_t) SeekBlob(image,(ssize_t) offset,SEEK_SET); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 499 | } |
| 500 | count=ReadBlob(image,(size_t) runlength[y+z*iris_info.rows], |
| 501 | packets); |
| 502 | if (EOFBlob(image) != MagickFalse) |
| 503 | break; |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 504 | offset+=(ssize_t) runlength[y+z*iris_info.rows]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 505 | status=SGIDecode(bytes_per_pixel,(ssize_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 506 | (runlength[y+z*iris_info.rows]/bytes_per_pixel),packets, |
| 507 | 1L*iris_info.columns,p+bytes_per_pixel*z); |
| 508 | if (status == MagickFalse) |
| 509 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 510 | p+=(iris_info.columns*4*bytes_per_pixel); |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | MagickOffsetType |
| 517 | position; |
| 518 | |
| 519 | position=TellBlob(image); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 520 | p=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 521 | for (y=0; y < (ssize_t) iris_info.rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 522 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 523 | for (z=0; z < (ssize_t) iris_info.depth; z++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | { |
| 525 | if (offset != offsets[y+z*iris_info.rows]) |
| 526 | { |
| 527 | offset=offsets[y+z*iris_info.rows]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 528 | offset=(ssize_t) SeekBlob(image,(ssize_t) offset,SEEK_SET); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 529 | } |
| 530 | count=ReadBlob(image,(size_t) runlength[y+z*iris_info.rows], |
| 531 | packets); |
| 532 | if (EOFBlob(image) != MagickFalse) |
| 533 | break; |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 534 | offset+=(ssize_t) runlength[y+z*iris_info.rows]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 535 | status=SGIDecode(bytes_per_pixel,(ssize_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 536 | (runlength[y+z*iris_info.rows]/bytes_per_pixel),packets, |
| 537 | 1L*iris_info.columns,p+bytes_per_pixel*z); |
| 538 | if (status == MagickFalse) |
| 539 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 540 | } |
| 541 | p+=(iris_info.columns*4*bytes_per_pixel); |
| 542 | } |
| 543 | offset=(ssize_t) SeekBlob(image,position,SEEK_SET); |
| 544 | } |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 545 | packet_info=RelinquishVirtualMemory(packet_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 546 | runlength=(size_t *) RelinquishMagickMemory(runlength); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 547 | offsets=(ssize_t *) RelinquishMagickMemory(offsets); |
| 548 | } |
| 549 | /* |
| 550 | Initialize image structure. |
| 551 | */ |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 552 | image->alpha_trait=iris_info.depth == 4 ? BlendPixelTrait : |
| 553 | UndefinedPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | image->columns=iris_info.columns; |
| 555 | image->rows=iris_info.rows; |
| 556 | /* |
| 557 | Convert SGI raster image to pixel packets. |
| 558 | */ |
| 559 | if (image->storage_class == DirectClass) |
| 560 | { |
| 561 | /* |
| 562 | Convert SGI image to DirectClass pixel packets. |
| 563 | */ |
| 564 | if (bytes_per_pixel == 2) |
| 565 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 566 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 568 | p=pixels+(image->rows-y-1)*8*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 569 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 570 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 571 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 572 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 573 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 574 | SetPixelRed(image,ScaleShortToQuantum((unsigned short) |
| 575 | ((*(p+0) << 8) | (*(p+1)))),q); |
| 576 | SetPixelGreen(image,ScaleShortToQuantum((unsigned short) |
| 577 | ((*(p+2) << 8) | (*(p+3)))),q); |
| 578 | SetPixelBlue(image,ScaleShortToQuantum((unsigned short) |
| 579 | ((*(p+4) << 8) | (*(p+5)))),q); |
| 580 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame^] | 581 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 582 | SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) |
| 583 | ((*(p+6) << 8) | (*(p+7)))),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | p+=8; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 585 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 586 | } |
| 587 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 588 | break; |
| 589 | if (image->previous == (Image *) NULL) |
| 590 | { |
cristy | 667a892 | 2010-12-29 13:43:35 +0000 | [diff] [blame] | 591 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 592 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 593 | if (status == MagickFalse) |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 599 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 601 | p=pixels+(image->rows-y-1)*4*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 602 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 603 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 604 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 605 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 606 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 607 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 608 | SetPixelGreen(image,ScaleCharToQuantum(*(p+1)),q); |
| 609 | SetPixelBlue(image,ScaleCharToQuantum(*(p+2)),q); |
| 610 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame^] | 611 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 612 | SetPixelAlpha(image,ScaleCharToQuantum(*(p+3)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | p+=4; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 614 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 615 | } |
| 616 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 617 | break; |
| 618 | if (image->previous == (Image *) NULL) |
| 619 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 620 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 621 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 622 | if (status == MagickFalse) |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | /* |
| 630 | Create grayscale map. |
| 631 | */ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 632 | if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 633 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 634 | /* |
| 635 | Convert SGI image to PseudoClass pixel packets. |
| 636 | */ |
| 637 | if (bytes_per_pixel == 2) |
| 638 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 639 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 640 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 641 | p=pixels+(image->rows-y-1)*8*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 642 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 643 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 645 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 646 | { |
| 647 | quantum=(*p << 8); |
| 648 | quantum|=(*(p+1)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 649 | SetPixelIndex(image,quantum,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 650 | p+=8; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 651 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 652 | } |
| 653 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 654 | break; |
| 655 | if (image->previous == (Image *) NULL) |
| 656 | { |
cristy | 667a892 | 2010-12-29 13:43:35 +0000 | [diff] [blame] | 657 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 658 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | if (status == MagickFalse) |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 665 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 666 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 667 | p=pixels+(image->rows-y-1)*4*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 669 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 671 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 672 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 673 | SetPixelIndex(image,*p,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | p+=4; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 675 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 676 | } |
| 677 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 678 | break; |
| 679 | if (image->previous == (Image *) NULL) |
| 680 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 681 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 682 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 683 | if (status == MagickFalse) |
| 684 | break; |
| 685 | } |
| 686 | } |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 687 | (void) SyncImage(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 688 | } |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 689 | pixel_info=RelinquishVirtualMemory(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 690 | if (EOFBlob(image) != MagickFalse) |
| 691 | { |
| 692 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 693 | image->filename); |
| 694 | break; |
| 695 | } |
| 696 | /* |
| 697 | Proceed to next image. |
| 698 | */ |
| 699 | if (image_info->number_scenes != 0) |
| 700 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 701 | break; |
| 702 | iris_info.magic=ReadBlobMSBShort(image); |
| 703 | if (iris_info.magic == 0x01DA) |
| 704 | { |
| 705 | /* |
| 706 | Allocate next image structure. |
| 707 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 708 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 709 | if (GetNextImageInList(image) == (Image *) NULL) |
| 710 | { |
| 711 | image=DestroyImageList(image); |
| 712 | return((Image *) NULL); |
| 713 | } |
| 714 | image=SyncNextImageInList(image); |
| 715 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 716 | GetBlobSize(image)); |
| 717 | if (status == MagickFalse) |
| 718 | break; |
| 719 | } |
| 720 | } while (iris_info.magic == 0x01DA); |
| 721 | (void) CloseBlob(image); |
| 722 | return(GetFirstImageInList(image)); |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 727 | % % |
| 728 | % % |
| 729 | % % |
| 730 | % R e g i s t e r S G I I m a g e % |
| 731 | % % |
| 732 | % % |
| 733 | % % |
| 734 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 735 | % |
| 736 | % RegisterSGIImage() adds properties for the SGI image format to |
| 737 | % the list of supported formats. The properties include the image format |
| 738 | % tag, a method to read and/or write the format, whether the format |
| 739 | % supports the saving of more than one frame to the same file or blob, |
| 740 | % whether the format supports native in-memory I/O, and a brief |
| 741 | % description of the format. |
| 742 | % |
| 743 | % The format of the RegisterSGIImage method is: |
| 744 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 745 | % size_t RegisterSGIImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 746 | % |
| 747 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 748 | ModuleExport size_t RegisterSGIImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 749 | { |
| 750 | MagickInfo |
| 751 | *entry; |
| 752 | |
| 753 | entry=SetMagickInfo("SGI"); |
| 754 | entry->decoder=(DecodeImageHandler *) ReadSGIImage; |
| 755 | entry->encoder=(EncodeImageHandler *) WriteSGIImage; |
| 756 | entry->magick=(IsImageFormatHandler *) IsSGI; |
| 757 | entry->description=ConstantString("Irix RGB image"); |
| 758 | entry->module=ConstantString("SGI"); |
| 759 | entry->seekable_stream=MagickTrue; |
| 760 | (void) RegisterMagickInfo(entry); |
| 761 | return(MagickImageCoderSignature); |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 766 | % % |
| 767 | % % |
| 768 | % % |
| 769 | % U n r e g i s t e r S G I I m a g e % |
| 770 | % % |
| 771 | % % |
| 772 | % % |
| 773 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 774 | % |
| 775 | % UnregisterSGIImage() removes format registrations made by the |
| 776 | % SGI module from the list of supported formats. |
| 777 | % |
| 778 | % The format of the UnregisterSGIImage method is: |
| 779 | % |
| 780 | % UnregisterSGIImage(void) |
| 781 | % |
| 782 | */ |
| 783 | ModuleExport void UnregisterSGIImage(void) |
| 784 | { |
| 785 | (void) UnregisterMagickInfo("SGI"); |
| 786 | } |
| 787 | |
| 788 | /* |
| 789 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 790 | % % |
| 791 | % % |
| 792 | % % |
| 793 | % W r i t e S G I I m a g e % |
| 794 | % % |
| 795 | % % |
| 796 | % % |
| 797 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 798 | % |
| 799 | % WriteSGIImage() writes an image in SGI RGB encoded image format. |
| 800 | % |
| 801 | % The format of the WriteSGIImage method is: |
| 802 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 803 | % MagickBooleanType WriteSGIImage(const ImageInfo *image_info, |
| 804 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 805 | % |
| 806 | % A description of each parameter follows. |
| 807 | % |
| 808 | % o image_info: the image info. |
| 809 | % |
| 810 | % o image: The image. |
| 811 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 812 | % o exception: return any errors or warnings in this structure. |
| 813 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 814 | */ |
| 815 | |
| 816 | static size_t SGIEncode(unsigned char *pixels,size_t length, |
| 817 | unsigned char *packets) |
| 818 | { |
| 819 | short |
| 820 | runlength; |
| 821 | |
| 822 | register unsigned char |
| 823 | *p, |
| 824 | *q; |
| 825 | |
| 826 | unsigned char |
| 827 | *limit, |
| 828 | *mark; |
| 829 | |
| 830 | p=pixels; |
| 831 | limit=p+length*4; |
| 832 | q=packets; |
| 833 | while (p < limit) |
| 834 | { |
| 835 | mark=p; |
| 836 | p+=8; |
| 837 | while ((p < limit) && ((*(p-8) != *(p-4)) || (*(p-4) != *p))) |
| 838 | p+=4; |
| 839 | p-=8; |
| 840 | length=(size_t) (p-mark) >> 2; |
| 841 | while (length != 0) |
| 842 | { |
| 843 | runlength=(short) (length > 126 ? 126 : length); |
| 844 | length-=runlength; |
| 845 | *q++=(unsigned char) (0x80 | runlength); |
| 846 | for ( ; runlength > 0; runlength--) |
| 847 | { |
| 848 | *q++=(*mark); |
| 849 | mark+=4; |
| 850 | } |
| 851 | } |
| 852 | mark=p; |
| 853 | p+=4; |
| 854 | while ((p < limit) && (*p == *mark)) |
| 855 | p+=4; |
| 856 | length=(size_t) (p-mark) >> 2; |
| 857 | while (length != 0) |
| 858 | { |
| 859 | runlength=(short) (length > 126 ? 126 : length); |
| 860 | length-=runlength; |
| 861 | *q++=(unsigned char) runlength; |
| 862 | *q++=(*mark); |
| 863 | } |
| 864 | } |
| 865 | *q++='\0'; |
| 866 | return((size_t) (q-packets)); |
| 867 | } |
| 868 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 869 | static MagickBooleanType WriteSGIImage(const ImageInfo *image_info,Image *image, |
| 870 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 871 | { |
| 872 | CompressionType |
| 873 | compression; |
| 874 | |
| 875 | const char |
| 876 | *value; |
| 877 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 878 | MagickBooleanType |
| 879 | status; |
| 880 | |
| 881 | MagickOffsetType |
| 882 | scene; |
| 883 | |
| 884 | MagickSizeType |
| 885 | number_pixels; |
| 886 | |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 887 | MemoryInfo |
| 888 | *pixel_info; |
| 889 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 890 | SGIInfo |
| 891 | iris_info; |
| 892 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 893 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 894 | *p; |
| 895 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 896 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 897 | i, |
| 898 | x; |
| 899 | |
| 900 | register unsigned char |
| 901 | *q; |
| 902 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 903 | ssize_t |
| 904 | y, |
| 905 | z; |
| 906 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 907 | unsigned char |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 908 | *pixels, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 909 | *packets; |
| 910 | |
| 911 | /* |
| 912 | Open output image file. |
| 913 | */ |
| 914 | assert(image_info != (const ImageInfo *) NULL); |
| 915 | assert(image_info->signature == MagickSignature); |
| 916 | assert(image != (Image *) NULL); |
| 917 | assert(image->signature == MagickSignature); |
| 918 | if (image->debug != MagickFalse) |
| 919 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 920 | if ((image->columns > 65535UL) || (image->rows > 65535UL)) |
| 921 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 922 | assert(exception != (ExceptionInfo *) NULL); |
| 923 | assert(exception->signature == MagickSignature); |
| 924 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 925 | if (status == MagickFalse) |
| 926 | return(status); |
| 927 | scene=0; |
| 928 | do |
| 929 | { |
| 930 | /* |
| 931 | Initialize SGI raster file header. |
| 932 | */ |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 933 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 934 | (void) ResetMagickMemory(&iris_info,0,sizeof(iris_info)); |
| 935 | iris_info.magic=0x01DA; |
| 936 | compression=image->compression; |
| 937 | if (image_info->compression != UndefinedCompression) |
| 938 | compression=image_info->compression; |
| 939 | if (image->depth > 8) |
| 940 | compression=NoCompression; |
| 941 | if (compression == NoCompression) |
| 942 | iris_info.storage=(unsigned char) 0x00; |
| 943 | else |
| 944 | iris_info.storage=(unsigned char) 0x01; |
| 945 | iris_info.bytes_per_pixel=(unsigned char) (image->depth > 8 ? 2 : 1); |
| 946 | iris_info.dimension=3; |
| 947 | iris_info.columns=(unsigned short) image->columns; |
| 948 | iris_info.rows=(unsigned short) image->rows; |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame^] | 949 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 950 | iris_info.depth=4; |
| 951 | else |
| 952 | { |
| 953 | if ((image_info->type != TrueColorType) && |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 954 | (IsImageGray(image,exception) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 955 | { |
| 956 | iris_info.dimension=2; |
| 957 | iris_info.depth=1; |
| 958 | } |
| 959 | else |
| 960 | iris_info.depth=3; |
| 961 | } |
| 962 | iris_info.minimum_value=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 963 | iris_info.maximum_value=(size_t) (image->depth <= 8 ? |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 964 | 1UL*ScaleQuantumToChar(QuantumRange) : |
| 965 | 1UL*ScaleQuantumToShort(QuantumRange)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 966 | /* |
| 967 | Write SGI header. |
| 968 | */ |
| 969 | (void) WriteBlobMSBShort(image,iris_info.magic); |
| 970 | (void) WriteBlobByte(image,iris_info.storage); |
| 971 | (void) WriteBlobByte(image,iris_info.bytes_per_pixel); |
| 972 | (void) WriteBlobMSBShort(image,iris_info.dimension); |
| 973 | (void) WriteBlobMSBShort(image,iris_info.columns); |
| 974 | (void) WriteBlobMSBShort(image,iris_info.rows); |
| 975 | (void) WriteBlobMSBShort(image,iris_info.depth); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 976 | (void) WriteBlobMSBLong(image,(unsigned int) iris_info.minimum_value); |
| 977 | (void) WriteBlobMSBLong(image,(unsigned int) iris_info.maximum_value); |
| 978 | (void) WriteBlobMSBLong(image,(unsigned int) iris_info.sans); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 979 | value=GetImageProperty(image,"label",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 980 | if (value != (const char *) NULL) |
| 981 | (void) CopyMagickString(iris_info.name,value,sizeof(iris_info.name)); |
| 982 | (void) WriteBlob(image,sizeof(iris_info.name),(unsigned char *) |
| 983 | iris_info.name); |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 984 | (void) WriteBlobMSBLong(image,(unsigned int) iris_info.pixel_format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 985 | (void) WriteBlob(image,sizeof(iris_info.filler),iris_info.filler); |
| 986 | /* |
| 987 | Allocate SGI pixels. |
| 988 | */ |
| 989 | number_pixels=(MagickSizeType) image->columns*image->rows; |
| 990 | if ((4*iris_info.bytes_per_pixel*number_pixels) != |
| 991 | ((MagickSizeType) (size_t) (4*iris_info.bytes_per_pixel*number_pixels))) |
| 992 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 993 | pixel_info=AcquireVirtualMemory((size_t) number_pixels,4* |
| 994 | iris_info.bytes_per_pixel*sizeof(*pixels)); |
| 995 | if (pixel_info == (MemoryInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 996 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 997 | pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 998 | /* |
| 999 | Convert image pixels to uncompressed SGI pixels. |
| 1000 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1001 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1002 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1003 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1004 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1005 | break; |
| 1006 | if (image->depth <= 8) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1007 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1008 | { |
| 1009 | register unsigned char |
| 1010 | *q; |
| 1011 | |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1012 | q=(unsigned char *) pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1013 | q+=((iris_info.rows-1)-y)*(4*iris_info.columns)+4*x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1014 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1015 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1016 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 1017 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1018 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | } |
| 1020 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1021 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1022 | { |
| 1023 | register unsigned short |
| 1024 | *q; |
| 1025 | |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1026 | q=(unsigned short *) pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1027 | q+=((iris_info.rows-1)-y)*(4*iris_info.columns)+4*x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1028 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1029 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1030 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1031 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1032 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1033 | } |
| 1034 | if (image->previous == (Image *) NULL) |
| 1035 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1036 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 1037 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1038 | if (status == MagickFalse) |
| 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | switch (compression) |
| 1043 | { |
| 1044 | case NoCompression: |
| 1045 | { |
| 1046 | /* |
| 1047 | Write uncompressed SGI pixels. |
| 1048 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1049 | for (z=0; z < (ssize_t) iris_info.depth; z++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1050 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1051 | for (y=0; y < (ssize_t) iris_info.rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1052 | { |
| 1053 | if (image->depth <= 8) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1054 | for (x=0; x < (ssize_t) iris_info.columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1055 | { |
| 1056 | register unsigned char |
| 1057 | *q; |
| 1058 | |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1059 | q=(unsigned char *) pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | q+=y*(4*iris_info.columns)+4*x+z; |
| 1061 | (void) WriteBlobByte(image,*q); |
| 1062 | } |
| 1063 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1064 | for (x=0; x < (ssize_t) iris_info.columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1065 | { |
| 1066 | register unsigned short |
| 1067 | *q; |
| 1068 | |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1069 | q=(unsigned short *) pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1070 | q+=y*(4*iris_info.columns)+4*x+z; |
| 1071 | (void) WriteBlobMSBShort(image,*q); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | break; |
| 1076 | } |
| 1077 | default: |
| 1078 | { |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1079 | MemoryInfo |
| 1080 | *packet_info; |
| 1081 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 1082 | size_t |
| 1083 | length, |
| 1084 | number_packets, |
| 1085 | *runlength; |
| 1086 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1087 | ssize_t |
| 1088 | offset, |
| 1089 | *offsets; |
| 1090 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1091 | /* |
| 1092 | Convert SGI uncompressed pixels. |
| 1093 | */ |
cristy | fa6de8c | 2014-05-18 16:34:44 +0000 | [diff] [blame] | 1094 | offsets=(ssize_t *) AcquireQuantumMemory(iris_info.rows, |
| 1095 | iris_info.depth*sizeof(*offsets)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1096 | runlength=(size_t *) AcquireQuantumMemory(iris_info.rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1097 | iris_info.depth*sizeof(*runlength)); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1098 | packet_info=AcquireVirtualMemory((2*(size_t) iris_info.columns+10)* |
| 1099 | image->rows,4*sizeof(*packets)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1100 | if ((offsets == (ssize_t *) NULL) || |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1101 | (runlength == (size_t *) NULL) || |
| 1102 | (packet_info == (MemoryInfo *) NULL)) |
| 1103 | { |
| 1104 | if (offsets != (ssize_t *) NULL) |
| 1105 | offsets=(ssize_t *) RelinquishMagickMemory(offsets); |
| 1106 | if (runlength != (size_t *) NULL) |
| 1107 | runlength=(size_t *) RelinquishMagickMemory(runlength); |
| 1108 | if (packet_info != (MemoryInfo *) NULL) |
| 1109 | packet_info=RelinquishVirtualMemory(packet_info); |
| 1110 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1111 | } |
| 1112 | packets=(unsigned char *) GetVirtualMemoryBlob(packet_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1113 | offset=512+4*2*((ssize_t) iris_info.rows*iris_info.depth); |
| 1114 | number_packets=0; |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1115 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1116 | for (y=0; y < (ssize_t) iris_info.rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1117 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1118 | for (z=0; z < (ssize_t) iris_info.depth; z++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1119 | { |
| 1120 | length=SGIEncode(q+z,(size_t) iris_info.columns,packets+ |
| 1121 | number_packets); |
| 1122 | number_packets+=length; |
| 1123 | offsets[y+z*iris_info.rows]=offset; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1124 | runlength[y+z*iris_info.rows]=(size_t) length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1125 | offset+=(ssize_t) length; |
| 1126 | } |
| 1127 | q+=(iris_info.columns*4); |
| 1128 | } |
| 1129 | /* |
| 1130 | Write out line start and length tables and runlength-encoded pixels. |
| 1131 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1132 | for (i=0; i < (ssize_t) (iris_info.rows*iris_info.depth); i++) |
cristy | f9cca6a | 2010-06-04 23:49:28 +0000 | [diff] [blame] | 1133 | (void) WriteBlobMSBLong(image,(unsigned int) offsets[i]); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1134 | for (i=0; i < (ssize_t) (iris_info.rows*iris_info.depth); i++) |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 1135 | (void) WriteBlobMSBLong(image,(unsigned int) runlength[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1136 | (void) WriteBlob(image,number_packets,packets); |
| 1137 | /* |
| 1138 | Relinquish resources. |
| 1139 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1140 | offsets=(ssize_t *) RelinquishMagickMemory(offsets); |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1141 | runlength=(size_t *) RelinquishMagickMemory(runlength); |
| 1142 | packet_info=RelinquishVirtualMemory(packet_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1143 | break; |
| 1144 | } |
| 1145 | } |
cristy | b64823d | 2013-06-30 20:58:24 +0000 | [diff] [blame] | 1146 | pixel_info=RelinquishVirtualMemory(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1147 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1148 | break; |
| 1149 | image=SyncNextImageInList(image); |
| 1150 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 1151 | GetImageListLength(image)); |
| 1152 | if (status == MagickFalse) |
| 1153 | break; |
| 1154 | } while (image_info->adjoin != MagickFalse); |
| 1155 | (void) CloseBlob(image); |
| 1156 | return(MagickTrue); |
| 1157 | } |