cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % AAA V V SSSSS % |
| 7 | % A A V V SS % |
| 8 | % AAAAA V V SSS % |
| 9 | % A A V V SS % |
| 10 | % A A V SSSSS % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write AVS X 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 | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 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/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 47 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/image.h" |
| 51 | #include "MagickCore/image-private.h" |
| 52 | #include "MagickCore/list.h" |
| 53 | #include "MagickCore/magick.h" |
| 54 | #include "MagickCore/memory_.h" |
| 55 | #include "MagickCore/monitor.h" |
| 56 | #include "MagickCore/monitor-private.h" |
| 57 | #include "MagickCore/pixel-accessor.h" |
| 58 | #include "MagickCore/quantum-private.h" |
| 59 | #include "MagickCore/static.h" |
| 60 | #include "MagickCore/string_.h" |
| 61 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | Forward declarations. |
| 65 | */ |
| 66 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 67 | WriteAVSImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 71 | % % |
| 72 | % % |
| 73 | % % |
| 74 | % R e a d A V S I m a g e % |
| 75 | % % |
| 76 | % % |
| 77 | % % |
| 78 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 79 | % |
| 80 | % ReadAVSImage() reads an AVS X image file and returns it. It |
| 81 | % allocates the memory necessary for the new Image structure and returns a |
| 82 | % pointer to the new image. |
| 83 | % |
| 84 | % The format of the ReadAVSImage method is: |
| 85 | % |
| 86 | % Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 87 | % |
| 88 | % A description of each parameter follows: |
| 89 | % |
| 90 | % o image_info: the image info. |
| 91 | % |
| 92 | % o exception: return any errors or warnings in this structure. |
| 93 | % |
| 94 | */ |
| 95 | static Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 96 | { |
| 97 | Image |
| 98 | *image; |
| 99 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 100 | MagickBooleanType |
| 101 | status; |
| 102 | |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 103 | MemoryInfo |
| 104 | *pixel_info; |
| 105 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 106 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 107 | *q; |
| 108 | |
cristy | bdadf31 | 2011-04-23 23:16:21 +0000 | [diff] [blame] | 109 | register ssize_t |
| 110 | x; |
| 111 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | register unsigned char |
| 113 | *p; |
| 114 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 115 | size_t |
cristy | e179ce2 | 2010-09-16 23:46:34 +0000 | [diff] [blame] | 116 | height, |
| 117 | length, |
| 118 | width; |
| 119 | |
| 120 | ssize_t |
| 121 | count, |
| 122 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | |
| 124 | unsigned char |
| 125 | *pixels; |
| 126 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 127 | /* |
| 128 | Open image file. |
| 129 | */ |
| 130 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 131 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 132 | if (image_info->debug != MagickFalse) |
| 133 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 134 | image_info->filename); |
| 135 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 136 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 137 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 138 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 139 | if (status == MagickFalse) |
| 140 | { |
| 141 | image=DestroyImageList(image); |
| 142 | return((Image *) NULL); |
| 143 | } |
| 144 | /* |
| 145 | Read AVS X image. |
| 146 | */ |
| 147 | width=ReadBlobMSBLong(image); |
| 148 | height=ReadBlobMSBLong(image); |
| 149 | if (EOFBlob(image) != MagickFalse) |
| 150 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 151 | if ((width == 0UL) || (height == 0UL)) |
| 152 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 153 | do |
| 154 | { |
| 155 | /* |
| 156 | Convert AVS raster image to pixel packets. |
| 157 | */ |
| 158 | image->columns=width; |
| 159 | image->rows=height; |
| 160 | image->depth=8; |
| 161 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 162 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 163 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 164 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 165 | if (status == MagickFalse) |
| 166 | return(DestroyImageList(image)); |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 167 | pixel_info=AcquireVirtualMemory(image->columns,4*sizeof(*pixels)); |
| 168 | if (pixel_info == (MemoryInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 170 | pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | length=(size_t) 4*image->columns; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 172 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | { |
| 174 | count=ReadBlob(image,length,pixels); |
| 175 | if ((size_t) count != length) |
| 176 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 177 | p=pixels; |
| 178 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 179 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 181 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 183 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 184 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 185 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 186 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
cristy | 95adade | 2015-01-31 01:51:55 +0000 | [diff] [blame] | 187 | if (GetPixelAlpha(image,q) != OpaqueAlpha) |
| 188 | image->alpha_trait=BlendPixelTrait; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 189 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | } |
| 191 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 192 | break; |
cristy | bdadf31 | 2011-04-23 23:16:21 +0000 | [diff] [blame] | 193 | if (image->previous == (Image *) NULL) |
| 194 | { |
| 195 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 196 | image->rows); |
| 197 | if (status == MagickFalse) |
| 198 | break; |
| 199 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | } |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 201 | pixel_info=RelinquishVirtualMemory(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | if (EOFBlob(image) != MagickFalse) |
| 203 | { |
| 204 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 205 | image->filename); |
| 206 | break; |
| 207 | } |
| 208 | /* |
| 209 | Proceed to next image. |
| 210 | */ |
| 211 | if (image_info->number_scenes != 0) |
| 212 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 213 | break; |
| 214 | width=ReadBlobMSBLong(image); |
| 215 | height=ReadBlobMSBLong(image); |
| 216 | if ((width != 0UL) && (height != 0UL)) |
| 217 | { |
| 218 | /* |
| 219 | Allocate next image structure. |
| 220 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 221 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 222 | if (GetNextImageInList(image) == (Image *) NULL) |
| 223 | { |
| 224 | image=DestroyImageList(image); |
| 225 | return((Image *) NULL); |
| 226 | } |
| 227 | image=SyncNextImageInList(image); |
| 228 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 229 | GetBlobSize(image)); |
| 230 | if (status == MagickFalse) |
| 231 | break; |
| 232 | } |
| 233 | } while ((width != 0UL) && (height != 0UL)); |
| 234 | (void) CloseBlob(image); |
| 235 | return(GetFirstImageInList(image)); |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 240 | % % |
| 241 | % % |
| 242 | % % |
| 243 | % R e g i s t e r A V S I m a g e % |
| 244 | % % |
| 245 | % % |
| 246 | % % |
| 247 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 248 | % |
| 249 | % RegisterAVSImage() adds attributes for the AVS X image format to the list |
| 250 | % of supported formats. The attributes include the image format tag, a |
| 251 | % method to read and/or write the format, whether the format supports the |
| 252 | % saving of more than one frame to the same file or blob, whether the format |
| 253 | % supports native in-memory I/O, and a brief description of the format. |
| 254 | % |
| 255 | % The format of the RegisterAVSImage method is: |
| 256 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 257 | % size_t RegisterAVSImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 258 | % |
| 259 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 260 | ModuleExport size_t RegisterAVSImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 261 | { |
| 262 | MagickInfo |
| 263 | *entry; |
| 264 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 265 | entry=AcquireMagickInfo("AVS","AVS","AVS X image"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | entry->decoder=(DecodeImageHandler *) ReadAVSImage; |
| 267 | entry->encoder=(EncodeImageHandler *) WriteAVSImage; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 268 | (void) RegisterMagickInfo(entry); |
| 269 | return(MagickImageCoderSignature); |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 274 | % % |
| 275 | % % |
| 276 | % % |
| 277 | % U n r e g i s t e r A V S I m a g e % |
| 278 | % % |
| 279 | % % |
| 280 | % % |
| 281 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 282 | % |
| 283 | % UnregisterAVSImage() removes format registrations made by the |
| 284 | % AVS module from the list of supported formats. |
| 285 | % |
| 286 | % The format of the UnregisterAVSImage method is: |
| 287 | % |
| 288 | % UnregisterAVSImage(void) |
| 289 | % |
| 290 | */ |
| 291 | ModuleExport void UnregisterAVSImage(void) |
| 292 | { |
| 293 | (void) UnregisterMagickInfo("AVS"); |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 298 | % % |
| 299 | % % |
| 300 | % % |
| 301 | % W r i t e A V S I m a g e % |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 306 | % |
| 307 | % WriteAVSImage() writes an image to a file in AVS X image format. |
| 308 | % |
| 309 | % The format of the WriteAVSImage method is: |
| 310 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 311 | % MagickBooleanType WriteAVSImage(const ImageInfo *image_info, |
| 312 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | % |
| 314 | % A description of each parameter follows. |
| 315 | % |
| 316 | % o image_info: the image info. |
| 317 | % |
| 318 | % o image: The image. |
| 319 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 320 | % o exception: return any errors or warnings in this structure. |
| 321 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | */ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 323 | static MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image, |
| 324 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 325 | { |
| 326 | MagickBooleanType |
| 327 | status; |
| 328 | |
| 329 | MagickOffsetType |
| 330 | scene; |
| 331 | |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 332 | MemoryInfo |
| 333 | *pixel_info; |
| 334 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 335 | register const Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 336 | *magick_restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 337 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 338 | register ssize_t |
cristy | 3f2302b | 2010-03-11 03:16:37 +0000 | [diff] [blame] | 339 | x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 340 | |
| 341 | register unsigned char |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 342 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 343 | |
| 344 | ssize_t |
cristy | eda6083 | 2010-09-17 00:00:24 +0000 | [diff] [blame] | 345 | count, |
| 346 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 347 | |
| 348 | unsigned char |
| 349 | *pixels; |
| 350 | |
| 351 | /* |
| 352 | Open output image file. |
| 353 | */ |
| 354 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 355 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 356 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 357 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 358 | if (image->debug != MagickFalse) |
| 359 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 360 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 361 | assert(exception->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 362 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | if (status == MagickFalse) |
| 364 | return(status); |
| 365 | scene=0; |
| 366 | do |
| 367 | { |
| 368 | /* |
| 369 | Write AVS header. |
| 370 | */ |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 371 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 372 | (void) WriteBlobMSBLong(image,(unsigned int) image->columns); |
| 373 | (void) WriteBlobMSBLong(image,(unsigned int) image->rows); |
| 374 | /* |
| 375 | Allocate memory for pixels. |
| 376 | */ |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 377 | pixel_info=AcquireVirtualMemory(image->columns,4*sizeof(*pixels)); |
| 378 | if (pixel_info == (MemoryInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 380 | pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 381 | /* |
| 382 | Convert MIFF to AVS raster pixels. |
| 383 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 384 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 385 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 386 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 387 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | break; |
| 389 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 390 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | { |
cristy | 0553bd5 | 2013-06-30 15:53:50 +0000 | [diff] [blame] | 392 | *q++=ScaleQuantumToChar((Quantum) (image->alpha_trait == |
| 393 | BlendPixelTrait ? GetPixelAlpha(image,p) : OpaqueAlpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 394 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 395 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 396 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 397 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 398 | } |
| 399 | count=WriteBlob(image,(size_t) (q-pixels),pixels); |
| 400 | if (count != (ssize_t) (q-pixels)) |
| 401 | break; |
cristy | bdadf31 | 2011-04-23 23:16:21 +0000 | [diff] [blame] | 402 | if (image->previous == (Image *) NULL) |
| 403 | { |
| 404 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 405 | image->rows); |
| 406 | if (status == MagickFalse) |
| 407 | break; |
| 408 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | } |
cristy | 3138126 | 2015-06-19 18:38:04 +0000 | [diff] [blame] | 410 | pixel_info=RelinquishVirtualMemory(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 411 | if (GetNextImageInList(image) == (Image *) NULL) |
| 412 | break; |
| 413 | image=SyncNextImageInList(image); |
| 414 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 415 | GetImageListLength(image)); |
| 416 | if (status == MagickFalse) |
| 417 | break; |
| 418 | } while (image_info->adjoin != MagickFalse); |
| 419 | (void) CloseBlob(image); |
| 420 | return(MagickTrue); |
| 421 | } |