cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % M M PPPP CCCC % |
| 7 | % MM MM P P C % |
| 8 | % M M M PPPP C % |
| 9 | % M M P C % |
| 10 | % M M P CCCC % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Magick Persistant Cache 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 | % March 2000 % |
| 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 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/artifact.h" |
| 45 | #include "MagickCore/attribute.h" |
| 46 | #include "MagickCore/blob.h" |
| 47 | #include "MagickCore/blob-private.h" |
| 48 | #include "MagickCore/cache.h" |
| 49 | #include "MagickCore/color.h" |
| 50 | #include "MagickCore/color-private.h" |
| 51 | #include "MagickCore/colormap.h" |
| 52 | #include "MagickCore/constitute.h" |
| 53 | #include "MagickCore/exception.h" |
| 54 | #include "MagickCore/exception-private.h" |
| 55 | #include "MagickCore/geometry.h" |
| 56 | #include "MagickCore/hashmap.h" |
| 57 | #include "MagickCore/image.h" |
| 58 | #include "MagickCore/image-private.h" |
| 59 | #include "MagickCore/list.h" |
| 60 | #include "MagickCore/magick.h" |
| 61 | #include "MagickCore/memory_.h" |
| 62 | #include "MagickCore/module.h" |
| 63 | #include "MagickCore/monitor.h" |
| 64 | #include "MagickCore/monitor-private.h" |
| 65 | #include "MagickCore/option.h" |
| 66 | #include "MagickCore/profile.h" |
| 67 | #include "MagickCore/property.h" |
| 68 | #include "MagickCore/quantum-private.h" |
| 69 | #include "MagickCore/static.h" |
| 70 | #include "MagickCore/statistic.h" |
| 71 | #include "MagickCore/string_.h" |
| 72 | #include "MagickCore/string-private.h" |
| 73 | #include "MagickCore/utility.h" |
cristy | a371edf | 2013-02-06 13:42:17 +0000 | [diff] [blame] | 74 | #include "MagickCore/version-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | Forward declarations. |
| 78 | */ |
| 79 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 80 | WriteMPCImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 84 | % % |
| 85 | % % |
| 86 | % % |
| 87 | % I s M P C % |
| 88 | % % |
| 89 | % % |
| 90 | % % |
| 91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 92 | % |
| 93 | % IsMPC() returns MagickTrue if the image format type, identified by the |
| 94 | % magick string, is an Magick Persistent Cache image. |
| 95 | % |
| 96 | % The format of the IsMPC method is: |
| 97 | % |
| 98 | % MagickBooleanType IsMPC(const unsigned char *magick,const size_t length) |
| 99 | % |
| 100 | % A description of each parameter follows: |
| 101 | % |
| 102 | % o magick: compare image format pattern against these bytes. |
| 103 | % |
| 104 | % o length: Specifies the length of the magick string. |
| 105 | % |
| 106 | */ |
| 107 | static MagickBooleanType IsMPC(const unsigned char *magick,const size_t length) |
| 108 | { |
| 109 | if (length < 14) |
| 110 | return(MagickFalse); |
| 111 | if (LocaleNCompare((const char *) magick,"id=MagickCache",14) == 0) |
| 112 | return(MagickTrue); |
| 113 | return(MagickFalse); |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 118 | % % |
| 119 | % % |
| 120 | % % |
| 121 | % R e a d C A C H E I m a g e % |
| 122 | % % |
| 123 | % % |
| 124 | % % |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 | % |
| 127 | % ReadMPCImage() reads an Magick Persistent Cache image file and returns |
| 128 | % it. It allocates the memory necessary for the new Image structure and |
| 129 | % returns a pointer to the new image. |
| 130 | % |
| 131 | % The format of the ReadMPCImage method is: |
| 132 | % |
| 133 | % Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 134 | % |
| 135 | % Decompression code contributed by Kyle Shorter. |
| 136 | % |
| 137 | % A description of each parameter follows: |
| 138 | % |
| 139 | % o image_info: the image info. |
| 140 | % |
| 141 | % o exception: return any errors or warnings in this structure. |
| 142 | % |
| 143 | */ |
| 144 | static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 145 | { |
| 146 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 147 | cache_filename[MagickPathExtent], |
| 148 | id[MagickPathExtent], |
| 149 | keyword[MagickPathExtent], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | *options; |
| 151 | |
| 152 | const unsigned char |
| 153 | *p; |
| 154 | |
| 155 | GeometryInfo |
| 156 | geometry_info; |
| 157 | |
| 158 | Image |
| 159 | *image; |
| 160 | |
| 161 | int |
| 162 | c; |
| 163 | |
| 164 | LinkedListInfo |
| 165 | *profiles; |
| 166 | |
| 167 | MagickBooleanType |
| 168 | status; |
| 169 | |
| 170 | MagickOffsetType |
| 171 | offset; |
| 172 | |
| 173 | MagickStatusType |
| 174 | flags; |
| 175 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 176 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | i; |
| 178 | |
| 179 | size_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 180 | depth, |
cristy | 6e32367 | 2013-02-05 18:44:04 +0000 | [diff] [blame] | 181 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | |
| 183 | ssize_t |
| 184 | count; |
| 185 | |
| 186 | StringInfo |
| 187 | *profile; |
| 188 | |
cristy | 6e32367 | 2013-02-05 18:44:04 +0000 | [diff] [blame] | 189 | unsigned int |
| 190 | signature; |
| 191 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 192 | /* |
| 193 | Open image file. |
| 194 | */ |
| 195 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 196 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 197 | if (image_info->debug != MagickFalse) |
| 198 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 199 | image_info->filename); |
| 200 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 201 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 202 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 203 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 204 | if (status == MagickFalse) |
| 205 | { |
| 206 | image=DestroyImageList(image); |
| 207 | return((Image *) NULL); |
| 208 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 209 | (void) CopyMagickString(cache_filename,image->filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 210 | AppendImageFormat("cache",cache_filename); |
| 211 | c=ReadBlobByte(image); |
| 212 | if (c == EOF) |
| 213 | { |
| 214 | image=DestroyImage(image); |
| 215 | return((Image *) NULL); |
| 216 | } |
| 217 | *id='\0'; |
| 218 | (void) ResetMagickMemory(keyword,0,sizeof(keyword)); |
| 219 | offset=0; |
| 220 | do |
| 221 | { |
| 222 | /* |
| 223 | Decode image header; header terminates one character beyond a ':'. |
| 224 | */ |
| 225 | profiles=(LinkedListInfo *) NULL; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 226 | length=MagickPathExtent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | options=AcquireString((char *) NULL); |
cristy | 6e32367 | 2013-02-05 18:44:04 +0000 | [diff] [blame] | 228 | signature=GetMagickSignature((const StringInfo *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | image->depth=8; |
| 230 | image->compression=NoCompression; |
| 231 | while ((isgraph(c) != MagickFalse) && (c != (int) ':')) |
| 232 | { |
| 233 | register char |
| 234 | *p; |
| 235 | |
| 236 | if (c == (int) '{') |
| 237 | { |
| 238 | char |
| 239 | *comment; |
| 240 | |
| 241 | /* |
| 242 | Read comment-- any text between { }. |
| 243 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 244 | length=MagickPathExtent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | comment=AcquireString((char *) NULL); |
| 246 | for (p=comment; comment != (char *) NULL; p++) |
| 247 | { |
| 248 | c=ReadBlobByte(image); |
cristy | b880ee8 | 2012-04-07 15:08:14 +0000 | [diff] [blame] | 249 | if (c == (int) '\\') |
| 250 | c=ReadBlobByte(image); |
| 251 | else |
| 252 | if ((c == EOF) || (c == (int) '}')) |
| 253 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 254 | if ((size_t) (p-comment+1) >= length) |
| 255 | { |
| 256 | *p='\0'; |
| 257 | length<<=1; |
| 258 | comment=(char *) ResizeQuantumMemory(comment,length+ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 259 | MagickPathExtent,sizeof(*comment)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 260 | if (comment == (char *) NULL) |
| 261 | break; |
| 262 | p=comment+strlen(comment); |
| 263 | } |
| 264 | *p=(char) c; |
| 265 | } |
| 266 | if (comment == (char *) NULL) |
| 267 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 268 | *p='\0'; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 269 | (void) SetImageProperty(image,"comment",comment,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 270 | comment=DestroyString(comment); |
| 271 | c=ReadBlobByte(image); |
| 272 | } |
| 273 | else |
| 274 | if (isalnum(c) != MagickFalse) |
| 275 | { |
| 276 | /* |
| 277 | Get the keyword. |
| 278 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 279 | length=MagickPathExtent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 280 | p=keyword; |
| 281 | do |
| 282 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | if (c == (int) '=') |
| 284 | break; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 285 | if ((size_t) (p-keyword) < (MagickPathExtent-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 286 | *p++=(char) c; |
| 287 | c=ReadBlobByte(image); |
| 288 | } while (c != EOF); |
| 289 | *p='\0'; |
| 290 | p=options; |
| 291 | while (isspace((int) ((unsigned char) c)) != 0) |
| 292 | c=ReadBlobByte(image); |
| 293 | if (c == (int) '=') |
| 294 | { |
| 295 | /* |
| 296 | Get the keyword value. |
| 297 | */ |
| 298 | c=ReadBlobByte(image); |
| 299 | while ((c != (int) '}') && (c != EOF)) |
| 300 | { |
| 301 | if ((size_t) (p-options+1) >= length) |
| 302 | { |
| 303 | *p='\0'; |
| 304 | length<<=1; |
| 305 | options=(char *) ResizeQuantumMemory(options,length+ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 306 | MagickPathExtent,sizeof(*options)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | if (options == (char *) NULL) |
| 308 | break; |
| 309 | p=options+strlen(options); |
| 310 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | *p++=(char) c; |
| 312 | c=ReadBlobByte(image); |
cristy | b880ee8 | 2012-04-07 15:08:14 +0000 | [diff] [blame] | 313 | if (c == '\\') |
| 314 | { |
| 315 | c=ReadBlobByte(image); |
| 316 | if (c == (int) '}') |
| 317 | { |
| 318 | *p++=(char) c; |
| 319 | c=ReadBlobByte(image); |
| 320 | } |
| 321 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | if (*options != '{') |
| 323 | if (isspace((int) ((unsigned char) c)) != 0) |
| 324 | break; |
| 325 | } |
cristy | 3788976 | 2015-01-07 12:20:18 +0000 | [diff] [blame] | 326 | if (options == (char *) NULL) |
| 327 | ThrowReaderException(ResourceLimitError, |
| 328 | "MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | } |
| 330 | *p='\0'; |
| 331 | if (*options == '{') |
cristy | 01cd730 | 2012-10-05 16:02:03 +0000 | [diff] [blame] | 332 | (void) CopyMagickString(options,options+1,strlen(options)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 333 | /* |
| 334 | Assign a value to the specified keyword. |
| 335 | */ |
| 336 | switch (*keyword) |
| 337 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 338 | case 'a': |
| 339 | case 'A': |
| 340 | { |
| 341 | if (LocaleCompare(keyword,"alpha-trait") == 0) |
| 342 | { |
| 343 | ssize_t |
| 344 | alpha_trait; |
| 345 | |
| 346 | alpha_trait=ParseCommandOption(MagickPixelTraitOptions, |
| 347 | MagickFalse,options); |
| 348 | if (alpha_trait < 0) |
| 349 | break; |
| 350 | image->alpha_trait=(PixelTrait) alpha_trait; |
| 351 | break; |
| 352 | } |
| 353 | (void) SetImageProperty(image,keyword,options,exception); |
| 354 | break; |
| 355 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 356 | case 'b': |
| 357 | case 'B': |
| 358 | { |
| 359 | if (LocaleCompare(keyword,"background-color") == 0) |
| 360 | { |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 361 | (void) QueryColorCompliance(options,AllCompliance, |
| 362 | &image->background_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | if (LocaleCompare(keyword,"blue-primary") == 0) |
| 366 | { |
| 367 | flags=ParseGeometry(options,&geometry_info); |
| 368 | image->chromaticity.blue_primary.x=geometry_info.rho; |
| 369 | image->chromaticity.blue_primary.y=geometry_info.sigma; |
| 370 | if ((flags & SigmaValue) == 0) |
| 371 | image->chromaticity.blue_primary.y= |
| 372 | image->chromaticity.blue_primary.x; |
| 373 | break; |
| 374 | } |
| 375 | if (LocaleCompare(keyword,"border-color") == 0) |
| 376 | { |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 377 | (void) QueryColorCompliance(options,AllCompliance, |
| 378 | &image->border_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | break; |
| 380 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 381 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 382 | break; |
| 383 | } |
| 384 | case 'c': |
| 385 | case 'C': |
| 386 | { |
| 387 | if (LocaleCompare(keyword,"class") == 0) |
| 388 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 389 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 390 | storage_class; |
| 391 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 392 | storage_class=ParseCommandOption(MagickClassOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 393 | MagickFalse,options); |
| 394 | if (storage_class < 0) |
| 395 | break; |
| 396 | image->storage_class=(ClassType) storage_class; |
| 397 | break; |
| 398 | } |
| 399 | if (LocaleCompare(keyword,"colors") == 0) |
| 400 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 401 | image->colors=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | if (LocaleCompare(keyword,"colorspace") == 0) |
| 405 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 406 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 407 | colorspace; |
| 408 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 409 | colorspace=ParseCommandOption(MagickColorspaceOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 410 | MagickFalse,options); |
| 411 | if (colorspace < 0) |
| 412 | break; |
cristy | 02a27d5 | 2013-03-05 01:06:21 +0000 | [diff] [blame] | 413 | image->colorspace=(ColorspaceType) colorspace; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 414 | break; |
| 415 | } |
| 416 | if (LocaleCompare(keyword,"compression") == 0) |
| 417 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 418 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | compression; |
| 420 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 421 | compression=ParseCommandOption(MagickCompressOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | MagickFalse,options); |
| 423 | if (compression < 0) |
| 424 | break; |
| 425 | image->compression=(CompressionType) compression; |
| 426 | break; |
| 427 | } |
| 428 | if (LocaleCompare(keyword,"columns") == 0) |
| 429 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 430 | image->columns=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 431 | break; |
| 432 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 433 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 434 | break; |
| 435 | } |
| 436 | case 'd': |
| 437 | case 'D': |
| 438 | { |
| 439 | if (LocaleCompare(keyword,"delay") == 0) |
| 440 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 441 | image->delay=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 442 | break; |
| 443 | } |
| 444 | if (LocaleCompare(keyword,"depth") == 0) |
| 445 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 446 | image->depth=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 447 | break; |
| 448 | } |
| 449 | if (LocaleCompare(keyword,"dispose") == 0) |
| 450 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 451 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | dispose; |
| 453 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 454 | dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 455 | options); |
| 456 | if (dispose < 0) |
| 457 | break; |
| 458 | image->dispose=(DisposeType) dispose; |
| 459 | break; |
| 460 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 461 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 462 | break; |
| 463 | } |
| 464 | case 'e': |
| 465 | case 'E': |
| 466 | { |
| 467 | if (LocaleCompare(keyword,"endian") == 0) |
| 468 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 469 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 470 | endian; |
| 471 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 472 | endian=ParseCommandOption(MagickEndianOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | options); |
| 474 | if (endian < 0) |
| 475 | break; |
| 476 | image->endian=(EndianType) endian; |
| 477 | break; |
| 478 | } |
| 479 | if (LocaleCompare(keyword,"error") == 0) |
| 480 | { |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 481 | image->error.mean_error_per_pixel=StringToDouble(options, |
| 482 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 483 | break; |
| 484 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 485 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 486 | break; |
| 487 | } |
| 488 | case 'g': |
| 489 | case 'G': |
| 490 | { |
| 491 | if (LocaleCompare(keyword,"gamma") == 0) |
| 492 | { |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 493 | image->gamma=StringToDouble(options,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 494 | break; |
| 495 | } |
| 496 | if (LocaleCompare(keyword,"green-primary") == 0) |
| 497 | { |
| 498 | flags=ParseGeometry(options,&geometry_info); |
| 499 | image->chromaticity.green_primary.x=geometry_info.rho; |
| 500 | image->chromaticity.green_primary.y=geometry_info.sigma; |
| 501 | if ((flags & SigmaValue) == 0) |
| 502 | image->chromaticity.green_primary.y= |
| 503 | image->chromaticity.green_primary.x; |
| 504 | break; |
| 505 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 506 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | case 'i': |
| 510 | case 'I': |
| 511 | { |
| 512 | if (LocaleCompare(keyword,"id") == 0) |
| 513 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 514 | (void) CopyMagickString(id,options,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | if (LocaleCompare(keyword,"iterations") == 0) |
| 518 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 519 | image->iterations=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | break; |
| 521 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 522 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | break; |
| 524 | } |
| 525 | case 'm': |
| 526 | case 'M': |
| 527 | { |
cristy | 240e825 | 2013-02-06 15:00:04 +0000 | [diff] [blame] | 528 | if (LocaleCompare(keyword,"magick-signature") == 0) |
| 529 | { |
| 530 | signature=(unsigned int) StringToUnsignedLong(options); |
| 531 | break; |
| 532 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 533 | if (LocaleCompare(keyword,"matte-color") == 0) |
| 534 | { |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 535 | (void) QueryColorCompliance(options,AllCompliance, |
| 536 | &image->matte_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 537 | break; |
| 538 | } |
| 539 | if (LocaleCompare(keyword,"maximum-error") == 0) |
| 540 | { |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 541 | image->error.normalized_maximum_error=StringToDouble( |
| 542 | options,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | if (LocaleCompare(keyword,"mean-error") == 0) |
| 546 | { |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 547 | image->error.normalized_mean_error=StringToDouble(options, |
| 548 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | if (LocaleCompare(keyword,"montage") == 0) |
| 552 | { |
| 553 | (void) CloneString(&image->montage,options); |
| 554 | break; |
| 555 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 556 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | case 'o': |
| 560 | case 'O': |
| 561 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 562 | if (LocaleCompare(keyword,"orientation") == 0) |
| 563 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 564 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 565 | orientation; |
| 566 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 567 | orientation=ParseCommandOption(MagickOrientationOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 568 | MagickFalse,options); |
| 569 | if (orientation < 0) |
| 570 | break; |
| 571 | image->orientation=(OrientationType) orientation; |
| 572 | break; |
| 573 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 574 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 575 | break; |
| 576 | } |
| 577 | case 'p': |
| 578 | case 'P': |
| 579 | { |
| 580 | if (LocaleCompare(keyword,"page") == 0) |
| 581 | { |
| 582 | char |
| 583 | *geometry; |
| 584 | |
| 585 | geometry=GetPageGeometry(options); |
| 586 | (void) ParseAbsoluteGeometry(geometry,&image->page); |
| 587 | geometry=DestroyString(geometry); |
| 588 | break; |
| 589 | } |
cristy | 3e4e9f4 | 2013-04-06 22:29:40 +0000 | [diff] [blame] | 590 | if (LocaleCompare(keyword,"pixel-intensity") == 0) |
| 591 | { |
| 592 | ssize_t |
| 593 | intensity; |
| 594 | |
| 595 | intensity=ParseCommandOption(MagickPixelIntensityOptions, |
| 596 | MagickFalse,options); |
| 597 | if (intensity < 0) |
| 598 | break; |
| 599 | image->intensity=(PixelIntensityMethod) intensity; |
| 600 | break; |
| 601 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 602 | if ((LocaleNCompare(keyword,"profile:",8) == 0) || |
| 603 | (LocaleNCompare(keyword,"profile-",8) == 0)) |
| 604 | { |
| 605 | if (profiles == (LinkedListInfo *) NULL) |
| 606 | profiles=NewLinkedList(0); |
| 607 | (void) AppendValueToLinkedList(profiles, |
| 608 | AcquireString(keyword+8)); |
cristy | 07c9bd6 | 2011-09-01 13:41:23 +0000 | [diff] [blame] | 609 | profile=BlobToStringInfo((const void *) NULL,(size_t) |
| 610 | StringToLong(options)); |
cristy | 0381c63 | 2011-09-01 18:02:13 +0000 | [diff] [blame] | 611 | if (profile == (StringInfo *) NULL) |
cristy | 07c9bd6 | 2011-09-01 13:41:23 +0000 | [diff] [blame] | 612 | ThrowReaderException(ResourceLimitError, |
| 613 | "MemoryAllocationFailed"); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 614 | (void) SetImageProfile(image,keyword+8,profile,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 615 | profile=DestroyStringInfo(profile); |
| 616 | break; |
| 617 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 618 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 619 | break; |
| 620 | } |
| 621 | case 'q': |
| 622 | case 'Q': |
| 623 | { |
| 624 | if (LocaleCompare(keyword,"quality") == 0) |
| 625 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 626 | image->quality=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 627 | break; |
| 628 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 629 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 630 | break; |
| 631 | } |
| 632 | case 'r': |
| 633 | case 'R': |
| 634 | { |
| 635 | if (LocaleCompare(keyword,"red-primary") == 0) |
| 636 | { |
| 637 | flags=ParseGeometry(options,&geometry_info); |
| 638 | image->chromaticity.red_primary.x=geometry_info.rho; |
| 639 | if ((flags & SigmaValue) != 0) |
| 640 | image->chromaticity.red_primary.y=geometry_info.sigma; |
| 641 | break; |
| 642 | } |
| 643 | if (LocaleCompare(keyword,"rendering-intent") == 0) |
| 644 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 645 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 646 | rendering_intent; |
| 647 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 648 | rendering_intent=ParseCommandOption(MagickIntentOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 649 | MagickFalse,options); |
| 650 | if (rendering_intent < 0) |
| 651 | break; |
| 652 | image->rendering_intent=(RenderingIntent) rendering_intent; |
| 653 | break; |
| 654 | } |
| 655 | if (LocaleCompare(keyword,"resolution") == 0) |
| 656 | { |
| 657 | flags=ParseGeometry(options,&geometry_info); |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 658 | image->resolution.x=geometry_info.rho; |
| 659 | image->resolution.y=geometry_info.sigma; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 660 | if ((flags & SigmaValue) == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 661 | image->resolution.y=image->resolution.x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | break; |
| 663 | } |
| 664 | if (LocaleCompare(keyword,"rows") == 0) |
| 665 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 666 | image->rows=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 667 | break; |
| 668 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 669 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | break; |
| 671 | } |
| 672 | case 's': |
| 673 | case 'S': |
| 674 | { |
| 675 | if (LocaleCompare(keyword,"scene") == 0) |
| 676 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 677 | image->scene=StringToUnsignedLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 678 | break; |
| 679 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 680 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 681 | break; |
| 682 | } |
| 683 | case 't': |
| 684 | case 'T': |
| 685 | { |
| 686 | if (LocaleCompare(keyword,"ticks-per-second") == 0) |
| 687 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 688 | image->ticks_per_second=(ssize_t) StringToLong(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | break; |
| 690 | } |
| 691 | if (LocaleCompare(keyword,"tile-offset") == 0) |
| 692 | { |
| 693 | char |
| 694 | *geometry; |
| 695 | |
| 696 | geometry=GetPageGeometry(options); |
| 697 | (void) ParseAbsoluteGeometry(geometry,&image->tile_offset); |
| 698 | geometry=DestroyString(geometry); |
| 699 | } |
| 700 | if (LocaleCompare(keyword,"type") == 0) |
| 701 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 702 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 703 | type; |
| 704 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 705 | type=ParseCommandOption(MagickTypeOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 706 | options); |
| 707 | if (type < 0) |
| 708 | break; |
| 709 | image->type=(ImageType) type; |
| 710 | break; |
| 711 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 712 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | break; |
| 714 | } |
| 715 | case 'u': |
| 716 | case 'U': |
| 717 | { |
| 718 | if (LocaleCompare(keyword,"units") == 0) |
| 719 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 720 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 721 | units; |
| 722 | |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 723 | units=ParseCommandOption(MagickResolutionOptions, |
| 724 | MagickFalse,options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 725 | if (units < 0) |
| 726 | break; |
| 727 | image->units=(ResolutionType) units; |
| 728 | break; |
| 729 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 730 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 731 | break; |
| 732 | } |
| 733 | case 'w': |
| 734 | case 'W': |
| 735 | { |
| 736 | if (LocaleCompare(keyword,"white-point") == 0) |
| 737 | { |
| 738 | flags=ParseGeometry(options,&geometry_info); |
| 739 | image->chromaticity.white_point.x=geometry_info.rho; |
| 740 | image->chromaticity.white_point.y=geometry_info.sigma; |
| 741 | if ((flags & SigmaValue) == 0) |
| 742 | image->chromaticity.white_point.y= |
| 743 | image->chromaticity.white_point.x; |
| 744 | break; |
| 745 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 746 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | default: |
| 750 | { |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 751 | (void) SetImageProperty(image,keyword,options,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | else |
| 757 | c=ReadBlobByte(image); |
| 758 | while (isspace((int) ((unsigned char) c)) != 0) |
| 759 | c=ReadBlobByte(image); |
| 760 | } |
| 761 | options=DestroyString(options); |
| 762 | (void) ReadBlobByte(image); |
| 763 | /* |
| 764 | Verify that required image information is defined. |
| 765 | */ |
| 766 | if ((LocaleCompare(id,"MagickCache") != 0) || |
| 767 | (image->storage_class == UndefinedClass) || |
| 768 | (image->compression == UndefinedCompression) || (image->columns == 0) || |
| 769 | (image->rows == 0)) |
| 770 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | 6e32367 | 2013-02-05 18:44:04 +0000 | [diff] [blame] | 771 | if (signature != GetMagickSignature((const StringInfo *) NULL)) |
| 772 | ThrowReaderException(CacheError,"IncompatibleAPI"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 773 | if (image->montage != (char *) NULL) |
| 774 | { |
| 775 | register char |
| 776 | *p; |
| 777 | |
| 778 | /* |
| 779 | Image directory. |
| 780 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 781 | length=MagickPathExtent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 782 | image->directory=AcquireString((char *) NULL); |
| 783 | p=image->directory; |
| 784 | do |
| 785 | { |
| 786 | *p='\0'; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 787 | if ((strlen(image->directory)+MagickPathExtent) >= length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 788 | { |
| 789 | /* |
| 790 | Allocate more memory for the image directory. |
| 791 | */ |
| 792 | length<<=1; |
| 793 | image->directory=(char *) ResizeQuantumMemory(image->directory, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 794 | length+MagickPathExtent,sizeof(*image->directory)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 795 | if (image->directory == (char *) NULL) |
| 796 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 797 | p=image->directory+strlen(image->directory); |
| 798 | } |
| 799 | c=ReadBlobByte(image); |
| 800 | *p++=(char) c; |
| 801 | } while (c != (int) '\0'); |
| 802 | } |
| 803 | if (profiles != (LinkedListInfo *) NULL) |
| 804 | { |
| 805 | const char |
| 806 | *name; |
| 807 | |
| 808 | const StringInfo |
| 809 | *profile; |
| 810 | |
| 811 | register unsigned char |
| 812 | *p; |
| 813 | |
| 814 | /* |
| 815 | Read image profiles. |
| 816 | */ |
| 817 | ResetLinkedListIterator(profiles); |
| 818 | name=(const char *) GetNextValueInLinkedList(profiles); |
| 819 | while (name != (const char *) NULL) |
| 820 | { |
| 821 | profile=GetImageProfile(image,name); |
| 822 | if (profile != (StringInfo *) NULL) |
| 823 | { |
| 824 | p=GetStringInfoDatum(profile); |
| 825 | count=ReadBlob(image,GetStringInfoLength(profile),p); |
| 826 | } |
| 827 | name=(const char *) GetNextValueInLinkedList(profiles); |
| 828 | } |
| 829 | profiles=DestroyLinkedList(profiles,RelinquishMagickMemory); |
| 830 | } |
| 831 | depth=GetImageQuantumDepth(image,MagickFalse); |
| 832 | if (image->storage_class == PseudoClass) |
| 833 | { |
| 834 | /* |
| 835 | Create image colormap. |
| 836 | */ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 837 | if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 838 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 839 | if (image->colors != 0) |
| 840 | { |
| 841 | size_t |
| 842 | packet_size; |
| 843 | |
| 844 | unsigned char |
| 845 | *colormap; |
| 846 | |
| 847 | /* |
| 848 | Read image colormap from file. |
| 849 | */ |
| 850 | packet_size=(size_t) (3UL*depth/8UL); |
| 851 | colormap=(unsigned char *) AcquireQuantumMemory(image->colors, |
| 852 | packet_size*sizeof(*colormap)); |
| 853 | if (colormap == (unsigned char *) NULL) |
| 854 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 855 | count=ReadBlob(image,packet_size*image->colors,colormap); |
| 856 | if (count != (ssize_t) (packet_size*image->colors)) |
| 857 | ThrowReaderException(CorruptImageError, |
| 858 | "InsufficientImageDataInFile"); |
| 859 | p=colormap; |
| 860 | switch (depth) |
| 861 | { |
| 862 | default: |
| 863 | ThrowReaderException(CorruptImageError, |
| 864 | "ImageDepthNotSupported"); |
| 865 | case 8: |
| 866 | { |
| 867 | unsigned char |
| 868 | pixel; |
| 869 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 870 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 871 | { |
| 872 | p=PushCharPixel(p,&pixel); |
| 873 | image->colormap[i].red=ScaleCharToQuantum(pixel); |
| 874 | p=PushCharPixel(p,&pixel); |
| 875 | image->colormap[i].green=ScaleCharToQuantum(pixel); |
| 876 | p=PushCharPixel(p,&pixel); |
| 877 | image->colormap[i].blue=ScaleCharToQuantum(pixel); |
| 878 | } |
| 879 | break; |
| 880 | } |
| 881 | case 16: |
| 882 | { |
| 883 | unsigned short |
| 884 | pixel; |
| 885 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 886 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 887 | { |
| 888 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 889 | image->colormap[i].red=ScaleShortToQuantum(pixel); |
| 890 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 891 | image->colormap[i].green=ScaleShortToQuantum(pixel); |
| 892 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 893 | image->colormap[i].blue=ScaleShortToQuantum(pixel); |
| 894 | } |
| 895 | break; |
| 896 | } |
| 897 | case 32: |
| 898 | { |
cristy | 4cb162a | 2010-05-30 03:04:47 +0000 | [diff] [blame] | 899 | unsigned int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 900 | pixel; |
| 901 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 902 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 903 | { |
| 904 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 905 | image->colormap[i].red=ScaleLongToQuantum(pixel); |
| 906 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 907 | image->colormap[i].green=ScaleLongToQuantum(pixel); |
| 908 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 909 | image->colormap[i].blue=ScaleLongToQuantum(pixel); |
| 910 | } |
| 911 | break; |
| 912 | } |
| 913 | } |
| 914 | colormap=(unsigned char *) RelinquishMagickMemory(colormap); |
| 915 | } |
| 916 | } |
| 917 | if (EOFBlob(image) != MagickFalse) |
| 918 | { |
| 919 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 920 | image->filename); |
| 921 | break; |
| 922 | } |
| 923 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 924 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 925 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 926 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 927 | if (status == MagickFalse) |
| 928 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | /* |
| 930 | Attach persistent pixel cache. |
| 931 | */ |
| 932 | status=PersistPixelCache(image,cache_filename,MagickTrue,&offset,exception); |
| 933 | if (status == MagickFalse) |
| 934 | ThrowReaderException(CacheError,"UnableToPersistPixelCache"); |
| 935 | /* |
| 936 | Proceed to next image. |
| 937 | */ |
| 938 | do |
| 939 | { |
| 940 | c=ReadBlobByte(image); |
| 941 | } while ((isgraph(c) == MagickFalse) && (c != EOF)); |
| 942 | if (c != EOF) |
| 943 | { |
| 944 | /* |
| 945 | Allocate next image structure. |
| 946 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 947 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 948 | if (GetNextImageInList(image) == (Image *) NULL) |
| 949 | { |
| 950 | image=DestroyImageList(image); |
| 951 | return((Image *) NULL); |
| 952 | } |
| 953 | image=SyncNextImageInList(image); |
| 954 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 955 | GetBlobSize(image)); |
| 956 | if (status == MagickFalse) |
| 957 | break; |
| 958 | } |
| 959 | } while (c != EOF); |
| 960 | (void) CloseBlob(image); |
| 961 | return(GetFirstImageInList(image)); |
| 962 | } |
| 963 | |
| 964 | /* |
| 965 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 966 | % % |
| 967 | % % |
| 968 | % % |
| 969 | % R e g i s t e r M P C I m a g e % |
| 970 | % % |
| 971 | % % |
| 972 | % % |
| 973 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 974 | % |
| 975 | % RegisterMPCImage() adds properties for the Cache image format to |
| 976 | % the list of supported formats. The properties include the image format |
| 977 | % tag, a method to read and/or write the format, whether the format |
| 978 | % supports the saving of more than one frame to the same file or blob, |
| 979 | % whether the format supports native in-memory I/O, and a brief |
| 980 | % description of the format. |
| 981 | % |
| 982 | % The format of the RegisterMPCImage method is: |
| 983 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 984 | % size_t RegisterMPCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 985 | % |
| 986 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 987 | ModuleExport size_t RegisterMPCImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 988 | { |
| 989 | MagickInfo |
| 990 | *entry; |
| 991 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 992 | entry=AcquireMagickInfo("MPC","CACHE", |
| 993 | "Magick Persistent Cache image format"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 994 | entry->module=ConstantString("CACHE"); |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 995 | entry->flags|=CoderStealthFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 996 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 997 | entry=AcquireMagickInfo("MPC","MPC","Magick Persistent Cache image format"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 998 | entry->decoder=(DecodeImageHandler *) ReadMPCImage; |
| 999 | entry->encoder=(EncodeImageHandler *) WriteMPCImage; |
| 1000 | entry->magick=(IsImageFormatHandler *) IsMPC; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1001 | (void) RegisterMagickInfo(entry); |
| 1002 | return(MagickImageCoderSignature); |
| 1003 | } |
| 1004 | |
| 1005 | /* |
| 1006 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1007 | % % |
| 1008 | % % |
| 1009 | % % |
| 1010 | % U n r e g i s t e r M P C I m a g e % |
| 1011 | % % |
| 1012 | % % |
| 1013 | % % |
| 1014 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1015 | % |
| 1016 | % UnregisterMPCImage() removes format registrations made by the |
| 1017 | % MPC module from the list of supported formats. |
| 1018 | % |
| 1019 | % The format of the UnregisterMPCImage method is: |
| 1020 | % |
| 1021 | % UnregisterMPCImage(void) |
| 1022 | % |
| 1023 | */ |
| 1024 | ModuleExport void UnregisterMPCImage(void) |
| 1025 | { |
| 1026 | (void) UnregisterMagickInfo("CACHE"); |
| 1027 | (void) UnregisterMagickInfo("MPC"); |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1032 | % % |
| 1033 | % % |
| 1034 | % % |
| 1035 | % W r i t e M P C I m a g e % |
| 1036 | % % |
| 1037 | % % |
| 1038 | % % |
| 1039 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1040 | % |
| 1041 | % WriteMPCImage() writes an Magick Persistent Cache image to a file. |
| 1042 | % |
| 1043 | % The format of the WriteMPCImage method is: |
| 1044 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1045 | % MagickBooleanType WriteMPCImage(const ImageInfo *image_info, |
| 1046 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1047 | % |
| 1048 | % A description of each parameter follows: |
| 1049 | % |
| 1050 | % o image_info: the image info. |
| 1051 | % |
| 1052 | % o image: the image. |
| 1053 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1054 | % o exception: return any errors or warnings in this structure. |
| 1055 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1056 | */ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1057 | static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image, |
| 1058 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1059 | { |
| 1060 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1061 | buffer[MagickPathExtent], |
| 1062 | cache_filename[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1063 | |
| 1064 | const char |
| 1065 | *property, |
| 1066 | *value; |
| 1067 | |
| 1068 | MagickBooleanType |
| 1069 | status; |
| 1070 | |
| 1071 | MagickOffsetType |
| 1072 | offset, |
| 1073 | scene; |
| 1074 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1075 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1076 | i; |
| 1077 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1078 | size_t |
cristy | 688dc7a | 2013-04-07 00:02:55 +0000 | [diff] [blame] | 1079 | depth; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | Open persistent cache. |
| 1083 | */ |
| 1084 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1085 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1086 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1087 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1088 | if (image->debug != MagickFalse) |
| 1089 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1090 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1091 | assert(exception->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1092 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1093 | if (status == MagickFalse) |
| 1094 | return(status); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1095 | (void) CopyMagickString(cache_filename,image->filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1096 | AppendImageFormat("cache",cache_filename); |
| 1097 | scene=0; |
| 1098 | offset=0; |
| 1099 | do |
| 1100 | { |
| 1101 | /* |
| 1102 | Write persistent cache meta-information. |
| 1103 | */ |
| 1104 | depth=GetImageQuantumDepth(image,MagickTrue); |
| 1105 | if ((image->storage_class == PseudoClass) && |
cristy | 3e4e9f4 | 2013-04-06 22:29:40 +0000 | [diff] [blame] | 1106 | (image->colors > (size_t) (GetQuantumRange(image->depth)+1))) |
cristy | 688dc7a | 2013-04-07 00:02:55 +0000 | [diff] [blame] | 1107 | (void) SetImageStorageClass(image,DirectClass,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1108 | (void) WriteBlobString(image,"id=MagickCache\n"); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1109 | (void) FormatLocaleString(buffer,MagickPathExtent,"magick-signature=%u\n", |
cristy | 6e32367 | 2013-02-05 18:44:04 +0000 | [diff] [blame] | 1110 | GetMagickSignature((const StringInfo *) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1111 | (void) WriteBlobString(image,buffer); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1112 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1113 | "class=%s colors=%.20g alpha-trait=%s\n",CommandOptionToMnemonic( |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1114 | MagickClassOptions,image->storage_class),(double) image->colors, |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1115 | CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t) |
| 1116 | image->alpha_trait)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1117 | (void) WriteBlobString(image,buffer); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1118 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1119 | "columns=%.20g rows=%.20g depth=%.20g\n",(double) image->columns, |
| 1120 | (double) image->rows,(double) image->depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1121 | (void) WriteBlobString(image,buffer); |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 1122 | if (image->type != UndefinedType) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1123 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1124 | (void) FormatLocaleString(buffer,MagickPathExtent,"type=%s\n", |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1125 | CommandOptionToMnemonic(MagickTypeOptions,image->type)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1126 | (void) WriteBlobString(image,buffer); |
| 1127 | } |
| 1128 | if (image->colorspace != UndefinedColorspace) |
| 1129 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1130 | (void) FormatLocaleString(buffer,MagickPathExtent,"colorspace=%s\n", |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1131 | CommandOptionToMnemonic(MagickColorspaceOptions,image->colorspace)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1132 | (void) WriteBlobString(image,buffer); |
| 1133 | } |
cristy | 3e4e9f4 | 2013-04-06 22:29:40 +0000 | [diff] [blame] | 1134 | if (image->intensity != UndefinedPixelIntensityMethod) |
| 1135 | { |
Cristy | 6ffac4f | 2015-08-23 10:55:57 -0400 | [diff] [blame] | 1136 | (void) FormatLocaleString(buffer,MagickPathExtent, |
| 1137 | "pixel-intensity=%s\n",CommandOptionToMnemonic( |
| 1138 | MagickPixelIntensityOptions,image->intensity)); |
cristy | 3e4e9f4 | 2013-04-06 22:29:40 +0000 | [diff] [blame] | 1139 | (void) WriteBlobString(image,buffer); |
| 1140 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1141 | if (image->endian != UndefinedEndian) |
| 1142 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1143 | (void) FormatLocaleString(buffer,MagickPathExtent,"endian=%s\n", |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1144 | CommandOptionToMnemonic(MagickEndianOptions,image->endian)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1145 | (void) WriteBlobString(image,buffer); |
| 1146 | } |
| 1147 | if (image->compression != UndefinedCompression) |
| 1148 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1149 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1150 | "compression=%s quality=%.20g\n",CommandOptionToMnemonic( |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1151 | MagickCompressOptions,image->compression),(double) image->quality); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1152 | (void) WriteBlobString(image,buffer); |
| 1153 | } |
| 1154 | if (image->units != UndefinedResolution) |
| 1155 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1156 | (void) FormatLocaleString(buffer,MagickPathExtent,"units=%s\n", |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1157 | CommandOptionToMnemonic(MagickResolutionOptions,image->units)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1158 | (void) WriteBlobString(image,buffer); |
| 1159 | } |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1160 | if ((image->resolution.x != 0) || (image->resolution.y != 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1161 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1162 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1163 | "resolution=%gx%g\n",image->resolution.x,image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1164 | (void) WriteBlobString(image,buffer); |
| 1165 | } |
| 1166 | if ((image->page.width != 0) || (image->page.height != 0)) |
| 1167 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1168 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1169 | "page=%.20gx%.20g%+.20g%+.20g\n",(double) image->page.width,(double) |
| 1170 | image->page.height,(double) image->page.x,(double) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1171 | (void) WriteBlobString(image,buffer); |
| 1172 | } |
| 1173 | else |
| 1174 | if ((image->page.x != 0) || (image->page.y != 0)) |
| 1175 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1176 | (void) FormatLocaleString(buffer,MagickPathExtent,"page=%+ld%+ld\n", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1177 | (long) image->page.x,(long) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1178 | (void) WriteBlobString(image,buffer); |
| 1179 | } |
cristy | ff1cf6f | 2015-05-03 19:56:44 +0000 | [diff] [blame] | 1180 | if ((image->tile_offset.x != 0) || (image->tile_offset.y != 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1181 | { |
cristy | ff1cf6f | 2015-05-03 19:56:44 +0000 | [diff] [blame] | 1182 | (void) FormatLocaleString(buffer,MagickPathExtent, |
| 1183 | "tile-offset=%+ld%+ld\n",(long) image->tile_offset.x,(long) |
| 1184 | image->tile_offset.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1185 | (void) WriteBlobString(image,buffer); |
| 1186 | } |
| 1187 | if ((GetNextImageInList(image) != (Image *) NULL) || |
| 1188 | (GetPreviousImageInList(image) != (Image *) NULL)) |
| 1189 | { |
| 1190 | if (image->scene == 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1191 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1192 | "iterations=%.20g delay=%.20g ticks-per-second=%.20g\n",(double) |
| 1193 | image->iterations,(double) image->delay,(double) |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1194 | image->ticks_per_second); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1195 | else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1196 | (void) FormatLocaleString(buffer,MagickPathExtent,"scene=%.20g " |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1197 | "iterations=%.20g delay=%.20g ticks-per-second=%.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1198 | (double) image->scene,(double) image->iterations,(double) |
| 1199 | image->delay,(double) image->ticks_per_second); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1200 | (void) WriteBlobString(image,buffer); |
| 1201 | } |
| 1202 | else |
| 1203 | { |
| 1204 | if (image->scene != 0) |
| 1205 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1206 | (void) FormatLocaleString(buffer,MagickPathExtent,"scene=%.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1207 | (double) image->scene); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1208 | (void) WriteBlobString(image,buffer); |
| 1209 | } |
| 1210 | if (image->iterations != 0) |
| 1211 | { |
Cristy | 6ffac4f | 2015-08-23 10:55:57 -0400 | [diff] [blame] | 1212 | (void) FormatLocaleString(buffer,MagickPathExtent, |
| 1213 | "iterations=%.20g\n",(double) image->iterations); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1214 | (void) WriteBlobString(image,buffer); |
| 1215 | } |
| 1216 | if (image->delay != 0) |
| 1217 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1218 | (void) FormatLocaleString(buffer,MagickPathExtent,"delay=%.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1219 | (double) image->delay); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | (void) WriteBlobString(image,buffer); |
| 1221 | } |
| 1222 | if (image->ticks_per_second != UndefinedTicksPerSecond) |
| 1223 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1224 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1225 | "ticks-per-second=%.20g\n",(double) image->ticks_per_second); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1226 | (void) WriteBlobString(image,buffer); |
| 1227 | } |
| 1228 | } |
| 1229 | if (image->gravity != UndefinedGravity) |
| 1230 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1231 | (void) FormatLocaleString(buffer,MagickPathExtent,"gravity=%s\n", |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1232 | CommandOptionToMnemonic(MagickGravityOptions,image->gravity)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1233 | (void) WriteBlobString(image,buffer); |
| 1234 | } |
| 1235 | if (image->dispose != UndefinedDispose) |
| 1236 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1237 | (void) FormatLocaleString(buffer,MagickPathExtent,"dispose=%s\n", |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1238 | CommandOptionToMnemonic(MagickDisposeOptions,image->dispose)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1239 | (void) WriteBlobString(image,buffer); |
| 1240 | } |
| 1241 | if (image->rendering_intent != UndefinedIntent) |
| 1242 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1243 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1244 | "rendering-intent=%s\n",CommandOptionToMnemonic(MagickIntentOptions, |
| 1245 | image->rendering_intent)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1246 | (void) WriteBlobString(image,buffer); |
| 1247 | } |
| 1248 | if (image->gamma != 0.0) |
| 1249 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1250 | (void) FormatLocaleString(buffer,MagickPathExtent,"gamma=%g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1251 | image->gamma); |
| 1252 | (void) WriteBlobString(image,buffer); |
| 1253 | } |
| 1254 | if (image->chromaticity.white_point.x != 0.0) |
| 1255 | { |
| 1256 | /* |
| 1257 | Note chomaticity points. |
| 1258 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1259 | (void) FormatLocaleString(buffer,MagickPathExtent,"red-primary=" |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1260 | "%g,%g green-primary=%g,%g blue-primary=%g,%g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1261 | image->chromaticity.red_primary.x,image->chromaticity.red_primary.y, |
| 1262 | image->chromaticity.green_primary.x, |
| 1263 | image->chromaticity.green_primary.y, |
| 1264 | image->chromaticity.blue_primary.x, |
| 1265 | image->chromaticity.blue_primary.y); |
| 1266 | (void) WriteBlobString(image,buffer); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1267 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1268 | "white-point=%g,%g\n",image->chromaticity.white_point.x, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1269 | image->chromaticity.white_point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1270 | (void) WriteBlobString(image,buffer); |
| 1271 | } |
| 1272 | if (image->orientation != UndefinedOrientation) |
| 1273 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1274 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1275 | "orientation=%s\n",CommandOptionToMnemonic(MagickOrientationOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1276 | image->orientation)); |
| 1277 | (void) WriteBlobString(image,buffer); |
| 1278 | } |
| 1279 | if (image->profiles != (void *) NULL) |
| 1280 | { |
| 1281 | const char |
| 1282 | *name; |
| 1283 | |
| 1284 | const StringInfo |
| 1285 | *profile; |
| 1286 | |
| 1287 | /* |
| 1288 | Generic profile. |
| 1289 | */ |
| 1290 | ResetImageProfileIterator(image); |
| 1291 | for (name=GetNextImageProfile(image); name != (const char *) NULL; ) |
| 1292 | { |
| 1293 | profile=GetImageProfile(image,name); |
| 1294 | if (profile != (StringInfo *) NULL) |
| 1295 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1296 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1297 | "profile:%s=%.20g\n",name,(double) |
| 1298 | GetStringInfoLength(profile)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1299 | (void) WriteBlobString(image,buffer); |
| 1300 | } |
| 1301 | name=GetNextImageProfile(image); |
| 1302 | } |
| 1303 | } |
| 1304 | if (image->montage != (char *) NULL) |
| 1305 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1306 | (void) FormatLocaleString(buffer,MagickPathExtent,"montage=%s\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1307 | image->montage); |
| 1308 | (void) WriteBlobString(image,buffer); |
| 1309 | } |
| 1310 | ResetImagePropertyIterator(image); |
| 1311 | property=GetNextImageProperty(image); |
| 1312 | while (property != (const char *) NULL) |
| 1313 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1314 | (void) FormatLocaleString(buffer,MagickPathExtent,"%s=",property); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1315 | (void) WriteBlobString(image,buffer); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1316 | value=GetImageProperty(image,property,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1317 | if (value != (const char *) NULL) |
| 1318 | { |
cristy | d76ed5d | 2012-05-20 16:15:57 +0000 | [diff] [blame] | 1319 | size_t |
| 1320 | length; |
| 1321 | |
cristy | 181c99c | 2012-05-20 16:14:14 +0000 | [diff] [blame] | 1322 | length=strlen(value); |
| 1323 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1324 | if (isspace((int) ((unsigned char) value[i])) != 0) |
| 1325 | break; |
cristy | 04e917f | 2013-08-17 00:54:17 +0000 | [diff] [blame] | 1326 | if ((i == (ssize_t) length) && (i != 0)) |
cristy | 181c99c | 2012-05-20 16:14:14 +0000 | [diff] [blame] | 1327 | (void) WriteBlob(image,length,(const unsigned char *) value); |
cristy | b880ee8 | 2012-04-07 15:08:14 +0000 | [diff] [blame] | 1328 | else |
| 1329 | { |
| 1330 | (void) WriteBlobByte(image,'{'); |
cristy | 181c99c | 2012-05-20 16:14:14 +0000 | [diff] [blame] | 1331 | if (strchr(value,'}') == (char *) NULL) |
| 1332 | (void) WriteBlob(image,length,(const unsigned char *) value); |
| 1333 | else |
| 1334 | for (i=0; i < (ssize_t) length; i++) |
| 1335 | { |
| 1336 | if (value[i] == (int) '}') |
| 1337 | (void) WriteBlobByte(image,'\\'); |
| 1338 | (void) WriteBlobByte(image,value[i]); |
| 1339 | } |
cristy | b880ee8 | 2012-04-07 15:08:14 +0000 | [diff] [blame] | 1340 | (void) WriteBlobByte(image,'}'); |
| 1341 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1342 | } |
| 1343 | (void) WriteBlobByte(image,'\n'); |
| 1344 | property=GetNextImageProperty(image); |
| 1345 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1346 | (void) WriteBlobString(image,"\f\n:\032"); |
| 1347 | if (image->montage != (char *) NULL) |
| 1348 | { |
| 1349 | /* |
| 1350 | Write montage tile directory. |
| 1351 | */ |
| 1352 | if (image->directory != (char *) NULL) |
| 1353 | (void) WriteBlobString(image,image->directory); |
| 1354 | (void) WriteBlobByte(image,'\0'); |
| 1355 | } |
| 1356 | if (image->profiles != 0) |
| 1357 | { |
| 1358 | const char |
| 1359 | *name; |
| 1360 | |
| 1361 | const StringInfo |
| 1362 | *profile; |
| 1363 | |
| 1364 | /* |
| 1365 | Write image profiles. |
| 1366 | */ |
| 1367 | ResetImageProfileIterator(image); |
| 1368 | name=GetNextImageProfile(image); |
| 1369 | while (name != (const char *) NULL) |
| 1370 | { |
| 1371 | profile=GetImageProfile(image,name); |
| 1372 | (void) WriteBlob(image,GetStringInfoLength(profile), |
| 1373 | GetStringInfoDatum(profile)); |
| 1374 | name=GetNextImageProfile(image); |
| 1375 | } |
| 1376 | } |
| 1377 | if (image->storage_class == PseudoClass) |
| 1378 | { |
| 1379 | size_t |
| 1380 | packet_size; |
| 1381 | |
| 1382 | unsigned char |
| 1383 | *colormap, |
| 1384 | *q; |
| 1385 | |
| 1386 | /* |
| 1387 | Allocate colormap. |
| 1388 | */ |
| 1389 | packet_size=(size_t) (3UL*depth/8UL); |
| 1390 | colormap=(unsigned char *) AcquireQuantumMemory(image->colors, |
| 1391 | packet_size*sizeof(*colormap)); |
| 1392 | if (colormap == (unsigned char *) NULL) |
| 1393 | return(MagickFalse); |
| 1394 | /* |
| 1395 | Write colormap to file. |
| 1396 | */ |
| 1397 | q=colormap; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1398 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1399 | { |
| 1400 | switch (depth) |
| 1401 | { |
| 1402 | default: |
| 1403 | ThrowWriterException(CorruptImageError,"ImageDepthNotSupported"); |
| 1404 | case 32: |
| 1405 | { |
cristy | 4cb162a | 2010-05-30 03:04:47 +0000 | [diff] [blame] | 1406 | unsigned int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1407 | pixel; |
| 1408 | |
| 1409 | pixel=ScaleQuantumToLong(image->colormap[i].red); |
| 1410 | q=PopLongPixel(MSBEndian,pixel,q); |
| 1411 | pixel=ScaleQuantumToLong(image->colormap[i].green); |
| 1412 | q=PopLongPixel(MSBEndian,pixel,q); |
| 1413 | pixel=ScaleQuantumToLong(image->colormap[i].blue); |
| 1414 | q=PopLongPixel(MSBEndian,pixel,q); |
dirk | c67e36d | 2014-05-18 06:58:25 +0000 | [diff] [blame] | 1415 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1416 | } |
| 1417 | case 16: |
| 1418 | { |
| 1419 | unsigned short |
| 1420 | pixel; |
| 1421 | |
| 1422 | pixel=ScaleQuantumToShort(image->colormap[i].red); |
| 1423 | q=PopShortPixel(MSBEndian,pixel,q); |
| 1424 | pixel=ScaleQuantumToShort(image->colormap[i].green); |
| 1425 | q=PopShortPixel(MSBEndian,pixel,q); |
| 1426 | pixel=ScaleQuantumToShort(image->colormap[i].blue); |
| 1427 | q=PopShortPixel(MSBEndian,pixel,q); |
| 1428 | break; |
| 1429 | } |
| 1430 | case 8: |
| 1431 | { |
| 1432 | unsigned char |
| 1433 | pixel; |
| 1434 | |
| 1435 | pixel=(unsigned char) ScaleQuantumToChar(image->colormap[i].red); |
| 1436 | q=PopCharPixel(pixel,q); |
| 1437 | pixel=(unsigned char) ScaleQuantumToChar( |
| 1438 | image->colormap[i].green); |
| 1439 | q=PopCharPixel(pixel,q); |
| 1440 | pixel=(unsigned char) ScaleQuantumToChar(image->colormap[i].blue); |
| 1441 | q=PopCharPixel(pixel,q); |
| 1442 | break; |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | (void) WriteBlob(image,packet_size*image->colors,colormap); |
| 1447 | colormap=(unsigned char *) RelinquishMagickMemory(colormap); |
| 1448 | } |
| 1449 | /* |
| 1450 | Initialize persistent pixel cache. |
| 1451 | */ |
| 1452 | status=PersistPixelCache(image,cache_filename,MagickFalse,&offset, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1453 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1454 | if (status == MagickFalse) |
| 1455 | ThrowWriterException(CacheError,"UnableToPersistPixelCache"); |
| 1456 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1457 | break; |
| 1458 | image=SyncNextImageInList(image); |
| 1459 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1460 | { |
| 1461 | status=image->progress_monitor(SaveImagesTag,scene, |
| 1462 | GetImageListLength(image),image->client_data); |
| 1463 | if (status == MagickFalse) |
| 1464 | break; |
| 1465 | } |
| 1466 | scene++; |
| 1467 | } while (image_info->adjoin != MagickFalse); |
| 1468 | (void) CloseBlob(image); |
| 1469 | return(status); |
| 1470 | } |