cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % M M TTTTT V V % |
| 7 | % MM MM T V V % |
| 8 | % M M M T V V % |
| 9 | % M M T V V % |
| 10 | % M M T V % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write MTV Raytracer 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 | d842011 | 2021-01-01 14:52:00 -0500 | [diff] [blame] | 20 | % Copyright 1999-2021 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 | % % |
Cristy | 83d74de | 2018-10-13 10:17:25 -0400 | [diff] [blame] | 26 | % https://imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | WriteMTVImage(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 M T V I m a g e % |
| 75 | % % |
| 76 | % % |
| 77 | % % |
| 78 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 79 | % |
| 80 | % ReadMTVImage() reads a MTV image file and returns it. It allocates |
| 81 | % the memory necessary for the new Image structure and returns a pointer to |
| 82 | % the new image. |
| 83 | % |
| 84 | % The format of the ReadMTVImage method is: |
| 85 | % |
| 86 | % Image *ReadMTVImage(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 *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 96 | { |
| 97 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 98 | buffer[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 99 | |
| 100 | Image |
| 101 | *image; |
| 102 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | MagickBooleanType |
| 104 | status; |
| 105 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 106 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 107 | x; |
| 108 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 109 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | *q; |
| 111 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 112 | unsigned char |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | *p; |
| 114 | |
| 115 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 116 | count, |
| 117 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 118 | |
| 119 | unsigned char |
| 120 | *pixels; |
| 121 | |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 122 | unsigned long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | columns, |
| 124 | rows; |
| 125 | |
| 126 | /* |
| 127 | Open image file. |
| 128 | */ |
| 129 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 130 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | if (image_info->debug != MagickFalse) |
| 132 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 133 | image_info->filename); |
| 134 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 135 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 136 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 138 | if (status == MagickFalse) |
| 139 | { |
| 140 | image=DestroyImageList(image); |
| 141 | return((Image *) NULL); |
| 142 | } |
| 143 | /* |
| 144 | Read MTV image. |
| 145 | */ |
Cristy | 7f3dd51 | 2018-03-25 17:46:14 -0400 | [diff] [blame] | 146 | (void) memset(buffer,0,sizeof(buffer)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 147 | (void) ReadBlobString(image,buffer); |
| 148 | count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows); |
Cristy | 7f3dd51 | 2018-03-25 17:46:14 -0400 | [diff] [blame] | 149 | if (count != 2) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 151 | do |
| 152 | { |
| 153 | /* |
| 154 | Initialize image structure. |
| 155 | */ |
| 156 | image->columns=columns; |
| 157 | image->rows=rows; |
| 158 | image->depth=8; |
| 159 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 160 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 161 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 162 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 163 | if (status == MagickFalse) |
| 164 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | /* |
| 166 | Convert MTV raster image to pixel packets. |
| 167 | */ |
cristy | bc4a1d4 | 2014-12-15 21:47:00 +0000 | [diff] [blame] | 168 | pixels=(unsigned char *) AcquireQuantumMemory(image->columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | 3UL*sizeof(*pixels)); |
| 170 | if (pixels == (unsigned char *) NULL) |
| 171 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
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=(ssize_t) ReadBlob(image,(size_t) (3*image->columns),pixels); |
| 175 | if (count != (ssize_t) (3*image->columns)) |
Cristy | f064939 | 2017-04-26 17:21:42 -0400 | [diff] [blame] | 176 | { |
| 177 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 178 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 179 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | p=pixels; |
| 181 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 182 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 184 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 186 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 187 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 188 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 189 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 190 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 191 | } |
| 192 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 193 | break; |
| 194 | if (image->previous == (Image *) NULL) |
| 195 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 196 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 197 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 198 | if (status == MagickFalse) |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 203 | if (EOFBlob(image) != MagickFalse) |
| 204 | { |
| 205 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 206 | image->filename); |
| 207 | break; |
| 208 | } |
| 209 | /* |
| 210 | Proceed to next image. |
| 211 | */ |
| 212 | if (image_info->number_scenes != 0) |
| 213 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 214 | break; |
| 215 | *buffer='\0'; |
Cristy | e80a30b | 2018-03-25 17:43:24 -0400 | [diff] [blame] | 216 | if (ReadBlobString(image,buffer) == (char *) NULL) |
| 217 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 218 | count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows); |
| 219 | if (count > 0) |
| 220 | { |
| 221 | /* |
| 222 | Allocate next image structure. |
| 223 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 224 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 225 | if (GetNextImageInList(image) == (Image *) NULL) |
| 226 | { |
Cristy | 3b48d20 | 2018-07-01 17:11:51 -0400 | [diff] [blame] | 227 | status=MagickFalse; |
| 228 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | } |
| 230 | image=SyncNextImageInList(image); |
| 231 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 232 | GetBlobSize(image)); |
| 233 | if (status == MagickFalse) |
| 234 | break; |
| 235 | } |
| 236 | } while (count > 0); |
| 237 | (void) CloseBlob(image); |
Cristy | 3b48d20 | 2018-07-01 17:11:51 -0400 | [diff] [blame] | 238 | if (status == MagickFalse) |
| 239 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | return(GetFirstImageInList(image)); |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 245 | % % |
| 246 | % % |
| 247 | % % |
| 248 | % R e g i s t e r M T V I m a g e % |
| 249 | % % |
| 250 | % % |
| 251 | % % |
| 252 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 253 | % |
| 254 | % RegisterMTVImage() adds attributes for the MTV image format to |
| 255 | % the list of supported formats. The attributes include the image format |
| 256 | % tag, a method to read and/or write the format, whether the format |
| 257 | % supports the saving of more than one frame to the same file or blob, |
| 258 | % whether the format supports native in-memory I/O, and a brief |
| 259 | % description of the format. |
| 260 | % |
| 261 | % The format of the RegisterMTVImage method is: |
| 262 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 263 | % size_t RegisterMTVImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | % |
| 265 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 266 | ModuleExport size_t RegisterMTVImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | { |
| 268 | MagickInfo |
| 269 | *entry; |
| 270 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 271 | entry=AcquireMagickInfo("MTV","MTV","MTV Raytracing image format"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 272 | entry->decoder=(DecodeImageHandler *) ReadMTVImage; |
| 273 | entry->encoder=(EncodeImageHandler *) WriteMTVImage; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 274 | (void) RegisterMagickInfo(entry); |
| 275 | return(MagickImageCoderSignature); |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 280 | % % |
| 281 | % % |
| 282 | % % |
| 283 | % U n r e g i s t e r M T V I m a g e % |
| 284 | % % |
| 285 | % % |
| 286 | % % |
| 287 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 288 | % |
| 289 | % UnregisterMTVImage() removes format registrations made by the |
| 290 | % MTV module from the list of supported formats. |
| 291 | % |
| 292 | % The format of the UnregisterMTVImage method is: |
| 293 | % |
| 294 | % UnregisterMTVImage(void) |
| 295 | % |
| 296 | */ |
| 297 | ModuleExport void UnregisterMTVImage(void) |
| 298 | { |
| 299 | (void) UnregisterMagickInfo("MTV"); |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 304 | % % |
| 305 | % % |
| 306 | % % |
| 307 | % W r i t e M T V I m a g e % |
| 308 | % % |
| 309 | % % |
| 310 | % % |
| 311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 312 | % |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 313 | % WriteMTVImage() writes an image to a file in red, green, and blue MTV |
| 314 | % rasterfile format. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 315 | % |
| 316 | % The format of the WriteMTVImage method is: |
| 317 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 318 | % MagickBooleanType WriteMTVImage(const ImageInfo *image_info, |
| 319 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 320 | % |
| 321 | % A description of each parameter follows. |
| 322 | % |
| 323 | % o image_info: the image info. |
| 324 | % |
| 325 | % o image: The image. |
| 326 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 327 | % o exception: return any errors or warnings in this structure. |
| 328 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | */ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 330 | static MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image, |
| 331 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | { |
| 333 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 334 | buffer[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 336 | MagickBooleanType |
| 337 | status; |
| 338 | |
| 339 | MagickOffsetType |
| 340 | scene; |
| 341 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 342 | const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 343 | *p; |
| 344 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 345 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | x; |
| 347 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 348 | unsigned char |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 349 | *q; |
| 350 | |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame] | 351 | size_t |
| 352 | imageListLength; |
| 353 | |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 354 | ssize_t |
| 355 | y; |
| 356 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 357 | unsigned char |
| 358 | *pixels; |
| 359 | |
| 360 | /* |
| 361 | Open output image file. |
| 362 | */ |
| 363 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 364 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 366 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 367 | if (image->debug != MagickFalse) |
| 368 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 369 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 370 | assert(exception->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 371 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 372 | if (status == MagickFalse) |
| 373 | return(status); |
| 374 | scene=0; |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame] | 375 | imageListLength=GetImageListLength(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 376 | do |
| 377 | { |
| 378 | /* |
| 379 | Allocate memory for pixels. |
| 380 | */ |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 381 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | bc4a1d4 | 2014-12-15 21:47:00 +0000 | [diff] [blame] | 382 | pixels=(unsigned char *) AcquireQuantumMemory(image->columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 383 | 3UL*sizeof(*pixels)); |
| 384 | if (pixels == (unsigned char *) NULL) |
| 385 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 386 | /* |
| 387 | Initialize raster file header. |
| 388 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 389 | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g %.20g\n",(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 390 | image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | (void) WriteBlobString(image,buffer); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 392 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 393 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 394 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 395 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 396 | break; |
| 397 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 398 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 400 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 401 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 402 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 403 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | } |
| 405 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
| 406 | if (image->previous == (Image *) NULL) |
| 407 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 408 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 409 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 410 | if (status == MagickFalse) |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 415 | if (GetNextImageInList(image) == (Image *) NULL) |
| 416 | break; |
| 417 | image=SyncNextImageInList(image); |
Cristy | c45b2bb | 2018-04-07 12:32:12 -0400 | [diff] [blame] | 418 | status=SetImageProgress(image,SaveImagesTag,scene,imageListLength); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | if (status == MagickFalse) |
| 420 | break; |
| 421 | scene++; |
| 422 | } while (image_info->adjoin != MagickFalse); |
| 423 | (void) CloseBlob(image); |
| 424 | return(MagickTrue); |
| 425 | } |