cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP RRRR OOO PPPP EEEEE RRRR TTTTT Y Y % |
| 7 | % P P R R O O P P E R R T Y Y % |
| 8 | % PPPP RRRR O O PPPP EEE RRRR T Y % |
| 9 | % P R R O O P E R R T Y % |
| 10 | % P R R OOO P EEEEE R R T Y % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Property Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % March 2000 % |
| 18 | % % |
| 19 | % % |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 20 | % Copyright 1999-2010 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 | */ |
| 43 | #include "magick/studio.h" |
cristy | 5a2ca48 | 2009-10-14 18:24:56 +0000 | [diff] [blame] | 44 | #include "magick/attribute.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 45 | #include "magick/cache.h" |
| 46 | #include "magick/color.h" |
| 47 | #include "magick/compare.h" |
| 48 | #include "magick/constitute.h" |
| 49 | #include "magick/draw.h" |
| 50 | #include "magick/effect.h" |
| 51 | #include "magick/exception.h" |
| 52 | #include "magick/exception-private.h" |
| 53 | #include "magick/fx.h" |
| 54 | #include "magick/fx-private.h" |
| 55 | #include "magick/gem.h" |
| 56 | #include "magick/geometry.h" |
cristy | f2e1166 | 2009-10-14 01:24:43 +0000 | [diff] [blame] | 57 | #include "magick/histogram.h" |
| 58 | #include "magick/image.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 59 | #include "magick/image.h" |
| 60 | #include "magick/layer.h" |
| 61 | #include "magick/list.h" |
cristy | 402d9c7 | 2010-01-18 17:34:43 +0000 | [diff] [blame] | 62 | #include "magick/magick.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 63 | #include "magick/memory_.h" |
| 64 | #include "magick/monitor.h" |
| 65 | #include "magick/montage.h" |
| 66 | #include "magick/option.h" |
| 67 | #include "magick/profile.h" |
| 68 | #include "magick/property.h" |
| 69 | #include "magick/quantum.h" |
| 70 | #include "magick/resource_.h" |
| 71 | #include "magick/splay-tree.h" |
| 72 | #include "magick/signature-private.h" |
| 73 | #include "magick/statistic.h" |
| 74 | #include "magick/string_.h" |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 75 | #include "magick/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | #include "magick/token.h" |
| 77 | #include "magick/utility.h" |
| 78 | #include "magick/xml-tree.h" |
| 79 | |
| 80 | /* |
| 81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 82 | % % |
| 83 | % % |
| 84 | % % |
| 85 | % C l o n e I m a g e P r o p e r t i e s % |
| 86 | % % |
| 87 | % % |
| 88 | % % |
| 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 90 | % |
| 91 | % CloneImageProperties() clones one or more image properties. |
| 92 | % |
| 93 | % The format of the CloneImageProperties method is: |
| 94 | % |
| 95 | % MagickBooleanType CloneImageProperties(Image *image, |
| 96 | % const Image *clone_image) |
| 97 | % |
| 98 | % A description of each parameter follows: |
| 99 | % |
| 100 | % o image: the image. |
| 101 | % |
| 102 | % o clone_image: the clone image. |
| 103 | % |
| 104 | */ |
| 105 | MagickExport MagickBooleanType CloneImageProperties(Image *image, |
| 106 | const Image *clone_image) |
| 107 | { |
| 108 | assert(image != (Image *) NULL); |
| 109 | assert(image->signature == MagickSignature); |
| 110 | if (image->debug != MagickFalse) |
| 111 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 112 | assert(clone_image != (const Image *) NULL); |
| 113 | assert(clone_image->signature == MagickSignature); |
| 114 | if (clone_image->debug != MagickFalse) |
| 115 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 116 | clone_image->filename); |
| 117 | (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent); |
| 118 | (void) CopyMagickString(image->magick_filename,clone_image->magick_filename, |
| 119 | MaxTextExtent); |
| 120 | image->compression=clone_image->compression; |
| 121 | image->quality=clone_image->quality; |
| 122 | image->depth=clone_image->depth; |
| 123 | image->background_color=clone_image->background_color; |
| 124 | image->border_color=clone_image->border_color; |
| 125 | image->matte_color=clone_image->matte_color; |
| 126 | image->transparent_color=clone_image->transparent_color; |
| 127 | image->gamma=clone_image->gamma; |
| 128 | image->chromaticity=clone_image->chromaticity; |
| 129 | image->rendering_intent=clone_image->rendering_intent; |
| 130 | image->black_point_compensation=clone_image->black_point_compensation; |
| 131 | image->units=clone_image->units; |
| 132 | image->montage=(char *) NULL; |
| 133 | image->directory=(char *) NULL; |
| 134 | (void) CloneString(&image->geometry,clone_image->geometry); |
| 135 | image->offset=clone_image->offset; |
| 136 | image->x_resolution=clone_image->x_resolution; |
| 137 | image->y_resolution=clone_image->y_resolution; |
| 138 | image->page=clone_image->page; |
| 139 | image->tile_offset=clone_image->tile_offset; |
| 140 | image->extract_info=clone_image->extract_info; |
| 141 | image->bias=clone_image->bias; |
| 142 | image->filter=clone_image->filter; |
| 143 | image->blur=clone_image->blur; |
| 144 | image->fuzz=clone_image->fuzz; |
| 145 | image->interlace=clone_image->interlace; |
| 146 | image->interpolate=clone_image->interpolate; |
| 147 | image->endian=clone_image->endian; |
| 148 | image->gravity=clone_image->gravity; |
| 149 | image->compose=clone_image->compose; |
| 150 | image->scene=clone_image->scene; |
| 151 | image->orientation=clone_image->orientation; |
| 152 | image->dispose=clone_image->dispose; |
| 153 | image->delay=clone_image->delay; |
| 154 | image->ticks_per_second=clone_image->ticks_per_second; |
| 155 | image->iterations=clone_image->iterations; |
| 156 | image->total_colors=clone_image->total_colors; |
| 157 | image->taint=clone_image->taint; |
| 158 | image->progress_monitor=clone_image->progress_monitor; |
| 159 | image->client_data=clone_image->client_data; |
| 160 | image->start_loop=clone_image->start_loop; |
| 161 | image->error=clone_image->error; |
| 162 | image->signature=clone_image->signature; |
| 163 | if (clone_image->properties != (void *) NULL) |
| 164 | { |
| 165 | if (image->properties != (void *) NULL) |
| 166 | DestroyImageProperties(image); |
| 167 | image->properties=CloneSplayTree((SplayTreeInfo *) |
| 168 | clone_image->properties,(void *(*)(void *)) ConstantString, |
| 169 | (void *(*)(void *)) ConstantString); |
| 170 | } |
| 171 | return(MagickTrue); |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 176 | % % |
| 177 | % % |
| 178 | % % |
| 179 | % D e f i n e I m a g e P r o p e r t y % |
| 180 | % % |
| 181 | % % |
| 182 | % % |
| 183 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 184 | % |
| 185 | % DefineImageProperty() associates a key/value pair with an image property. |
| 186 | % |
| 187 | % The format of the DefineImageProperty method is: |
| 188 | % |
| 189 | % MagickBooleanType DefineImageProperty(Image *image, |
| 190 | % const char *property) |
| 191 | % |
| 192 | % A description of each parameter follows: |
| 193 | % |
| 194 | % o image: the image. |
| 195 | % |
| 196 | % o property: the image property. |
| 197 | % |
| 198 | */ |
| 199 | MagickExport MagickBooleanType DefineImageProperty(Image *image, |
| 200 | const char *property) |
| 201 | { |
| 202 | char |
| 203 | key[MaxTextExtent], |
| 204 | value[MaxTextExtent]; |
| 205 | |
| 206 | register char |
| 207 | *p; |
| 208 | |
| 209 | assert(image != (Image *) NULL); |
| 210 | assert(property != (const char *) NULL); |
| 211 | (void) CopyMagickString(key,property,MaxTextExtent-1); |
| 212 | for (p=key; *p != '\0'; p++) |
| 213 | if (*p == '=') |
| 214 | break; |
| 215 | *value='\0'; |
| 216 | if (*p == '=') |
| 217 | (void) CopyMagickString(value,p+1,MaxTextExtent); |
| 218 | *p='\0'; |
| 219 | return(SetImageProperty(image,key,value)); |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 224 | % % |
| 225 | % % |
| 226 | % % |
| 227 | % D e l e t e I m a g e P r o p e r t y % |
| 228 | % % |
| 229 | % % |
| 230 | % % |
| 231 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 232 | % |
| 233 | % DeleteImageProperty() deletes an image property. |
| 234 | % |
| 235 | % The format of the DeleteImageProperty method is: |
| 236 | % |
| 237 | % MagickBooleanType DeleteImageProperty(Image *image,const char *property) |
| 238 | % |
| 239 | % A description of each parameter follows: |
| 240 | % |
| 241 | % o image: the image. |
| 242 | % |
| 243 | % o property: the image property. |
| 244 | % |
| 245 | */ |
| 246 | MagickExport MagickBooleanType DeleteImageProperty(Image *image, |
| 247 | const char *property) |
| 248 | { |
| 249 | assert(image != (Image *) NULL); |
| 250 | assert(image->signature == MagickSignature); |
| 251 | if (image->debug != MagickFalse) |
| 252 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 253 | image->filename); |
| 254 | if (image->properties == (void *) NULL) |
| 255 | return(MagickFalse); |
| 256 | return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property)); |
| 257 | } |
| 258 | |
| 259 | /* |
| 260 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 261 | % % |
| 262 | % % |
| 263 | % % |
| 264 | % D e s t r o y I m a g e P r o p e r t i e s % |
| 265 | % % |
| 266 | % % |
| 267 | % % |
| 268 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 269 | % |
| 270 | % DestroyImageProperties() releases memory associated with image property |
| 271 | % values. |
| 272 | % |
| 273 | % The format of the DestroyDefines method is: |
| 274 | % |
| 275 | % void DestroyImageProperties(Image *image) |
| 276 | % |
| 277 | % A description of each parameter follows: |
| 278 | % |
| 279 | % o image: the image. |
| 280 | % |
| 281 | */ |
| 282 | MagickExport void DestroyImageProperties(Image *image) |
| 283 | { |
| 284 | assert(image != (Image *) NULL); |
| 285 | assert(image->signature == MagickSignature); |
| 286 | if (image->debug != MagickFalse) |
| 287 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 288 | image->filename); |
| 289 | if (image->properties != (void *) NULL) |
| 290 | image->properties=(void *) DestroySplayTree((SplayTreeInfo *) |
| 291 | image->properties); |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 296 | % % |
| 297 | % % |
| 298 | % % |
| 299 | % F o r m a t I m a g e P r o p e r t y % |
| 300 | % % |
| 301 | % % |
| 302 | % % |
| 303 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 304 | % |
| 305 | % FormatImageProperty() permits formatted property/value pairs to be saved as |
| 306 | % an image proporty. |
| 307 | % |
| 308 | % The format of the FormatImageProperty method is: |
| 309 | % |
| 310 | % MagickBooleanType FormatImageProperty(Image *image,const char *property, |
| 311 | % const char *format,...) |
| 312 | % |
| 313 | % A description of each parameter follows. |
| 314 | % |
| 315 | % o image: The image. |
| 316 | % |
| 317 | % o property: The attribute property. |
| 318 | % |
| 319 | % o format: A string describing the format to use to write the remaining |
| 320 | % arguments. |
| 321 | % |
| 322 | */ |
| 323 | |
| 324 | MagickExport MagickBooleanType FormatImagePropertyList(Image *image, |
| 325 | const char *property,const char *format,va_list operands) |
| 326 | { |
| 327 | char |
| 328 | value[MaxTextExtent]; |
| 329 | |
| 330 | int |
| 331 | n; |
| 332 | |
| 333 | #if defined(MAGICKCORE_HAVE_VSNPRINTF) |
| 334 | n=vsnprintf(value,MaxTextExtent,format,operands); |
| 335 | #else |
| 336 | n=vsprintf(value,format,operands); |
| 337 | #endif |
| 338 | if (n < 0) |
| 339 | value[MaxTextExtent-1]='\0'; |
| 340 | return(SetImageProperty(image,property,value)); |
| 341 | } |
| 342 | |
| 343 | MagickExport MagickBooleanType FormatImageProperty(Image *image, |
| 344 | const char *property,const char *format,...) |
| 345 | { |
| 346 | MagickBooleanType |
| 347 | status; |
| 348 | |
| 349 | va_list |
| 350 | operands; |
| 351 | |
| 352 | va_start(operands,format); |
| 353 | status=FormatImagePropertyList(image,property,format,operands); |
| 354 | va_end(operands); |
| 355 | return(status); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 360 | % % |
| 361 | % % |
| 362 | % % |
| 363 | % G e t I m a g e P r o p e r t y % |
| 364 | % % |
| 365 | % % |
| 366 | % % |
| 367 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 368 | % |
| 369 | % GetImageProperty() gets a value associated with an image property. |
| 370 | % |
| 371 | % The format of the GetImageProperty method is: |
| 372 | % |
| 373 | % const char *GetImageProperty(const Image *image,const char *key) |
| 374 | % |
| 375 | % A description of each parameter follows: |
| 376 | % |
| 377 | % o image: the image. |
| 378 | % |
| 379 | % o key: the key. |
| 380 | % |
| 381 | */ |
| 382 | |
| 383 | static char |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 384 | *TracePSClippath(const unsigned char *,size_t,const size_t, |
| 385 | const size_t), |
| 386 | *TraceSVGClippath(const unsigned char *,size_t,const size_t, |
| 387 | const size_t); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | |
| 389 | static MagickBooleanType GetIPTCProperty(const Image *image,const char *key) |
| 390 | { |
| 391 | char |
| 392 | *attribute, |
| 393 | *message; |
| 394 | |
| 395 | const StringInfo |
| 396 | *profile; |
| 397 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 398 | long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | count, |
| 400 | dataset, |
| 401 | record; |
| 402 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 403 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | i; |
| 405 | |
| 406 | size_t |
| 407 | length; |
| 408 | |
| 409 | profile=GetImageProfile(image,"iptc"); |
| 410 | if (profile == (StringInfo *) NULL) |
| 411 | profile=GetImageProfile(image,"8bim"); |
| 412 | if (profile == (StringInfo *) NULL) |
| 413 | return(MagickFalse); |
| 414 | count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record); |
| 415 | if (count != 2) |
| 416 | return(MagickFalse); |
| 417 | attribute=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 418 | for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | { |
| 420 | length=1; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 421 | if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | continue; |
| 423 | length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8); |
| 424 | length|=GetStringInfoDatum(profile)[i+4]; |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 425 | if (((long) GetStringInfoDatum(profile)[i+1] == dataset) && |
| 426 | ((long) GetStringInfoDatum(profile)[i+2] == record)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 427 | { |
| 428 | message=(char *) NULL; |
| 429 | if (~length >= 1) |
| 430 | message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message)); |
| 431 | if (message != (char *) NULL) |
| 432 | { |
| 433 | (void) CopyMagickString(message,(char *) GetStringInfoDatum( |
| 434 | profile)+i+5,length+1); |
| 435 | (void) ConcatenateString(&attribute,message); |
| 436 | (void) ConcatenateString(&attribute,";"); |
| 437 | message=DestroyString(message); |
| 438 | } |
| 439 | } |
| 440 | i+=5; |
| 441 | } |
| 442 | if ((attribute == (char *) NULL) || (*attribute == ';')) |
| 443 | { |
| 444 | if (attribute != (char *) NULL) |
| 445 | attribute=DestroyString(attribute); |
| 446 | return(MagickFalse); |
| 447 | } |
| 448 | attribute[strlen(attribute)-1]='\0'; |
| 449 | (void) SetImageProperty((Image *) image,key,(const char *) attribute); |
| 450 | attribute=DestroyString(attribute); |
| 451 | return(MagickTrue); |
| 452 | } |
| 453 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 454 | static inline ssize_t MagickMax(const ssize_t x,const ssize_t y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 455 | { |
| 456 | if (x > y) |
| 457 | return(x); |
| 458 | return(y); |
| 459 | } |
| 460 | |
| 461 | static inline int ReadPropertyByte(const unsigned char **p,size_t *length) |
| 462 | { |
| 463 | int |
| 464 | c; |
| 465 | |
| 466 | if (*length < 1) |
| 467 | return(EOF); |
| 468 | c=(int) (*(*p)++); |
| 469 | (*length)--; |
| 470 | return(c); |
| 471 | } |
| 472 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 473 | static inline size_t ReadPropertyMSBLong(const unsigned char **p, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 474 | size_t *length) |
| 475 | { |
| 476 | int |
| 477 | c; |
| 478 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 479 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 480 | i; |
| 481 | |
| 482 | unsigned char |
| 483 | buffer[4]; |
| 484 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 485 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 486 | value; |
| 487 | |
| 488 | if (*length < 4) |
| 489 | return(~0UL); |
| 490 | for (i=0; i < 4; i++) |
| 491 | { |
| 492 | c=(int) (*(*p)++); |
| 493 | (*length)--; |
| 494 | buffer[i]=(unsigned char) c; |
| 495 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 496 | value=(size_t) (buffer[0] << 24); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 497 | value|=buffer[1] << 16; |
| 498 | value|=buffer[2] << 8; |
| 499 | value|=buffer[3]; |
| 500 | return(value & 0xffffffff); |
| 501 | } |
| 502 | |
| 503 | static inline unsigned short ReadPropertyMSBShort(const unsigned char **p, |
| 504 | size_t *length) |
| 505 | { |
| 506 | int |
| 507 | c; |
| 508 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 509 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 510 | i; |
| 511 | |
| 512 | unsigned char |
| 513 | buffer[2]; |
| 514 | |
| 515 | unsigned short |
| 516 | value; |
| 517 | |
| 518 | if (*length < 2) |
| 519 | return((unsigned short) ~0U); |
| 520 | for (i=0; i < 2; i++) |
| 521 | { |
| 522 | c=(int) (*(*p)++); |
| 523 | (*length)--; |
| 524 | buffer[i]=(unsigned char) c; |
| 525 | } |
| 526 | value=(unsigned short) (buffer[0] << 8); |
| 527 | value|=buffer[1]; |
| 528 | return((unsigned short) (value & 0xffff)); |
| 529 | } |
| 530 | |
| 531 | static MagickBooleanType Get8BIMProperty(const Image *image,const char *key) |
| 532 | { |
| 533 | char |
| 534 | *attribute, |
| 535 | format[MaxTextExtent], |
| 536 | name[MaxTextExtent], |
| 537 | *resource; |
| 538 | |
| 539 | const StringInfo |
| 540 | *profile; |
| 541 | |
| 542 | const unsigned char |
| 543 | *info; |
| 544 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 545 | long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | start, |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 547 | stop; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 548 | |
| 549 | MagickBooleanType |
| 550 | status; |
| 551 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 552 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 553 | i; |
| 554 | |
| 555 | ssize_t |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 556 | count, |
| 557 | id, |
| 558 | sub_number; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | |
| 560 | size_t |
| 561 | length; |
| 562 | |
| 563 | /* |
| 564 | There's no newlines in path names, so it's safe as terminator. |
| 565 | */ |
| 566 | profile=GetImageProfile(image,"8bim"); |
| 567 | if (profile == (StringInfo *) NULL) |
| 568 | return(MagickFalse); |
| 569 | count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name, |
| 570 | format); |
| 571 | if ((count != 2) && (count != 3) && (count != 4)) |
| 572 | return(MagickFalse); |
| 573 | if (count < 4) |
| 574 | (void) CopyMagickString(format,"SVG",MaxTextExtent); |
| 575 | if (count < 3) |
| 576 | *name='\0'; |
| 577 | sub_number=1; |
| 578 | if (*name == '#') |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 579 | sub_number=StringToLong(&name[1]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 580 | sub_number=MagickMax(sub_number,1L); |
| 581 | resource=(char *) NULL; |
| 582 | status=MagickFalse; |
| 583 | length=GetStringInfoLength(profile); |
| 584 | info=GetStringInfoDatum(profile); |
| 585 | while ((length > 0) && (status == MagickFalse)) |
| 586 | { |
| 587 | if (ReadPropertyByte(&info,&length) != (unsigned char) '8') |
| 588 | continue; |
| 589 | if (ReadPropertyByte(&info,&length) != (unsigned char) 'B') |
| 590 | continue; |
| 591 | if (ReadPropertyByte(&info,&length) != (unsigned char) 'I') |
| 592 | continue; |
| 593 | if (ReadPropertyByte(&info,&length) != (unsigned char) 'M') |
| 594 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 595 | id=(ssize_t) ReadPropertyMSBShort(&info,&length); |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 596 | if (id < (ssize_t) start) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 597 | continue; |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 598 | if (id > (ssize_t) stop) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 599 | continue; |
| 600 | if (resource != (char *) NULL) |
| 601 | resource=DestroyString(resource); |
| 602 | count=(ssize_t) ReadPropertyByte(&info,&length); |
| 603 | if ((count != 0) && ((size_t) count <= length)) |
| 604 | { |
| 605 | resource=(char *) NULL; |
| 606 | if (~(1UL*count) >= MaxTextExtent) |
| 607 | resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent, |
| 608 | sizeof(*resource)); |
| 609 | if (resource != (char *) NULL) |
| 610 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 611 | for (i=0; i < (ssize_t) count; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 612 | resource[i]=(char) ReadPropertyByte(&info,&length); |
| 613 | resource[count]='\0'; |
| 614 | } |
| 615 | } |
| 616 | if ((count & 0x01) == 0) |
| 617 | (void) ReadPropertyByte(&info,&length); |
| 618 | count=(ssize_t) ReadPropertyMSBLong(&info,&length); |
| 619 | if ((*name != '\0') && (*name != '#')) |
| 620 | if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0)) |
| 621 | { |
| 622 | /* |
| 623 | No name match, scroll forward and try next. |
| 624 | */ |
| 625 | info+=count; |
| 626 | length-=count; |
| 627 | continue; |
| 628 | } |
| 629 | if ((*name == '#') && (sub_number != 1)) |
| 630 | { |
| 631 | /* |
| 632 | No numbered match, scroll forward and try next. |
| 633 | */ |
| 634 | sub_number--; |
| 635 | info+=count; |
| 636 | length-=count; |
| 637 | continue; |
| 638 | } |
| 639 | /* |
| 640 | We have the resource of interest. |
| 641 | */ |
| 642 | attribute=(char *) NULL; |
| 643 | if (~(1UL*count) >= MaxTextExtent) |
| 644 | attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent, |
| 645 | sizeof(*attribute)); |
| 646 | if (attribute != (char *) NULL) |
| 647 | { |
| 648 | (void) CopyMagickMemory(attribute,(char *) info,(size_t) count); |
| 649 | attribute[count]='\0'; |
| 650 | info+=count; |
| 651 | length-=count; |
| 652 | if ((id <= 1999) || (id >= 2999)) |
| 653 | (void) SetImageProperty((Image *) image,key,(const char *) |
| 654 | attribute); |
| 655 | else |
| 656 | { |
| 657 | char |
| 658 | *path; |
| 659 | |
| 660 | if (LocaleCompare(format,"svg") == 0) |
| 661 | path=TraceSVGClippath((unsigned char *) attribute,(size_t) count, |
| 662 | image->columns,image->rows); |
| 663 | else |
| 664 | path=TracePSClippath((unsigned char *) attribute,(size_t) count, |
| 665 | image->columns,image->rows); |
| 666 | (void) SetImageProperty((Image *) image,key,(const char *) path); |
| 667 | path=DestroyString(path); |
| 668 | } |
| 669 | attribute=DestroyString(attribute); |
| 670 | status=MagickTrue; |
| 671 | } |
| 672 | } |
| 673 | if (resource != (char *) NULL) |
| 674 | resource=DestroyString(resource); |
| 675 | return(status); |
| 676 | } |
| 677 | |
| 678 | static inline unsigned short ReadPropertyShort(const EndianType endian, |
| 679 | const unsigned char *buffer) |
| 680 | { |
| 681 | unsigned short |
| 682 | value; |
| 683 | |
| 684 | if (endian == MSBEndian) |
| 685 | { |
| 686 | value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) | |
| 687 | ((unsigned char *) buffer)[1]); |
| 688 | return((unsigned short) (value & 0xffff)); |
| 689 | } |
| 690 | value=(unsigned short) ((buffer[1] << 8) | buffer[0]); |
| 691 | return((unsigned short) (value & 0xffff)); |
| 692 | } |
| 693 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 694 | static inline size_t ReadPropertyLong(const EndianType endian, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 695 | const unsigned char *buffer) |
| 696 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 697 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 698 | value; |
| 699 | |
| 700 | if (endian == MSBEndian) |
| 701 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 702 | value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 703 | (buffer[2] << 8) | buffer[3]); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 704 | return((size_t) (value & 0xffffffff)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 705 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 706 | value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 707 | (buffer[1] << 8 ) | (buffer[0])); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 708 | return((size_t) (value & 0xffffffff)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | static MagickBooleanType GetEXIFProperty(const Image *image, |
| 712 | const char *property) |
| 713 | { |
| 714 | #define MaxDirectoryStack 16 |
| 715 | #define EXIF_DELIMITER "\n" |
| 716 | #define EXIF_NUM_FORMATS 12 |
| 717 | #define EXIF_FMT_BYTE 1 |
| 718 | #define EXIF_FMT_STRING 2 |
| 719 | #define EXIF_FMT_USHORT 3 |
| 720 | #define EXIF_FMT_ULONG 4 |
| 721 | #define EXIF_FMT_URATIONAL 5 |
| 722 | #define EXIF_FMT_SBYTE 6 |
| 723 | #define EXIF_FMT_UNDEFINED 7 |
| 724 | #define EXIF_FMT_SSHORT 8 |
| 725 | #define EXIF_FMT_SLONG 9 |
| 726 | #define EXIF_FMT_SRATIONAL 10 |
| 727 | #define EXIF_FMT_SINGLE 11 |
| 728 | #define EXIF_FMT_DOUBLE 12 |
| 729 | #define TAG_EXIF_OFFSET 0x8769 |
| 730 | #define TAG_GPS_OFFSET 0x8825 |
| 731 | #define TAG_INTEROP_OFFSET 0xa005 |
| 732 | |
| 733 | #define EXIFMultipleValues(size, format, arg) \ |
| 734 | { \ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 735 | ssize_t \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 736 | component; \ |
| 737 | \ |
| 738 | size_t \ |
| 739 | length; \ |
| 740 | \ |
| 741 | unsigned char \ |
| 742 | *p1; \ |
| 743 | \ |
| 744 | length=0; \ |
| 745 | p1=p; \ |
| 746 | for (component=0; component < components; component++) \ |
| 747 | { \ |
| 748 | length+=FormatMagickString(buffer+length,MaxTextExtent-length, \ |
| 749 | format", ",arg); \ |
| 750 | if (length >= MaxTextExtent - 1) \ |
| 751 | length=MaxTextExtent-1; \ |
| 752 | p1+=size; \ |
| 753 | } \ |
| 754 | if (length > 1) \ |
| 755 | buffer[length-2]='\0'; \ |
| 756 | value=AcquireString(buffer); \ |
| 757 | } |
| 758 | |
| 759 | #define EXIFMultipleFractions(size, format, arg1, arg2) \ |
| 760 | { \ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 761 | ssize_t \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 762 | component; \ |
| 763 | \ |
| 764 | size_t \ |
| 765 | length; \ |
| 766 | \ |
| 767 | unsigned char \ |
| 768 | *p1; \ |
| 769 | \ |
| 770 | length=0; \ |
| 771 | p1=p; \ |
| 772 | for (component=0; component < components; component++) \ |
| 773 | { \ |
| 774 | length+=FormatMagickString(buffer+length,MaxTextExtent-length, \ |
| 775 | format", ",arg1, arg2); \ |
| 776 | if (length >= MaxTextExtent - 1) \ |
| 777 | length=MaxTextExtent-1; \ |
| 778 | p1+=size; \ |
| 779 | } \ |
| 780 | if (length > 1) \ |
| 781 | buffer[length-2]='\0'; \ |
| 782 | value=AcquireString(buffer); \ |
| 783 | } |
| 784 | |
| 785 | typedef struct _DirectoryInfo |
| 786 | { |
| 787 | const unsigned char |
| 788 | *directory; |
| 789 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 790 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 791 | entry, |
| 792 | offset; |
| 793 | } DirectoryInfo; |
| 794 | |
| 795 | typedef struct _TagInfo |
| 796 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 797 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 798 | tag; |
| 799 | |
| 800 | const char |
| 801 | *description; |
| 802 | } TagInfo; |
| 803 | |
| 804 | static TagInfo |
| 805 | EXIFTag[] = |
| 806 | { |
| 807 | { 0x001, "exif:InteroperabilityIndex" }, |
| 808 | { 0x002, "exif:InteroperabilityVersion" }, |
| 809 | { 0x100, "exif:ImageWidth" }, |
| 810 | { 0x101, "exif:ImageLength" }, |
| 811 | { 0x102, "exif:BitsPerSample" }, |
| 812 | { 0x103, "exif:Compression" }, |
| 813 | { 0x106, "exif:PhotometricInterpretation" }, |
| 814 | { 0x10a, "exif:FillOrder" }, |
| 815 | { 0x10d, "exif:DocumentName" }, |
| 816 | { 0x10e, "exif:ImageDescription" }, |
| 817 | { 0x10f, "exif:Make" }, |
| 818 | { 0x110, "exif:Model" }, |
| 819 | { 0x111, "exif:StripOffsets" }, |
| 820 | { 0x112, "exif:Orientation" }, |
| 821 | { 0x115, "exif:SamplesPerPixel" }, |
| 822 | { 0x116, "exif:RowsPerStrip" }, |
| 823 | { 0x117, "exif:StripByteCounts" }, |
| 824 | { 0x11a, "exif:XResolution" }, |
| 825 | { 0x11b, "exif:YResolution" }, |
| 826 | { 0x11c, "exif:PlanarConfiguration" }, |
| 827 | { 0x11d, "exif:PageName" }, |
| 828 | { 0x11e, "exif:XPosition" }, |
| 829 | { 0x11f, "exif:YPosition" }, |
| 830 | { 0x118, "exif:MinSampleValue" }, |
| 831 | { 0x119, "exif:MaxSampleValue" }, |
| 832 | { 0x120, "exif:FreeOffsets" }, |
| 833 | { 0x121, "exif:FreeByteCounts" }, |
| 834 | { 0x122, "exif:GrayResponseUnit" }, |
| 835 | { 0x123, "exif:GrayResponseCurve" }, |
| 836 | { 0x124, "exif:T4Options" }, |
| 837 | { 0x125, "exif:T6Options" }, |
| 838 | { 0x128, "exif:ResolutionUnit" }, |
| 839 | { 0x12d, "exif:TransferFunction" }, |
| 840 | { 0x131, "exif:Software" }, |
| 841 | { 0x132, "exif:DateTime" }, |
| 842 | { 0x13b, "exif:Artist" }, |
| 843 | { 0x13e, "exif:WhitePoint" }, |
| 844 | { 0x13f, "exif:PrimaryChromaticities" }, |
| 845 | { 0x140, "exif:ColorMap" }, |
| 846 | { 0x141, "exif:HalfToneHints" }, |
| 847 | { 0x142, "exif:TileWidth" }, |
| 848 | { 0x143, "exif:TileLength" }, |
| 849 | { 0x144, "exif:TileOffsets" }, |
| 850 | { 0x145, "exif:TileByteCounts" }, |
| 851 | { 0x14a, "exif:SubIFD" }, |
| 852 | { 0x14c, "exif:InkSet" }, |
| 853 | { 0x14d, "exif:InkNames" }, |
| 854 | { 0x14e, "exif:NumberOfInks" }, |
| 855 | { 0x150, "exif:DotRange" }, |
| 856 | { 0x151, "exif:TargetPrinter" }, |
| 857 | { 0x152, "exif:ExtraSample" }, |
| 858 | { 0x153, "exif:SampleFormat" }, |
| 859 | { 0x154, "exif:SMinSampleValue" }, |
| 860 | { 0x155, "exif:SMaxSampleValue" }, |
| 861 | { 0x156, "exif:TransferRange" }, |
| 862 | { 0x157, "exif:ClipPath" }, |
| 863 | { 0x158, "exif:XClipPathUnits" }, |
| 864 | { 0x159, "exif:YClipPathUnits" }, |
| 865 | { 0x15a, "exif:Indexed" }, |
| 866 | { 0x15b, "exif:JPEGTables" }, |
| 867 | { 0x15f, "exif:OPIProxy" }, |
| 868 | { 0x200, "exif:JPEGProc" }, |
| 869 | { 0x201, "exif:JPEGInterchangeFormat" }, |
| 870 | { 0x202, "exif:JPEGInterchangeFormatLength" }, |
| 871 | { 0x203, "exif:JPEGRestartInterval" }, |
| 872 | { 0x205, "exif:JPEGLosslessPredictors" }, |
| 873 | { 0x206, "exif:JPEGPointTransforms" }, |
| 874 | { 0x207, "exif:JPEGQTables" }, |
| 875 | { 0x208, "exif:JPEGDCTables" }, |
| 876 | { 0x209, "exif:JPEGACTables" }, |
| 877 | { 0x211, "exif:YCbCrCoefficients" }, |
| 878 | { 0x212, "exif:YCbCrSubSampling" }, |
| 879 | { 0x213, "exif:YCbCrPositioning" }, |
| 880 | { 0x214, "exif:ReferenceBlackWhite" }, |
| 881 | { 0x2bc, "exif:ExtensibleMetadataPlatform" }, |
| 882 | { 0x301, "exif:Gamma" }, |
| 883 | { 0x302, "exif:ICCProfileDescriptor" }, |
| 884 | { 0x303, "exif:SRGBRenderingIntent" }, |
| 885 | { 0x320, "exif:ImageTitle" }, |
| 886 | { 0x5001, "exif:ResolutionXUnit" }, |
| 887 | { 0x5002, "exif:ResolutionYUnit" }, |
| 888 | { 0x5003, "exif:ResolutionXLengthUnit" }, |
| 889 | { 0x5004, "exif:ResolutionYLengthUnit" }, |
| 890 | { 0x5005, "exif:PrintFlags" }, |
| 891 | { 0x5006, "exif:PrintFlagsVersion" }, |
| 892 | { 0x5007, "exif:PrintFlagsCrop" }, |
| 893 | { 0x5008, "exif:PrintFlagsBleedWidth" }, |
| 894 | { 0x5009, "exif:PrintFlagsBleedWidthScale" }, |
| 895 | { 0x500A, "exif:HalftoneLPI" }, |
| 896 | { 0x500B, "exif:HalftoneLPIUnit" }, |
| 897 | { 0x500C, "exif:HalftoneDegree" }, |
| 898 | { 0x500D, "exif:HalftoneShape" }, |
| 899 | { 0x500E, "exif:HalftoneMisc" }, |
| 900 | { 0x500F, "exif:HalftoneScreen" }, |
| 901 | { 0x5010, "exif:JPEGQuality" }, |
| 902 | { 0x5011, "exif:GridSize" }, |
| 903 | { 0x5012, "exif:ThumbnailFormat" }, |
| 904 | { 0x5013, "exif:ThumbnailWidth" }, |
| 905 | { 0x5014, "exif:ThumbnailHeight" }, |
| 906 | { 0x5015, "exif:ThumbnailColorDepth" }, |
| 907 | { 0x5016, "exif:ThumbnailPlanes" }, |
| 908 | { 0x5017, "exif:ThumbnailRawBytes" }, |
| 909 | { 0x5018, "exif:ThumbnailSize" }, |
| 910 | { 0x5019, "exif:ThumbnailCompressedSize" }, |
| 911 | { 0x501a, "exif:ColorTransferFunction" }, |
| 912 | { 0x501b, "exif:ThumbnailData" }, |
| 913 | { 0x5020, "exif:ThumbnailImageWidth" }, |
| 914 | { 0x5021, "exif:ThumbnailImageHeight" }, |
| 915 | { 0x5022, "exif:ThumbnailBitsPerSample" }, |
| 916 | { 0x5023, "exif:ThumbnailCompression" }, |
| 917 | { 0x5024, "exif:ThumbnailPhotometricInterp" }, |
| 918 | { 0x5025, "exif:ThumbnailImageDescription" }, |
| 919 | { 0x5026, "exif:ThumbnailEquipMake" }, |
| 920 | { 0x5027, "exif:ThumbnailEquipModel" }, |
| 921 | { 0x5028, "exif:ThumbnailStripOffsets" }, |
| 922 | { 0x5029, "exif:ThumbnailOrientation" }, |
| 923 | { 0x502a, "exif:ThumbnailSamplesPerPixel" }, |
| 924 | { 0x502b, "exif:ThumbnailRowsPerStrip" }, |
| 925 | { 0x502c, "exif:ThumbnailStripBytesCount" }, |
| 926 | { 0x502d, "exif:ThumbnailResolutionX" }, |
| 927 | { 0x502e, "exif:ThumbnailResolutionY" }, |
| 928 | { 0x502f, "exif:ThumbnailPlanarConfig" }, |
| 929 | { 0x5030, "exif:ThumbnailResolutionUnit" }, |
| 930 | { 0x5031, "exif:ThumbnailTransferFunction" }, |
| 931 | { 0x5032, "exif:ThumbnailSoftwareUsed" }, |
| 932 | { 0x5033, "exif:ThumbnailDateTime" }, |
| 933 | { 0x5034, "exif:ThumbnailArtist" }, |
| 934 | { 0x5035, "exif:ThumbnailWhitePoint" }, |
| 935 | { 0x5036, "exif:ThumbnailPrimaryChromaticities" }, |
| 936 | { 0x5037, "exif:ThumbnailYCbCrCoefficients" }, |
| 937 | { 0x5038, "exif:ThumbnailYCbCrSubsampling" }, |
| 938 | { 0x5039, "exif:ThumbnailYCbCrPositioning" }, |
| 939 | { 0x503A, "exif:ThumbnailRefBlackWhite" }, |
| 940 | { 0x503B, "exif:ThumbnailCopyRight" }, |
| 941 | { 0x5090, "exif:LuminanceTable" }, |
| 942 | { 0x5091, "exif:ChrominanceTable" }, |
| 943 | { 0x5100, "exif:FrameDelay" }, |
| 944 | { 0x5101, "exif:LoopCount" }, |
| 945 | { 0x5110, "exif:PixelUnit" }, |
| 946 | { 0x5111, "exif:PixelPerUnitX" }, |
| 947 | { 0x5112, "exif:PixelPerUnitY" }, |
| 948 | { 0x5113, "exif:PaletteHistogram" }, |
| 949 | { 0x1000, "exif:RelatedImageFileFormat" }, |
| 950 | { 0x1001, "exif:RelatedImageLength" }, |
| 951 | { 0x1002, "exif:RelatedImageWidth" }, |
| 952 | { 0x800d, "exif:ImageID" }, |
| 953 | { 0x80e3, "exif:Matteing" }, |
| 954 | { 0x80e4, "exif:DataType" }, |
| 955 | { 0x80e5, "exif:ImageDepth" }, |
| 956 | { 0x80e6, "exif:TileDepth" }, |
| 957 | { 0x828d, "exif:CFARepeatPatternDim" }, |
| 958 | { 0x828e, "exif:CFAPattern2" }, |
| 959 | { 0x828f, "exif:BatteryLevel" }, |
| 960 | { 0x8298, "exif:Copyright" }, |
| 961 | { 0x829a, "exif:ExposureTime" }, |
| 962 | { 0x829d, "exif:FNumber" }, |
| 963 | { 0x83bb, "exif:IPTC/NAA" }, |
| 964 | { 0x84e3, "exif:IT8RasterPadding" }, |
| 965 | { 0x84e5, "exif:IT8ColorTable" }, |
| 966 | { 0x8649, "exif:ImageResourceInformation" }, |
| 967 | { 0x8769, "exif:ExifOffset" }, |
| 968 | { 0x8773, "exif:InterColorProfile" }, |
| 969 | { 0x8822, "exif:ExposureProgram" }, |
| 970 | { 0x8824, "exif:SpectralSensitivity" }, |
| 971 | { 0x8825, "exif:GPSInfo" }, |
| 972 | { 0x8827, "exif:ISOSpeedRatings" }, |
| 973 | { 0x8828, "exif:OECF" }, |
| 974 | { 0x8829, "exif:Interlace" }, |
| 975 | { 0x882a, "exif:TimeZoneOffset" }, |
| 976 | { 0x882b, "exif:SelfTimerMode" }, |
| 977 | { 0x9000, "exif:ExifVersion" }, |
| 978 | { 0x9003, "exif:DateTimeOriginal" }, |
| 979 | { 0x9004, "exif:DateTimeDigitized" }, |
| 980 | { 0x9101, "exif:ComponentsConfiguration" }, |
| 981 | { 0x9102, "exif:CompressedBitsPerPixel" }, |
| 982 | { 0x9201, "exif:ShutterSpeedValue" }, |
| 983 | { 0x9202, "exif:ApertureValue" }, |
| 984 | { 0x9203, "exif:BrightnessValue" }, |
| 985 | { 0x9204, "exif:ExposureBiasValue" }, |
| 986 | { 0x9205, "exif:MaxApertureValue" }, |
| 987 | { 0x9206, "exif:SubjectDistance" }, |
| 988 | { 0x9207, "exif:MeteringMode" }, |
| 989 | { 0x9208, "exif:LightSource" }, |
| 990 | { 0x9209, "exif:Flash" }, |
| 991 | { 0x920a, "exif:FocalLength" }, |
| 992 | { 0x920b, "exif:FlashEnergy" }, |
| 993 | { 0x920c, "exif:SpatialFrequencyResponse" }, |
| 994 | { 0x920d, "exif:Noise" }, |
| 995 | { 0x9211, "exif:ImageNumber" }, |
| 996 | { 0x9212, "exif:SecurityClassification" }, |
| 997 | { 0x9213, "exif:ImageHistory" }, |
| 998 | { 0x9214, "exif:SubjectArea" }, |
| 999 | { 0x9215, "exif:ExposureIndex" }, |
| 1000 | { 0x9216, "exif:TIFF-EPStandardID" }, |
| 1001 | { 0x927c, "exif:MakerNote" }, |
| 1002 | { 0x9C9b, "exif:WinXP-Title" }, |
| 1003 | { 0x9C9c, "exif:WinXP-Comments" }, |
| 1004 | { 0x9C9d, "exif:WinXP-Author" }, |
| 1005 | { 0x9C9e, "exif:WinXP-Keywords" }, |
| 1006 | { 0x9C9f, "exif:WinXP-Subject" }, |
| 1007 | { 0x9286, "exif:UserComment" }, |
| 1008 | { 0x9290, "exif:SubSecTime" }, |
| 1009 | { 0x9291, "exif:SubSecTimeOriginal" }, |
| 1010 | { 0x9292, "exif:SubSecTimeDigitized" }, |
| 1011 | { 0xa000, "exif:FlashPixVersion" }, |
| 1012 | { 0xa001, "exif:ColorSpace" }, |
| 1013 | { 0xa002, "exif:ExifImageWidth" }, |
| 1014 | { 0xa003, "exif:ExifImageLength" }, |
| 1015 | { 0xa004, "exif:RelatedSoundFile" }, |
| 1016 | { 0xa005, "exif:InteroperabilityOffset" }, |
| 1017 | { 0xa20b, "exif:FlashEnergy" }, |
| 1018 | { 0xa20c, "exif:SpatialFrequencyResponse" }, |
| 1019 | { 0xa20d, "exif:Noise" }, |
| 1020 | { 0xa20e, "exif:FocalPlaneXResolution" }, |
| 1021 | { 0xa20f, "exif:FocalPlaneYResolution" }, |
| 1022 | { 0xa210, "exif:FocalPlaneResolutionUnit" }, |
| 1023 | { 0xa214, "exif:SubjectLocation" }, |
| 1024 | { 0xa215, "exif:ExposureIndex" }, |
| 1025 | { 0xa216, "exif:TIFF/EPStandardID" }, |
| 1026 | { 0xa217, "exif:SensingMethod" }, |
| 1027 | { 0xa300, "exif:FileSource" }, |
| 1028 | { 0xa301, "exif:SceneType" }, |
| 1029 | { 0xa302, "exif:CFAPattern" }, |
| 1030 | { 0xa401, "exif:CustomRendered" }, |
| 1031 | { 0xa402, "exif:ExposureMode" }, |
| 1032 | { 0xa403, "exif:WhiteBalance" }, |
| 1033 | { 0xa404, "exif:DigitalZoomRatio" }, |
| 1034 | { 0xa405, "exif:FocalLengthIn35mmFilm" }, |
| 1035 | { 0xa406, "exif:SceneCaptureType" }, |
| 1036 | { 0xa407, "exif:GainControl" }, |
| 1037 | { 0xa408, "exif:Contrast" }, |
| 1038 | { 0xa409, "exif:Saturation" }, |
| 1039 | { 0xa40a, "exif:Sharpness" }, |
| 1040 | { 0xa40b, "exif:DeviceSettingDescription" }, |
| 1041 | { 0xa40c, "exif:SubjectDistanceRange" }, |
| 1042 | { 0xa420, "exif:ImageUniqueID" }, |
| 1043 | { 0xc4a5, "exif:PrintImageMatching" }, |
cristy | b3fea0e | 2009-11-28 01:46:20 +0000 | [diff] [blame] | 1044 | { 0xa500, "exif:Gamma" }, |
| 1045 | { 0xc640, "exif:CR2Slice" }, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1046 | { 0x10000, "exif:GPSVersionID" }, |
| 1047 | { 0x10001, "exif:GPSLatitudeRef" }, |
| 1048 | { 0x10002, "exif:GPSLatitude" }, |
| 1049 | { 0x10003, "exif:GPSLongitudeRef" }, |
| 1050 | { 0x10004, "exif:GPSLongitude" }, |
| 1051 | { 0x10005, "exif:GPSAltitudeRef" }, |
| 1052 | { 0x10006, "exif:GPSAltitude" }, |
| 1053 | { 0x10007, "exif:GPSTimeStamp" }, |
| 1054 | { 0x10008, "exif:GPSSatellites" }, |
| 1055 | { 0x10009, "exif:GPSStatus" }, |
| 1056 | { 0x1000a, "exif:GPSMeasureMode" }, |
| 1057 | { 0x1000b, "exif:GPSDop" }, |
| 1058 | { 0x1000c, "exif:GPSSpeedRef" }, |
| 1059 | { 0x1000d, "exif:GPSSpeed" }, |
| 1060 | { 0x1000e, "exif:GPSTrackRef" }, |
| 1061 | { 0x1000f, "exif:GPSTrack" }, |
| 1062 | { 0x10010, "exif:GPSImgDirectionRef" }, |
| 1063 | { 0x10011, "exif:GPSImgDirection" }, |
| 1064 | { 0x10012, "exif:GPSMapDatum" }, |
| 1065 | { 0x10013, "exif:GPSDestLatitudeRef" }, |
| 1066 | { 0x10014, "exif:GPSDestLatitude" }, |
| 1067 | { 0x10015, "exif:GPSDestLongitudeRef" }, |
| 1068 | { 0x10016, "exif:GPSDestLongitude" }, |
| 1069 | { 0x10017, "exif:GPSDestBearingRef" }, |
| 1070 | { 0x10018, "exif:GPSDestBearing" }, |
| 1071 | { 0x10019, "exif:GPSDestDistanceRef" }, |
| 1072 | { 0x1001a, "exif:GPSDestDistance" }, |
| 1073 | { 0x1001b, "exif:GPSProcessingMethod" }, |
| 1074 | { 0x1001c, "exif:GPSAreaInformation" }, |
| 1075 | { 0x1001d, "exif:GPSDateStamp" }, |
| 1076 | { 0x1001e, "exif:GPSDifferential" }, |
| 1077 | { 0x0000, NULL} |
| 1078 | }; |
| 1079 | |
| 1080 | const StringInfo |
| 1081 | *profile; |
| 1082 | |
| 1083 | const unsigned char |
| 1084 | *directory, |
| 1085 | *exif; |
| 1086 | |
| 1087 | DirectoryInfo |
| 1088 | directory_stack[MaxDirectoryStack]; |
| 1089 | |
| 1090 | EndianType |
| 1091 | endian; |
| 1092 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1093 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 | all, |
| 1095 | id, |
| 1096 | level, |
| 1097 | tag_value; |
| 1098 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1099 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1100 | i; |
| 1101 | |
| 1102 | size_t |
| 1103 | length; |
| 1104 | |
| 1105 | ssize_t |
| 1106 | offset; |
| 1107 | |
| 1108 | static int |
| 1109 | tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}; |
| 1110 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1111 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1112 | entry, |
| 1113 | number_entries, |
| 1114 | tag_offset, |
| 1115 | tag; |
| 1116 | |
| 1117 | /* |
| 1118 | If EXIF data exists, then try to parse the request for a tag. |
| 1119 | */ |
| 1120 | profile=GetImageProfile(image,"exif"); |
| 1121 | if (profile == (StringInfo *) NULL) |
| 1122 | return(MagickFalse); |
| 1123 | if ((property == (const char *) NULL) || (*property == '\0')) |
| 1124 | return(MagickFalse); |
| 1125 | while (isspace((int) ((unsigned char) *property)) != 0) |
| 1126 | property++; |
| 1127 | all=0; |
| 1128 | tag=(~0UL); |
| 1129 | switch (*(property+5)) |
| 1130 | { |
| 1131 | case '*': |
| 1132 | { |
| 1133 | /* |
| 1134 | Caller has asked for all the tags in the EXIF data. |
| 1135 | */ |
| 1136 | tag=0; |
| 1137 | all=1; /* return the data in description=value format */ |
| 1138 | break; |
| 1139 | } |
| 1140 | case '!': |
| 1141 | { |
| 1142 | tag=0; |
| 1143 | all=2; /* return the data in tagid=value format */ |
| 1144 | break; |
| 1145 | } |
| 1146 | case '#': |
| 1147 | case '@': |
| 1148 | { |
| 1149 | int |
| 1150 | c; |
| 1151 | |
| 1152 | size_t |
| 1153 | n; |
| 1154 | |
| 1155 | /* |
| 1156 | Check for a hex based tag specification first. |
| 1157 | */ |
| 1158 | tag=(*(property+5) == '@') ? 1UL : 0UL; |
| 1159 | property+=6; |
| 1160 | n=strlen(property); |
| 1161 | if (n != 4) |
| 1162 | return(MagickFalse); |
| 1163 | /* |
| 1164 | Parse tag specification as a hex number. |
| 1165 | */ |
| 1166 | n/=4; |
| 1167 | do |
| 1168 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1169 | for (i=(ssize_t) n-1L; i >= 0; i--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1170 | { |
| 1171 | c=(*property++); |
| 1172 | tag<<=4; |
| 1173 | if ((c >= '0') && (c <= '9')) |
| 1174 | tag|=(c-'0'); |
| 1175 | else |
| 1176 | if ((c >= 'A') && (c <= 'F')) |
| 1177 | tag|=(c-('A'-10)); |
| 1178 | else |
| 1179 | if ((c >= 'a') && (c <= 'f')) |
| 1180 | tag|=(c-('a'-10)); |
| 1181 | else |
| 1182 | return(MagickFalse); |
| 1183 | } |
| 1184 | } while (*property != '\0'); |
| 1185 | break; |
| 1186 | } |
| 1187 | default: |
| 1188 | { |
| 1189 | /* |
| 1190 | Try to match the text with a tag name instead. |
| 1191 | */ |
| 1192 | for (i=0; ; i++) |
| 1193 | { |
| 1194 | if (EXIFTag[i].tag == 0) |
| 1195 | break; |
| 1196 | if (LocaleCompare(EXIFTag[i].description,property) == 0) |
| 1197 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1198 | tag=(size_t) EXIFTag[i].tag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 | break; |
| 1200 | } |
| 1201 | } |
| 1202 | break; |
| 1203 | } |
| 1204 | } |
| 1205 | if (tag == (~0UL)) |
| 1206 | return(MagickFalse); |
| 1207 | length=GetStringInfoLength(profile); |
| 1208 | exif=GetStringInfoDatum(profile); |
| 1209 | while (length != 0) |
| 1210 | { |
| 1211 | if (ReadPropertyByte(&exif,&length) != 0x45) |
| 1212 | continue; |
| 1213 | if (ReadPropertyByte(&exif,&length) != 0x78) |
| 1214 | continue; |
| 1215 | if (ReadPropertyByte(&exif,&length) != 0x69) |
| 1216 | continue; |
| 1217 | if (ReadPropertyByte(&exif,&length) != 0x66) |
| 1218 | continue; |
| 1219 | if (ReadPropertyByte(&exif,&length) != 0x00) |
| 1220 | continue; |
| 1221 | if (ReadPropertyByte(&exif,&length) != 0x00) |
| 1222 | continue; |
| 1223 | break; |
| 1224 | } |
| 1225 | if (length < 16) |
| 1226 | return(MagickFalse); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1227 | id=(ssize_t) ReadPropertyShort(LSBEndian,exif); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1228 | endian=LSBEndian; |
| 1229 | if (id == 0x4949) |
| 1230 | endian=LSBEndian; |
| 1231 | else |
| 1232 | if (id == 0x4D4D) |
| 1233 | endian=MSBEndian; |
| 1234 | else |
| 1235 | return(MagickFalse); |
| 1236 | if (ReadPropertyShort(endian,exif+2) != 0x002a) |
| 1237 | return(MagickFalse); |
| 1238 | /* |
| 1239 | This the offset to the first IFD. |
| 1240 | */ |
| 1241 | offset=(ssize_t) ReadPropertyLong(endian,exif+4); |
| 1242 | if ((size_t) offset >= length) |
| 1243 | return(MagickFalse); |
| 1244 | /* |
| 1245 | Set the pointer to the first IFD and follow it were it leads. |
| 1246 | */ |
| 1247 | directory=exif+offset; |
| 1248 | level=0; |
| 1249 | entry=0; |
| 1250 | tag_offset=0; |
| 1251 | do |
| 1252 | { |
| 1253 | /* |
| 1254 | If there is anything on the stack then pop it off. |
| 1255 | */ |
| 1256 | if (level > 0) |
| 1257 | { |
| 1258 | level--; |
| 1259 | directory=directory_stack[level].directory; |
| 1260 | entry=directory_stack[level].entry; |
| 1261 | tag_offset=directory_stack[level].offset; |
| 1262 | } |
| 1263 | /* |
| 1264 | Determine how many entries there are in the current IFD. |
| 1265 | */ |
| 1266 | number_entries=ReadPropertyShort(endian,directory); |
| 1267 | for ( ; entry < number_entries; entry++) |
| 1268 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1269 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1270 | components; |
| 1271 | |
| 1272 | register unsigned char |
| 1273 | *p, |
| 1274 | *q; |
| 1275 | |
| 1276 | size_t |
| 1277 | number_bytes; |
| 1278 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1279 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1280 | format; |
| 1281 | |
| 1282 | q=(unsigned char *) (directory+2+(12*entry)); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame^] | 1283 | tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1284 | format=(size_t) ReadPropertyShort(endian,q+2); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1285 | if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes))) |
| 1286 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1287 | components=(ssize_t) ReadPropertyLong(endian,q+4); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1288 | number_bytes=(size_t) components*tag_bytes[format]; |
| 1289 | if (number_bytes <= 4) |
| 1290 | p=q+8; |
| 1291 | else |
| 1292 | { |
| 1293 | ssize_t |
| 1294 | offset; |
| 1295 | |
| 1296 | /* |
| 1297 | The directory entry contains an offset. |
| 1298 | */ |
| 1299 | offset=(ssize_t) ReadPropertyLong(endian,q+8); |
| 1300 | if ((size_t) (offset+number_bytes) > length) |
| 1301 | continue; |
| 1302 | p=(unsigned char *) (exif+offset); |
| 1303 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1304 | if ((all != 0) || (tag == (size_t) tag_value)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1305 | { |
| 1306 | char |
| 1307 | buffer[MaxTextExtent], |
| 1308 | *value; |
| 1309 | |
| 1310 | switch (format) |
| 1311 | { |
| 1312 | case EXIF_FMT_BYTE: |
| 1313 | case EXIF_FMT_UNDEFINED: |
| 1314 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1315 | EXIFMultipleValues(1,"%lu",(unsigned long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1316 | (*(unsigned char *) p1)); |
| 1317 | break; |
| 1318 | } |
| 1319 | case EXIF_FMT_SBYTE: |
| 1320 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1321 | EXIFMultipleValues(1,"%ld",(long) (*(signed char *) p1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1322 | break; |
| 1323 | } |
| 1324 | case EXIF_FMT_SSHORT: |
| 1325 | { |
| 1326 | EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1)); |
| 1327 | break; |
| 1328 | } |
| 1329 | case EXIF_FMT_USHORT: |
| 1330 | { |
| 1331 | EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1)); |
| 1332 | break; |
| 1333 | } |
| 1334 | case EXIF_FMT_ULONG: |
| 1335 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1336 | EXIFMultipleValues(4,"%lu",(long) ReadPropertyLong(endian,p1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1337 | break; |
| 1338 | } |
| 1339 | case EXIF_FMT_SLONG: |
| 1340 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1341 | EXIFMultipleValues(4,"%ld",(long) ReadPropertyLong(endian,p1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1342 | break; |
| 1343 | } |
| 1344 | case EXIF_FMT_URATIONAL: |
| 1345 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1346 | EXIFMultipleFractions(8,"%ld/%ld",(long) |
| 1347 | ReadPropertyLong(endian,p1),(long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1348 | ReadPropertyLong(endian,p1+4)); |
| 1349 | break; |
| 1350 | } |
| 1351 | case EXIF_FMT_SRATIONAL: |
| 1352 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1353 | EXIFMultipleFractions(8,"%ld/%ld",(long) |
| 1354 | ReadPropertyLong(endian,p1),(long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1355 | ReadPropertyLong(endian,p1+4)); |
| 1356 | break; |
| 1357 | } |
| 1358 | case EXIF_FMT_SINGLE: |
| 1359 | { |
| 1360 | EXIFMultipleValues(4,"%f",(double) *(float *) p1); |
| 1361 | break; |
| 1362 | } |
| 1363 | case EXIF_FMT_DOUBLE: |
| 1364 | { |
| 1365 | EXIFMultipleValues(8,"%f",*(double *) p1); |
| 1366 | break; |
| 1367 | } |
| 1368 | default: |
| 1369 | case EXIF_FMT_STRING: |
| 1370 | { |
| 1371 | value=(char *) NULL; |
| 1372 | if (~(1UL*number_bytes) >= 1) |
| 1373 | value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL, |
| 1374 | sizeof(*value)); |
| 1375 | if (value != (char *) NULL) |
| 1376 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1377 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1378 | i; |
| 1379 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1380 | for (i=0; i < (ssize_t) number_bytes; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1381 | { |
| 1382 | value[i]='.'; |
| 1383 | if ((isprint((int) p[i]) != 0) || (p[i] == '\0')) |
| 1384 | value[i]=(char) p[i]; |
| 1385 | } |
| 1386 | value[i]='\0'; |
| 1387 | } |
| 1388 | break; |
| 1389 | } |
| 1390 | } |
| 1391 | if (value != (char *) NULL) |
| 1392 | { |
| 1393 | char |
| 1394 | key[MaxTextExtent]; |
| 1395 | |
| 1396 | register const char |
| 1397 | *p; |
| 1398 | |
| 1399 | (void) CopyMagickString(key,property,MaxTextExtent); |
| 1400 | switch (all) |
| 1401 | { |
| 1402 | case 1: |
| 1403 | { |
| 1404 | const char |
| 1405 | *description; |
| 1406 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1407 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1408 | i; |
| 1409 | |
| 1410 | description="unknown"; |
| 1411 | for (i=0; ; i++) |
| 1412 | { |
| 1413 | if (EXIFTag[i].tag == 0) |
| 1414 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1415 | if ((ssize_t) EXIFTag[i].tag == tag_value) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1416 | { |
| 1417 | description=EXIFTag[i].description; |
| 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | (void) FormatMagickString(key,MaxTextExtent,"%s", |
| 1422 | description); |
| 1423 | break; |
| 1424 | } |
| 1425 | case 2: |
| 1426 | { |
| 1427 | if (tag_value < 0x10000) |
| 1428 | (void) FormatMagickString(key,MaxTextExtent,"#%04lx", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1429 | (unsigned long) tag_value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1430 | else |
| 1431 | if (tag_value < 0x20000) |
| 1432 | (void) FormatMagickString(key,MaxTextExtent,"@%04lx", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1433 | (unsigned long) (tag_value & 0xffff)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1434 | else |
| 1435 | (void) FormatMagickString(key,MaxTextExtent,"unknown"); |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
| 1439 | p=(const char *) NULL; |
| 1440 | if (image->properties != (void *) NULL) |
| 1441 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 1442 | image->properties,key); |
| 1443 | if (p == (const char *) NULL) |
| 1444 | (void) SetImageProperty((Image *) image,key,value); |
| 1445 | value=DestroyString(value); |
| 1446 | } |
| 1447 | } |
| 1448 | if ((tag_value == TAG_EXIF_OFFSET) || |
| 1449 | (tag_value == TAG_INTEROP_OFFSET) || |
| 1450 | (tag_value == TAG_GPS_OFFSET)) |
| 1451 | { |
| 1452 | size_t |
| 1453 | offset; |
| 1454 | |
| 1455 | offset=(size_t) ReadPropertyLong(endian,p); |
| 1456 | if ((offset < length) && (level < (MaxDirectoryStack-2))) |
| 1457 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1458 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1459 | tag_offset1; |
| 1460 | |
| 1461 | tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL; |
| 1462 | directory_stack[level].directory=directory; |
| 1463 | entry++; |
| 1464 | directory_stack[level].entry=entry; |
| 1465 | directory_stack[level].offset=tag_offset; |
| 1466 | level++; |
| 1467 | directory_stack[level].directory=exif+offset; |
| 1468 | directory_stack[level].offset=tag_offset1; |
| 1469 | directory_stack[level].entry=0; |
| 1470 | level++; |
| 1471 | if ((directory+2+(12*number_entries)) > (exif+length)) |
| 1472 | break; |
| 1473 | offset=(size_t) ReadPropertyLong(endian,directory+2+(12* |
| 1474 | number_entries)); |
| 1475 | if ((offset != 0) && (offset < length) && |
| 1476 | (level < (MaxDirectoryStack-2))) |
| 1477 | { |
| 1478 | directory_stack[level].directory=exif+offset; |
| 1479 | directory_stack[level].entry=0; |
| 1480 | directory_stack[level].offset=tag_offset1; |
| 1481 | level++; |
| 1482 | } |
| 1483 | } |
| 1484 | break; |
| 1485 | } |
| 1486 | } |
| 1487 | } while (level > 0); |
| 1488 | return(MagickTrue); |
| 1489 | } |
| 1490 | |
| 1491 | static MagickBooleanType GetXMPProperty(const Image *image, |
| 1492 | const char *property) |
| 1493 | { |
| 1494 | char |
| 1495 | *xmp_profile; |
| 1496 | |
| 1497 | const StringInfo |
| 1498 | *profile; |
| 1499 | |
| 1500 | ExceptionInfo |
| 1501 | *exception; |
| 1502 | |
| 1503 | MagickBooleanType |
| 1504 | status; |
| 1505 | |
| 1506 | register const char |
| 1507 | *p; |
| 1508 | |
| 1509 | XMLTreeInfo |
| 1510 | *child, |
| 1511 | *description, |
| 1512 | *node, |
| 1513 | *rdf, |
| 1514 | *xmp; |
| 1515 | |
| 1516 | profile=GetImageProfile(image,"xmp"); |
| 1517 | if (profile == (StringInfo *) NULL) |
| 1518 | return(MagickFalse); |
| 1519 | if ((property == (const char *) NULL) || (*property == '\0')) |
| 1520 | return(MagickFalse); |
| 1521 | xmp_profile=StringInfoToString(profile); |
| 1522 | if (xmp_profile == (char *) NULL) |
| 1523 | return(MagickFalse); |
| 1524 | for (p=xmp_profile; *p != '\0'; p++) |
| 1525 | if ((*p == '<') && (*(p+1) == 'x')) |
| 1526 | break; |
| 1527 | exception=AcquireExceptionInfo(); |
| 1528 | xmp=NewXMLTree((char *) p,exception); |
| 1529 | xmp_profile=DestroyString(xmp_profile); |
| 1530 | exception=DestroyExceptionInfo(exception); |
| 1531 | if (xmp == (XMLTreeInfo *) NULL) |
| 1532 | return(MagickFalse); |
| 1533 | status=MagickFalse; |
| 1534 | rdf=GetXMLTreeChild(xmp,"rdf:RDF"); |
| 1535 | if (rdf != (XMLTreeInfo *) NULL) |
| 1536 | { |
| 1537 | if (image->properties == (void *) NULL) |
| 1538 | ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString, |
| 1539 | RelinquishMagickMemory,RelinquishMagickMemory); |
| 1540 | description=GetXMLTreeChild(rdf,"rdf:Description"); |
| 1541 | while (description != (XMLTreeInfo *) NULL) |
| 1542 | { |
| 1543 | node=GetXMLTreeChild(description,(const char *) NULL); |
| 1544 | while (node != (XMLTreeInfo *) NULL) |
| 1545 | { |
| 1546 | child=GetXMLTreeChild(node,(const char *) NULL); |
| 1547 | if (child == (XMLTreeInfo *) NULL) |
| 1548 | (void) AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 1549 | ConstantString(GetXMLTreeTag(node)), |
| 1550 | ConstantString(GetXMLTreeContent(node))); |
| 1551 | while (child != (XMLTreeInfo *) NULL) |
| 1552 | { |
| 1553 | if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0) |
| 1554 | (void) AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 1555 | ConstantString(GetXMLTreeTag(child)), |
| 1556 | ConstantString(GetXMLTreeContent(child))); |
| 1557 | child=GetXMLTreeSibling(child); |
| 1558 | } |
| 1559 | node=GetXMLTreeSibling(node); |
| 1560 | } |
| 1561 | description=GetNextXMLTreeTag(description); |
| 1562 | } |
| 1563 | } |
| 1564 | xmp=DestroyXMLTree(xmp); |
| 1565 | return(status); |
| 1566 | } |
| 1567 | |
| 1568 | static char *TracePSClippath(const unsigned char *blob,size_t length, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1569 | const size_t magick_unused(columns), |
| 1570 | const size_t magick_unused(rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1571 | { |
| 1572 | char |
| 1573 | *path, |
| 1574 | *message; |
| 1575 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1576 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1577 | knot_count, |
| 1578 | selector, |
| 1579 | y; |
| 1580 | |
| 1581 | MagickBooleanType |
| 1582 | in_subpath; |
| 1583 | |
| 1584 | PointInfo |
| 1585 | first[3], |
| 1586 | last[3], |
| 1587 | point[3]; |
| 1588 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1589 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1590 | i, |
| 1591 | x; |
| 1592 | |
| 1593 | path=AcquireString((char *) NULL); |
| 1594 | if (path == (char *) NULL) |
| 1595 | return((char *) NULL); |
| 1596 | message=AcquireString((char *) NULL); |
| 1597 | (void) FormatMagickString(message,MaxTextExtent,"/ClipImage\n"); |
| 1598 | (void) ConcatenateString(&path,message); |
| 1599 | (void) FormatMagickString(message,MaxTextExtent,"{\n"); |
| 1600 | (void) ConcatenateString(&path,message); |
| 1601 | (void) FormatMagickString(message,MaxTextExtent," /c {curveto} bind def\n"); |
| 1602 | (void) ConcatenateString(&path,message); |
| 1603 | (void) FormatMagickString(message,MaxTextExtent," /l {lineto} bind def\n"); |
| 1604 | (void) ConcatenateString(&path,message); |
| 1605 | (void) FormatMagickString(message,MaxTextExtent," /m {moveto} bind def\n"); |
| 1606 | (void) ConcatenateString(&path,message); |
| 1607 | (void) FormatMagickString(message,MaxTextExtent, |
| 1608 | " /v {currentpoint 6 2 roll curveto} bind def\n"); |
| 1609 | (void) ConcatenateString(&path,message); |
| 1610 | (void) FormatMagickString(message,MaxTextExtent, |
| 1611 | " /y {2 copy curveto} bind def\n"); |
| 1612 | (void) ConcatenateString(&path,message); |
| 1613 | (void) FormatMagickString(message,MaxTextExtent, |
| 1614 | " /z {closepath} bind def\n"); |
| 1615 | (void) ConcatenateString(&path,message); |
| 1616 | (void) FormatMagickString(message,MaxTextExtent," newpath\n"); |
| 1617 | (void) ConcatenateString(&path,message); |
| 1618 | /* |
| 1619 | The clipping path format is defined in "Adobe Photoshop File |
| 1620 | Formats Specification" version 6.0 downloadable from adobe.com. |
| 1621 | */ |
| 1622 | (void) ResetMagickMemory(point,0,sizeof(point)); |
| 1623 | (void) ResetMagickMemory(first,0,sizeof(first)); |
| 1624 | (void) ResetMagickMemory(last,0,sizeof(last)); |
| 1625 | knot_count=0; |
| 1626 | in_subpath=MagickFalse; |
| 1627 | while (length > 0) |
| 1628 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1629 | selector=(ssize_t) ReadPropertyMSBShort(&blob,&length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1630 | switch (selector) |
| 1631 | { |
| 1632 | case 0: |
| 1633 | case 3: |
| 1634 | { |
| 1635 | if (knot_count != 0) |
| 1636 | { |
| 1637 | blob+=24; |
| 1638 | length-=24; |
| 1639 | break; |
| 1640 | } |
| 1641 | /* |
| 1642 | Expected subpath length record. |
| 1643 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1644 | knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1645 | blob+=22; |
| 1646 | length-=22; |
| 1647 | break; |
| 1648 | } |
| 1649 | case 1: |
| 1650 | case 2: |
| 1651 | case 4: |
| 1652 | case 5: |
| 1653 | { |
| 1654 | if (knot_count == 0) |
| 1655 | { |
| 1656 | /* |
| 1657 | Unexpected subpath knot |
| 1658 | */ |
| 1659 | blob+=24; |
| 1660 | length-=24; |
| 1661 | break; |
| 1662 | } |
| 1663 | /* |
| 1664 | Add sub-path knot |
| 1665 | */ |
| 1666 | for (i=0; i < 3; i++) |
| 1667 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1668 | size_t |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1669 | xx, |
| 1670 | yy; |
| 1671 | |
| 1672 | yy=ReadPropertyMSBLong(&blob,&length); |
| 1673 | xx=ReadPropertyMSBLong(&blob,&length); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1674 | x=(ssize_t) xx; |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1675 | if (xx > 2147483647) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1676 | x=(ssize_t) xx-4294967295-1; |
| 1677 | y=(ssize_t) yy; |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1678 | if (yy > 2147483647) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1679 | y=(ssize_t) yy-4294967295-1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1680 | point[i].x=(double) x/4096/4096; |
| 1681 | point[i].y=1.0-(double) y/4096/4096; |
| 1682 | } |
| 1683 | if (in_subpath == MagickFalse) |
| 1684 | { |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1685 | (void) FormatMagickString(message,MaxTextExtent," %g %g m\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1686 | point[1].x,point[1].y); |
| 1687 | for (i=0; i < 3; i++) |
| 1688 | { |
| 1689 | first[i]=point[i]; |
| 1690 | last[i]=point[i]; |
| 1691 | } |
| 1692 | } |
| 1693 | else |
| 1694 | { |
| 1695 | /* |
| 1696 | Handle special cases when Bezier curves are used to describe |
| 1697 | corners and straight lines. |
| 1698 | */ |
| 1699 | if ((last[1].x == last[2].x) && (last[1].y == last[2].y) && |
| 1700 | (point[0].x == point[1].x) && (point[0].y == point[1].y)) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1701 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1702 | " %g %g l\n",point[1].x,point[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1703 | else |
| 1704 | if ((last[1].x == last[2].x) && (last[1].y == last[2].y)) |
| 1705 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1706 | " %g %g %g %g v\n",point[0].x,point[0].y, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1707 | point[1].x,point[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1708 | else |
| 1709 | if ((point[0].x == point[1].x) && (point[0].y == point[1].y)) |
| 1710 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1711 | " %g %g %g %g y\n",last[2].x,last[2].y, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1712 | point[1].x,point[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1713 | else |
| 1714 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1715 | " %g %g %g %g %g %g c\n",last[2].x, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1716 | last[2].y,point[0].x,point[0].y,point[1].x,point[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1717 | for (i=0; i < 3; i++) |
| 1718 | last[i]=point[i]; |
| 1719 | } |
| 1720 | (void) ConcatenateString(&path,message); |
| 1721 | in_subpath=MagickTrue; |
| 1722 | knot_count--; |
| 1723 | /* |
| 1724 | Close the subpath if there are no more knots. |
| 1725 | */ |
| 1726 | if (knot_count == 0) |
| 1727 | { |
| 1728 | /* |
| 1729 | Same special handling as above except we compare to the |
| 1730 | first point in the path and close the path. |
| 1731 | */ |
| 1732 | if ((last[1].x == last[2].x) && (last[1].y == last[2].y) && |
| 1733 | (first[0].x == first[1].x) && (first[0].y == first[1].y)) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1734 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1735 | " %g %g l z\n",first[1].x,first[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1736 | else |
| 1737 | if ((last[1].x == last[2].x) && (last[1].y == last[2].y)) |
| 1738 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1739 | " %g %g %g %g v z\n",first[0].x,first[0].y, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1740 | first[1].x,first[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1741 | else |
| 1742 | if ((first[0].x == first[1].x) && (first[0].y == first[1].y)) |
| 1743 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1744 | " %g %g %g %g y z\n",last[2].x,last[2].y, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1745 | first[1].x,first[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1746 | else |
| 1747 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1748 | " %g %g %g %g %g %g c z\n",last[2].x, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1749 | last[2].y,first[0].x,first[0].y,first[1].x,first[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1750 | (void) ConcatenateString(&path,message); |
| 1751 | in_subpath=MagickFalse; |
| 1752 | } |
| 1753 | break; |
| 1754 | } |
| 1755 | case 6: |
| 1756 | case 7: |
| 1757 | case 8: |
| 1758 | default: |
| 1759 | { |
| 1760 | blob+=24; |
| 1761 | length-=24; |
| 1762 | break; |
| 1763 | } |
| 1764 | } |
| 1765 | } |
| 1766 | /* |
| 1767 | Returns an empty PS path if the path has no knots. |
| 1768 | */ |
| 1769 | (void) FormatMagickString(message,MaxTextExtent," eoclip\n"); |
| 1770 | (void) ConcatenateString(&path,message); |
| 1771 | (void) FormatMagickString(message,MaxTextExtent,"} bind def"); |
| 1772 | (void) ConcatenateString(&path,message); |
| 1773 | message=DestroyString(message); |
| 1774 | return(path); |
| 1775 | } |
| 1776 | |
| 1777 | static char *TraceSVGClippath(const unsigned char *blob,size_t length, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1778 | const size_t columns,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1779 | { |
| 1780 | char |
| 1781 | *path, |
| 1782 | *message; |
| 1783 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1784 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1785 | knot_count, |
| 1786 | selector, |
| 1787 | x, |
| 1788 | y; |
| 1789 | |
| 1790 | MagickBooleanType |
| 1791 | in_subpath; |
| 1792 | |
| 1793 | PointInfo |
| 1794 | first[3], |
| 1795 | last[3], |
| 1796 | point[3]; |
| 1797 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1798 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1799 | i; |
| 1800 | |
| 1801 | path=AcquireString((char *) NULL); |
| 1802 | if (path == (char *) NULL) |
| 1803 | return((char *) NULL); |
| 1804 | message=AcquireString((char *) NULL); |
| 1805 | (void) FormatMagickString(message,MaxTextExtent, |
| 1806 | "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"); |
| 1807 | (void) ConcatenateString(&path,message); |
| 1808 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1809 | "<svg width=\"%lu\" height=\"%lu\">\n",(unsigned long) columns, |
| 1810 | (unsigned long) rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1811 | (void) ConcatenateString(&path,message); |
| 1812 | (void) FormatMagickString(message,MaxTextExtent,"<g>\n"); |
| 1813 | (void) ConcatenateString(&path,message); |
| 1814 | (void) FormatMagickString(message,MaxTextExtent, |
| 1815 | "<path style=\"fill:#00000000;stroke:#00000000;"); |
| 1816 | (void) ConcatenateString(&path,message); |
| 1817 | (void) FormatMagickString(message,MaxTextExtent, |
| 1818 | "stroke-width:0;stroke-antialiasing:false\" d=\"\n"); |
| 1819 | (void) ConcatenateString(&path,message); |
| 1820 | (void) ResetMagickMemory(point,0,sizeof(point)); |
| 1821 | (void) ResetMagickMemory(first,0,sizeof(first)); |
| 1822 | (void) ResetMagickMemory(last,0,sizeof(last)); |
| 1823 | knot_count=0; |
| 1824 | in_subpath=MagickFalse; |
| 1825 | while (length != 0) |
| 1826 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1827 | selector=(ssize_t) ReadPropertyMSBShort(&blob,&length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1828 | switch (selector) |
| 1829 | { |
| 1830 | case 0: |
| 1831 | case 3: |
| 1832 | { |
| 1833 | if (knot_count != 0) |
| 1834 | { |
| 1835 | blob+=24; |
| 1836 | length-=24; |
| 1837 | break; |
| 1838 | } |
| 1839 | /* |
| 1840 | Expected subpath length record. |
| 1841 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1842 | knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1843 | blob+=22; |
| 1844 | length-=22; |
| 1845 | break; |
| 1846 | } |
| 1847 | case 1: |
| 1848 | case 2: |
| 1849 | case 4: |
| 1850 | case 5: |
| 1851 | { |
| 1852 | if (knot_count == 0) |
| 1853 | { |
| 1854 | /* |
| 1855 | Unexpected subpath knot. |
| 1856 | */ |
| 1857 | blob+=24; |
| 1858 | length-=24; |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1859 | break; |
| 1860 | } |
| 1861 | /* |
| 1862 | Add sub-path knot |
| 1863 | */ |
| 1864 | for (i=0; i < 3; i++) |
| 1865 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1866 | size_t |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1867 | xx, |
| 1868 | yy; |
| 1869 | |
| 1870 | yy=ReadPropertyMSBLong(&blob,&length); |
| 1871 | xx=ReadPropertyMSBLong(&blob,&length); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1872 | x=(ssize_t) xx; |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1873 | if (xx > 2147483647) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1874 | x=(ssize_t) xx-4294967295-1; |
| 1875 | y=(ssize_t) yy; |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1876 | if (yy > 2147483647) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1877 | y=(ssize_t) yy-4294967295-1; |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1878 | point[i].x=(double) x*columns/4096/4096; |
| 1879 | point[i].y=(double) y*rows/4096/4096; |
| 1880 | } |
| 1881 | if (in_subpath == MagickFalse) |
| 1882 | { |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1883 | (void) FormatMagickString(message,MaxTextExtent,"M %g,%g\n", |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1884 | point[1].x,point[1].y); |
| 1885 | for (i=0; i < 3; i++) |
| 1886 | { |
| 1887 | first[i]=point[i]; |
| 1888 | last[i]=point[i]; |
| 1889 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1890 | } |
| 1891 | else |
| 1892 | { |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1893 | if ((last[1].x == last[2].x) && (last[1].y == last[2].y) && |
| 1894 | (point[0].x == point[1].x) && (point[0].y == point[1].y)) |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1895 | (void) FormatMagickString(message,MaxTextExtent,"L %g,%g\n", |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1896 | point[1].x,point[1].y); |
| 1897 | else |
| 1898 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1899 | "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y, |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1900 | point[0].x,point[0].y,point[1].x,point[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1901 | for (i=0; i < 3; i++) |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1902 | last[i]=point[i]; |
| 1903 | } |
| 1904 | (void) ConcatenateString(&path,message); |
| 1905 | in_subpath=MagickTrue; |
| 1906 | knot_count--; |
| 1907 | /* |
| 1908 | Close the subpath if there are no more knots. |
| 1909 | */ |
| 1910 | if (knot_count == 0) |
| 1911 | { |
| 1912 | if ((last[1].x == last[2].x) && (last[1].y == last[2].y) && |
| 1913 | (first[0].x == first[1].x) && (first[0].y == first[1].y)) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1914 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1915 | "L %g,%g Z\n",first[1].x,first[1].y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1916 | else |
| 1917 | { |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1918 | (void) FormatMagickString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1919 | "C %g,%g %g,%g %g,%g Z\n",last[2].x, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1920 | last[2].y,first[0].x,first[0].y,first[1].x,first[1].y); |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1921 | (void) ConcatenateString(&path,message); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1922 | } |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1923 | in_subpath=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1924 | } |
cristy | 9743320 | 2009-10-27 02:05:08 +0000 | [diff] [blame] | 1925 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1926 | } |
| 1927 | case 6: |
| 1928 | case 7: |
| 1929 | case 8: |
| 1930 | default: |
| 1931 | { |
| 1932 | blob+=24; |
| 1933 | length-=24; |
| 1934 | break; |
| 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | /* |
| 1939 | Return an empty SVG image if the path does not have knots. |
| 1940 | */ |
| 1941 | (void) FormatMagickString(message,MaxTextExtent,"\"/>\n"); |
| 1942 | (void) ConcatenateString(&path,message); |
| 1943 | (void) FormatMagickString(message,MaxTextExtent,"</g>\n"); |
| 1944 | (void) ConcatenateString(&path,message); |
| 1945 | (void) FormatMagickString(message,MaxTextExtent,"</svg>\n"); |
| 1946 | (void) ConcatenateString(&path,message); |
| 1947 | message=DestroyString(message); |
| 1948 | return(path); |
| 1949 | } |
| 1950 | |
| 1951 | MagickExport const char *GetImageProperty(const Image *image, |
| 1952 | const char *property) |
| 1953 | { |
| 1954 | ExceptionInfo |
| 1955 | *exception; |
| 1956 | |
| 1957 | FxInfo |
| 1958 | *fx_info; |
| 1959 | |
| 1960 | MagickRealType |
| 1961 | alpha; |
| 1962 | |
| 1963 | MagickStatusType |
| 1964 | status; |
| 1965 | |
| 1966 | register const char |
| 1967 | *p; |
| 1968 | |
| 1969 | assert(image != (Image *) NULL); |
| 1970 | assert(image->signature == MagickSignature); |
| 1971 | if (image->debug != MagickFalse) |
| 1972 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1973 | p=(const char *) NULL; |
| 1974 | if (property == (const char *) NULL) |
| 1975 | { |
| 1976 | ResetSplayTreeIterator((SplayTreeInfo *) image->properties); |
| 1977 | p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *) |
| 1978 | image->properties); |
| 1979 | return(p); |
| 1980 | } |
| 1981 | if ((image->properties != (void *) NULL) && |
| 1982 | (LocaleNCompare("fx:",property,3) != 0)) |
| 1983 | { |
| 1984 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 1985 | image->properties,property); |
| 1986 | if (p != (const char *) NULL) |
| 1987 | return(p); |
| 1988 | } |
| 1989 | if (strchr(property,':') == (char *) NULL) |
| 1990 | return(p); |
| 1991 | exception=(&((Image *) image)->exception); |
| 1992 | switch (*property) |
| 1993 | { |
| 1994 | case '8': |
| 1995 | { |
| 1996 | if (LocaleNCompare("8bim:",property,5) == 0) |
| 1997 | { |
| 1998 | if (Get8BIMProperty(image,property) != MagickFalse) |
| 1999 | { |
| 2000 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 2001 | image->properties,property); |
| 2002 | return(p); |
| 2003 | } |
| 2004 | } |
| 2005 | break; |
| 2006 | } |
| 2007 | case 'E': |
| 2008 | case 'e': |
| 2009 | { |
| 2010 | if (LocaleNCompare("exif:",property,5) == 0) |
| 2011 | { |
| 2012 | if (GetEXIFProperty(image,property) != MagickFalse) |
| 2013 | { |
| 2014 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 2015 | image->properties,property); |
| 2016 | return(p); |
| 2017 | } |
| 2018 | } |
| 2019 | break; |
| 2020 | } |
| 2021 | case 'F': |
| 2022 | case 'f': |
| 2023 | { |
| 2024 | if (LocaleNCompare("fx:",property,3) == 0) |
| 2025 | { |
| 2026 | fx_info=AcquireFxInfo(image,property+3); |
| 2027 | status=FxEvaluateExpression(fx_info,&alpha,exception); |
| 2028 | fx_info=DestroyFxInfo(fx_info); |
| 2029 | if (status != MagickFalse) |
| 2030 | { |
| 2031 | char |
| 2032 | value[MaxTextExtent]; |
| 2033 | |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2034 | (void) FormatMagickString(value,MaxTextExtent,"%g",(double) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2035 | alpha); |
| 2036 | (void) SetImageProperty((Image *) image,property,value); |
| 2037 | } |
| 2038 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 2039 | image->properties,property); |
| 2040 | return(p); |
| 2041 | } |
| 2042 | break; |
| 2043 | } |
| 2044 | case 'I': |
| 2045 | case 'i': |
| 2046 | { |
| 2047 | if (LocaleNCompare("iptc:",property,5) == 0) |
| 2048 | { |
| 2049 | if (GetIPTCProperty(image,property) != MagickFalse) |
| 2050 | { |
| 2051 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 2052 | image->properties,property); |
| 2053 | return(p); |
| 2054 | } |
| 2055 | } |
| 2056 | break; |
| 2057 | } |
| 2058 | case 'P': |
| 2059 | case 'p': |
| 2060 | { |
| 2061 | if (LocaleNCompare("pixel:",property,6) == 0) |
| 2062 | { |
| 2063 | MagickPixelPacket |
| 2064 | pixel; |
| 2065 | |
| 2066 | GetMagickPixelPacket(image,&pixel); |
| 2067 | fx_info=AcquireFxInfo(image,property+6); |
| 2068 | status=FxEvaluateChannelExpression(fx_info,RedChannel,0,0,&alpha, |
| 2069 | exception); |
| 2070 | pixel.red=(MagickRealType) QuantumRange*alpha; |
| 2071 | status|=FxEvaluateChannelExpression(fx_info,GreenChannel,0,0,&alpha, |
| 2072 | exception); |
| 2073 | pixel.green=(MagickRealType) QuantumRange*alpha; |
| 2074 | status|=FxEvaluateChannelExpression(fx_info,BlueChannel,0,0,&alpha, |
| 2075 | exception); |
| 2076 | pixel.blue=(MagickRealType) QuantumRange*alpha; |
| 2077 | status|=FxEvaluateChannelExpression(fx_info,OpacityChannel,0,0,&alpha, |
| 2078 | exception); |
| 2079 | pixel.opacity=(MagickRealType) QuantumRange*(1.0-alpha); |
| 2080 | if (image->colorspace == CMYKColorspace) |
| 2081 | { |
| 2082 | status|=FxEvaluateChannelExpression(fx_info,BlackChannel,0,0, |
| 2083 | &alpha,exception); |
| 2084 | pixel.index=(MagickRealType) QuantumRange*alpha; |
| 2085 | } |
| 2086 | fx_info=DestroyFxInfo(fx_info); |
| 2087 | if (status != MagickFalse) |
| 2088 | { |
| 2089 | char |
| 2090 | name[MaxTextExtent]; |
| 2091 | |
| 2092 | (void) QueryMagickColorname(image,&pixel,SVGCompliance,name, |
| 2093 | exception); |
| 2094 | (void) SetImageProperty((Image *) image,property,name); |
| 2095 | return(GetImageProperty(image,property)); |
| 2096 | } |
| 2097 | } |
| 2098 | break; |
| 2099 | } |
| 2100 | case 'X': |
| 2101 | case 'x': |
| 2102 | { |
| 2103 | if (LocaleNCompare("xmp:",property,4) == 0) |
| 2104 | { |
| 2105 | if (GetXMPProperty(image,property) != MagickFalse) |
| 2106 | { |
| 2107 | p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) |
| 2108 | image->properties,property); |
| 2109 | return(p); |
| 2110 | } |
| 2111 | } |
| 2112 | break; |
| 2113 | } |
| 2114 | } |
| 2115 | return(p); |
| 2116 | } |
| 2117 | |
| 2118 | /* |
| 2119 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2120 | % % |
| 2121 | % % |
| 2122 | % % |
| 2123 | + G e t M a g i c k P r o p e r t y % |
| 2124 | % % |
| 2125 | % % |
| 2126 | % % |
| 2127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2128 | % |
| 2129 | % GetMagickProperty() gets a value associated with an image property. |
| 2130 | % |
| 2131 | % The format of the GetMagickProperty method is: |
| 2132 | % |
| 2133 | % const char *GetMagickProperty(const ImageInfo *image_info, |
| 2134 | % Image *image,const char *key) |
| 2135 | % |
| 2136 | % A description of each parameter follows: |
| 2137 | % |
| 2138 | % o image_info: the image info. |
| 2139 | % |
| 2140 | % o image: the image. |
| 2141 | % |
| 2142 | % o key: the key. |
| 2143 | % |
| 2144 | */ |
| 2145 | MagickExport const char *GetMagickProperty(const ImageInfo *image_info, |
| 2146 | Image *image,const char *property) |
| 2147 | { |
| 2148 | char |
| 2149 | value[MaxTextExtent], |
| 2150 | filename[MaxTextExtent]; |
| 2151 | |
| 2152 | *value='\0'; |
cristy | ec6897c | 2010-05-12 00:43:15 +0000 | [diff] [blame] | 2153 | switch (*property) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2154 | { |
| 2155 | case 'b': |
| 2156 | { |
| 2157 | if (LocaleNCompare("base",property,4) == 0) |
| 2158 | { |
| 2159 | GetPathComponent(image->magick_filename,BasePath,filename); |
| 2160 | (void) CopyMagickString(value,filename,MaxTextExtent); |
| 2161 | break; |
| 2162 | } |
| 2163 | break; |
| 2164 | } |
| 2165 | case 'c': |
| 2166 | { |
| 2167 | if (LocaleNCompare("channels",property,8) == 0) |
| 2168 | { |
| 2169 | /* |
| 2170 | Image channels. |
| 2171 | */ |
| 2172 | (void) FormatMagickString(value,MaxTextExtent,"%s", |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2173 | MagickOptionToMnemonic(MagickColorspaceOptions,(ssize_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2174 | image->colorspace)); |
| 2175 | LocaleLower(value); |
| 2176 | if (image->matte != MagickFalse) |
| 2177 | (void) ConcatenateMagickString(value,"a",MaxTextExtent); |
| 2178 | break; |
| 2179 | } |
| 2180 | if (LocaleNCompare("colorspace",property,10) == 0) |
| 2181 | { |
| 2182 | ColorspaceType |
| 2183 | colorspace; |
| 2184 | |
| 2185 | /* |
| 2186 | Image storage class and colorspace. |
| 2187 | */ |
| 2188 | colorspace=image->colorspace; |
| 2189 | if (IsGrayImage(image,&image->exception) != MagickFalse) |
| 2190 | colorspace=GRAYColorspace; |
| 2191 | (void) FormatMagickString(value,MaxTextExtent,"%s", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2192 | MagickOptionToMnemonic(MagickColorspaceOptions,(ssize_t) |
| 2193 | colorspace)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | } |
| 2196 | break; |
| 2197 | } |
| 2198 | case 'd': |
| 2199 | { |
| 2200 | if (LocaleNCompare("depth",property,5) == 0) |
| 2201 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2202 | (void) FormatMagickString(value,MaxTextExtent,"%lu",(unsigned long) |
| 2203 | image->depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2204 | break; |
| 2205 | } |
| 2206 | if (LocaleNCompare("directory",property,9) == 0) |
| 2207 | { |
| 2208 | GetPathComponent(image->magick_filename,HeadPath,filename); |
| 2209 | (void) CopyMagickString(value,filename,MaxTextExtent); |
| 2210 | break; |
| 2211 | } |
| 2212 | break; |
| 2213 | } |
| 2214 | case 'e': |
| 2215 | { |
| 2216 | if (LocaleNCompare("extension",property,9) == 0) |
| 2217 | { |
| 2218 | GetPathComponent(image->magick_filename,ExtensionPath,filename); |
| 2219 | (void) CopyMagickString(value,filename,MaxTextExtent); |
| 2220 | break; |
| 2221 | } |
| 2222 | break; |
| 2223 | } |
| 2224 | case 'g': |
| 2225 | { |
| 2226 | if (LocaleNCompare("group",property,5) == 0) |
| 2227 | { |
| 2228 | (void) FormatMagickString(value,MaxTextExtent,"0x%lx", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2229 | (unsigned long) image_info->group); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | } |
| 2232 | break; |
| 2233 | } |
| 2234 | case 'h': |
| 2235 | { |
| 2236 | if (LocaleNCompare("height",property,6) == 0) |
| 2237 | { |
| 2238 | (void) FormatMagickString(value,MaxTextExtent,"%lu", |
| 2239 | image->magick_rows != 0 ? image->magick_rows : 256UL); |
| 2240 | break; |
| 2241 | } |
| 2242 | break; |
| 2243 | } |
| 2244 | case 'i': |
| 2245 | { |
| 2246 | if (LocaleNCompare("input",property,5) == 0) |
| 2247 | { |
| 2248 | (void) CopyMagickString(value,image->filename,MaxTextExtent); |
| 2249 | break; |
| 2250 | } |
| 2251 | break; |
| 2252 | } |
| 2253 | case 'k': |
| 2254 | { |
| 2255 | if (LocaleNCompare("kurtosis",property,8) == 0) |
| 2256 | { |
| 2257 | double |
| 2258 | kurtosis, |
| 2259 | skewness; |
| 2260 | |
| 2261 | (void) GetImageChannelKurtosis(image,image_info->channel,&kurtosis, |
| 2262 | &skewness,&image->exception); |
cristy | 0596f85 | 2010-01-17 20:21:09 +0000 | [diff] [blame] | 2263 | (void) FormatMagickString(value,MaxTextExtent,"%.*g", |
| 2264 | GetMagickPrecision(),kurtosis); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2265 | break; |
| 2266 | } |
| 2267 | break; |
| 2268 | } |
| 2269 | case 'm': |
| 2270 | { |
| 2271 | if (LocaleNCompare("magick",property,6) == 0) |
| 2272 | { |
| 2273 | (void) CopyMagickString(value,image->magick,MaxTextExtent); |
| 2274 | break; |
| 2275 | } |
| 2276 | if (LocaleNCompare("max",property,3) == 0) |
| 2277 | { |
| 2278 | double |
| 2279 | maximum, |
| 2280 | minimum; |
| 2281 | |
| 2282 | (void) GetImageChannelRange(image,image_info->channel,&minimum, |
| 2283 | &maximum,&image->exception); |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2284 | (void) FormatMagickString(value,MaxTextExtent,"%g",maximum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2285 | break; |
| 2286 | } |
| 2287 | if (LocaleNCompare("mean",property,4) == 0) |
| 2288 | { |
| 2289 | double |
| 2290 | mean, |
| 2291 | standard_deviation; |
| 2292 | |
| 2293 | (void) GetImageChannelMean(image,image_info->channel,&mean, |
| 2294 | &standard_deviation,&image->exception); |
cristy | 0596f85 | 2010-01-17 20:21:09 +0000 | [diff] [blame] | 2295 | (void) FormatMagickString(value,MaxTextExtent,"%.*g", |
| 2296 | GetMagickPrecision(),mean); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | } |
| 2299 | if (LocaleNCompare("min",property,3) == 0) |
| 2300 | { |
| 2301 | double |
| 2302 | maximum, |
| 2303 | minimum; |
| 2304 | |
| 2305 | (void) GetImageChannelRange(image,image_info->channel,&minimum, |
| 2306 | &maximum,&image->exception); |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2307 | (void) FormatMagickString(value,MaxTextExtent,"%g",minimum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2308 | break; |
| 2309 | } |
| 2310 | break; |
| 2311 | } |
| 2312 | case 'n': |
| 2313 | { |
| 2314 | if (LocaleNCompare("name",property,4) == 0) |
| 2315 | { |
| 2316 | (void) CopyMagickString(value,filename,MaxTextExtent); |
| 2317 | break; |
| 2318 | } |
| 2319 | break; |
| 2320 | } |
| 2321 | case 'o': |
| 2322 | { |
| 2323 | if (LocaleNCompare("output",property,6) == 0) |
| 2324 | { |
| 2325 | (void) CopyMagickString(value,image_info->filename,MaxTextExtent); |
| 2326 | break; |
| 2327 | } |
| 2328 | break; |
| 2329 | } |
| 2330 | case 'p': |
| 2331 | { |
| 2332 | if (LocaleNCompare("page",property,4) == 0) |
| 2333 | { |
| 2334 | register const Image |
| 2335 | *p; |
| 2336 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2337 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2338 | page; |
| 2339 | |
| 2340 | p=image; |
| 2341 | for (page=1; GetPreviousImageInList(p) != (Image *) NULL; page++) |
| 2342 | p=GetPreviousImageInList(p); |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2343 | (void) FormatMagickString(value,MaxTextExtent,"%lu",(unsigned long) |
| 2344 | page); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | } |
| 2347 | break; |
| 2348 | } |
| 2349 | case 's': |
| 2350 | { |
| 2351 | if (LocaleNCompare("size",property,4) == 0) |
| 2352 | { |
| 2353 | char |
| 2354 | format[MaxTextExtent]; |
| 2355 | |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 2356 | (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format); |
cristy | 2ce15c9 | 2010-03-12 14:03:41 +0000 | [diff] [blame] | 2357 | (void) FormatMagickString(value,MaxTextExtent,"%sB",format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | } |
| 2360 | if (LocaleNCompare("scenes",property,6) == 0) |
| 2361 | { |
| 2362 | (void) FormatMagickString(value,MaxTextExtent,"%lu", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2363 | (unsigned long) GetImageListLength(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2364 | break; |
| 2365 | } |
| 2366 | if (LocaleNCompare("scene",property,5) == 0) |
| 2367 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2368 | (void) FormatMagickString(value,MaxTextExtent,"%lu",(unsigned long) |
| 2369 | image->scene); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2370 | if (image_info->number_scenes != 0) |
| 2371 | (void) FormatMagickString(value,MaxTextExtent,"%lu", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2372 | (unsigned long) image_info->scene); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | } |
| 2375 | if (LocaleNCompare("skewness",property,8) == 0) |
| 2376 | { |
| 2377 | double |
| 2378 | kurtosis, |
| 2379 | skewness; |
| 2380 | |
| 2381 | (void) GetImageChannelKurtosis(image,image_info->channel,&kurtosis, |
| 2382 | &skewness,&image->exception); |
cristy | 0596f85 | 2010-01-17 20:21:09 +0000 | [diff] [blame] | 2383 | (void) FormatMagickString(value,MaxTextExtent,"%.*g", |
| 2384 | GetMagickPrecision(),skewness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | } |
| 2387 | if ((LocaleNCompare("standard-deviation",property,18) == 0) || |
| 2388 | (LocaleNCompare("standard_deviation",property,18) == 0)) |
| 2389 | { |
| 2390 | double |
| 2391 | mean, |
| 2392 | standard_deviation; |
| 2393 | |
| 2394 | (void) GetImageChannelMean(image,image_info->channel,&mean, |
| 2395 | &standard_deviation,&image->exception); |
cristy | 0596f85 | 2010-01-17 20:21:09 +0000 | [diff] [blame] | 2396 | (void) FormatMagickString(value,MaxTextExtent,"%.*g", |
| 2397 | GetMagickPrecision(),standard_deviation); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2398 | break; |
| 2399 | } |
| 2400 | break; |
| 2401 | } |
| 2402 | case 'u': |
| 2403 | { |
| 2404 | if (LocaleNCompare("unique",property,6) == 0) |
| 2405 | { |
| 2406 | (void) CopyMagickString(filename,image_info->unique,MaxTextExtent); |
| 2407 | (void) CopyMagickString(value,filename,MaxTextExtent); |
| 2408 | break; |
| 2409 | } |
| 2410 | break; |
| 2411 | } |
| 2412 | case 'w': |
| 2413 | { |
| 2414 | if (LocaleNCompare("width",property,5) == 0) |
| 2415 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2416 | (void) FormatMagickString(value,MaxTextExtent,"%lu",(unsigned long) |
| 2417 | (image->magick_columns != 0 ? image->magick_columns : 256)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2418 | break; |
| 2419 | } |
| 2420 | break; |
| 2421 | } |
| 2422 | case 'x': |
| 2423 | { |
| 2424 | if (LocaleNCompare("xresolution",property,11) == 0) |
| 2425 | { |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2426 | (void) FormatMagickString(value,MaxTextExtent,"%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2427 | image->x_resolution); |
| 2428 | break; |
| 2429 | } |
| 2430 | break; |
| 2431 | } |
| 2432 | case 'y': |
| 2433 | { |
| 2434 | if (LocaleNCompare("yresolution",property,11) == 0) |
| 2435 | { |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2436 | (void) FormatMagickString(value,MaxTextExtent,"%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2437 | image->y_resolution); |
| 2438 | break; |
| 2439 | } |
| 2440 | break; |
| 2441 | } |
| 2442 | case 'z': |
| 2443 | { |
| 2444 | if (LocaleNCompare("zero",property,4) == 0) |
| 2445 | { |
| 2446 | (void) CopyMagickString(filename,image_info->zero,MaxTextExtent); |
| 2447 | (void) CopyMagickString(value,filename,MaxTextExtent); |
| 2448 | break; |
| 2449 | } |
| 2450 | break; |
| 2451 | } |
| 2452 | } |
| 2453 | if (*value != '\0') |
| 2454 | { |
| 2455 | if (image->properties == (void *) NULL) |
| 2456 | image->properties=NewSplayTree(CompareSplayTreeString, |
| 2457 | RelinquishMagickMemory,RelinquishMagickMemory); |
| 2458 | (void) AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 2459 | ConstantString(property),ConstantString(value)); |
| 2460 | } |
| 2461 | return(GetImageProperty(image,property)); |
| 2462 | } |
| 2463 | |
| 2464 | /* |
| 2465 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2466 | % % |
| 2467 | % % |
| 2468 | % % |
| 2469 | % G e t N e x t I m a g e P r o p e r t y % |
| 2470 | % % |
| 2471 | % % |
| 2472 | % % |
| 2473 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2474 | % |
| 2475 | % GetNextImageProperty() gets the next image property value. |
| 2476 | % |
| 2477 | % The format of the GetNextImageProperty method is: |
| 2478 | % |
| 2479 | % char *GetNextImageProperty(const Image *image) |
| 2480 | % |
| 2481 | % A description of each parameter follows: |
| 2482 | % |
| 2483 | % o image: the image. |
| 2484 | % |
| 2485 | */ |
| 2486 | MagickExport char *GetNextImageProperty(const Image *image) |
| 2487 | { |
| 2488 | assert(image != (Image *) NULL); |
| 2489 | assert(image->signature == MagickSignature); |
| 2490 | if (image->debug != MagickFalse) |
| 2491 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2492 | image->filename); |
| 2493 | if (image->properties == (void *) NULL) |
| 2494 | return((char *) NULL); |
| 2495 | return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties)); |
| 2496 | } |
| 2497 | |
| 2498 | /* |
| 2499 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2500 | % % |
| 2501 | % % |
| 2502 | % % |
| 2503 | % I n t e r p r e t I m a g e P r o p e r t i e s % |
| 2504 | % % |
| 2505 | % % |
| 2506 | % % |
| 2507 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2508 | % |
| 2509 | % InterpretImageProperties() replaces any embedded formatting characters with |
| 2510 | % the appropriate image property and returns the interpretted text. |
| 2511 | % |
| 2512 | % The format of the InterpretImageProperties method is: |
| 2513 | % |
| 2514 | % char *InterpretImageProperties(const ImageInfo *image_info,Image *image, |
| 2515 | % const char *embed_text) |
| 2516 | % |
| 2517 | % A description of each parameter follows: |
| 2518 | % |
| 2519 | % o image_info: the image info. |
| 2520 | % |
| 2521 | % o image: the image. |
| 2522 | % |
| 2523 | % o embed_text: the address of a character string containing the embedded |
| 2524 | % formatting characters. |
| 2525 | % |
| 2526 | */ |
| 2527 | MagickExport char *InterpretImageProperties(const ImageInfo *image_info, |
| 2528 | Image *image,const char *embed_text) |
| 2529 | { |
| 2530 | char |
| 2531 | filename[MaxTextExtent], |
| 2532 | *interpret_text, |
| 2533 | *text; |
| 2534 | |
| 2535 | const char |
| 2536 | *value; |
| 2537 | |
| 2538 | ImageInfo |
| 2539 | *text_info; |
| 2540 | |
| 2541 | register char |
| 2542 | *q; |
| 2543 | |
| 2544 | register const char |
| 2545 | *p; |
| 2546 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2547 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2548 | i; |
| 2549 | |
| 2550 | size_t |
| 2551 | extent, |
| 2552 | length; |
| 2553 | |
| 2554 | assert(image != (Image *) NULL); |
| 2555 | assert(image->signature == MagickSignature); |
| 2556 | if (image->debug != MagickFalse) |
| 2557 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 2558 | if ((embed_text == (const char *) NULL) || (*embed_text == '\0')) |
| 2559 | return((char *) NULL); |
| 2560 | text=(char *) embed_text; |
| 2561 | if ((*text == '@') && ((*(text+1) == '-') || |
| 2562 | (IsPathAccessible(text+1) != MagickFalse))) |
| 2563 | return(FileToString(embed_text+1,~0,&image->exception)); |
| 2564 | /* |
| 2565 | Translate any embedded format characters. |
| 2566 | */ |
| 2567 | text_info=CloneImageInfo(image_info); |
| 2568 | interpret_text=AcquireString(text); |
| 2569 | extent=MaxTextExtent; |
| 2570 | p=text; |
| 2571 | for (q=interpret_text; *p != '\0'; p++) |
| 2572 | { |
| 2573 | *q='\0'; |
| 2574 | if ((size_t) (q-interpret_text+MaxTextExtent) >= extent) |
| 2575 | { |
| 2576 | extent+=MaxTextExtent; |
| 2577 | interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ |
| 2578 | MaxTextExtent+1,sizeof(*interpret_text)); |
| 2579 | if (interpret_text == (char *) NULL) |
| 2580 | break; |
| 2581 | q=interpret_text+strlen(interpret_text); |
| 2582 | } |
| 2583 | /* |
| 2584 | Process formatting characters in text. |
| 2585 | */ |
| 2586 | if ((*p == '\\') && (*(p+1) == 'r')) |
| 2587 | { |
| 2588 | *q++='\r'; |
| 2589 | p++; |
| 2590 | continue; |
| 2591 | } |
| 2592 | if ((*p == '\\') && (*(p+1) == 'n')) |
| 2593 | { |
| 2594 | *q++='\n'; |
| 2595 | p++; |
| 2596 | continue; |
| 2597 | } |
| 2598 | if (*p == '\\') |
| 2599 | { |
| 2600 | p++; |
| 2601 | *q++=(*p); |
| 2602 | continue; |
| 2603 | } |
| 2604 | if (*p != '%') |
| 2605 | { |
| 2606 | *q++=(*p); |
| 2607 | continue; |
| 2608 | } |
| 2609 | p++; |
| 2610 | switch (*p) |
| 2611 | { |
| 2612 | case 'b': |
| 2613 | { |
| 2614 | char |
| 2615 | format[MaxTextExtent]; |
| 2616 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2617 | /* |
| 2618 | File size. |
| 2619 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2620 | (void) FormatMagickString(format,MaxTextExtent,"%lu",(unsigned long) |
cristy | 81b8ce5 | 2010-02-05 01:53:17 +0000 | [diff] [blame] | 2621 | image->extent); |
| 2622 | if (image->extent != (MagickSizeType) ((size_t) image->extent)) |
| 2623 | (void) FormatMagickSize(image->extent,MagickFalse,format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2624 | q+=ConcatenateMagickString(q,format,extent); |
cristy | 2ce15c9 | 2010-03-12 14:03:41 +0000 | [diff] [blame] | 2625 | q+=ConcatenateMagickString(q,"B",extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | } |
| 2628 | case 'c': |
| 2629 | { |
| 2630 | /* |
| 2631 | Image comment. |
| 2632 | */ |
| 2633 | value=GetImageProperty(image,"comment"); |
| 2634 | if (value == (const char *) NULL) |
| 2635 | break; |
| 2636 | length=strlen(value); |
| 2637 | if ((size_t) (q-interpret_text+length+1) >= extent) |
| 2638 | { |
| 2639 | extent+=length; |
| 2640 | interpret_text=(char *) ResizeQuantumMemory(interpret_text, |
| 2641 | extent+MaxTextExtent,sizeof(*interpret_text)); |
| 2642 | if (interpret_text == (char *) NULL) |
| 2643 | break; |
| 2644 | q=interpret_text+strlen(interpret_text); |
| 2645 | } |
| 2646 | (void) CopyMagickString(q,value,extent); |
| 2647 | q+=length; |
| 2648 | break; |
| 2649 | } |
| 2650 | case 'd': |
| 2651 | case 'e': |
| 2652 | case 'f': |
| 2653 | case 't': |
| 2654 | { |
| 2655 | /* |
| 2656 | Label segment is the base of the filename. |
| 2657 | */ |
| 2658 | if (*image->magick_filename == '\0') |
| 2659 | break; |
| 2660 | switch (*p) |
| 2661 | { |
| 2662 | case 'd': |
| 2663 | { |
| 2664 | /* |
| 2665 | Directory. |
| 2666 | */ |
| 2667 | GetPathComponent(image->magick_filename,HeadPath,filename); |
| 2668 | q+=CopyMagickString(q,filename,extent); |
| 2669 | break; |
| 2670 | } |
| 2671 | case 'e': |
| 2672 | { |
| 2673 | /* |
| 2674 | Filename extension. |
| 2675 | */ |
| 2676 | GetPathComponent(image->magick_filename,ExtensionPath,filename); |
| 2677 | q+=CopyMagickString(q,filename,extent); |
| 2678 | break; |
| 2679 | } |
| 2680 | case 'f': |
| 2681 | { |
| 2682 | /* |
| 2683 | Filename. |
| 2684 | */ |
| 2685 | GetPathComponent(image->magick_filename,TailPath,filename); |
| 2686 | q+=CopyMagickString(q,filename,extent); |
| 2687 | break; |
| 2688 | } |
| 2689 | case 't': |
| 2690 | { |
| 2691 | /* |
| 2692 | Base filename. |
| 2693 | */ |
| 2694 | GetPathComponent(image->magick_filename,BasePath,filename); |
| 2695 | q+=CopyMagickString(q,filename,extent); |
| 2696 | break; |
| 2697 | } |
| 2698 | } |
| 2699 | break; |
| 2700 | } |
| 2701 | case 'g': |
| 2702 | { |
| 2703 | /* |
| 2704 | Image geometry. |
| 2705 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2706 | q+=FormatMagickString(q,extent,"%lux%lu%+ld%+ld",(unsigned long) |
| 2707 | image->page.width,(unsigned long) image->page.height,(long) |
| 2708 | image->page.x,(long) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2709 | break; |
| 2710 | } |
| 2711 | case 'h': |
| 2712 | { |
| 2713 | /* |
| 2714 | Image height. |
| 2715 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2716 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
| 2717 | (image->rows != 0 ? image->rows : image->magick_rows)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2718 | break; |
| 2719 | } |
| 2720 | case 'i': |
| 2721 | { |
| 2722 | /* |
| 2723 | Image filename. |
| 2724 | */ |
| 2725 | q+=CopyMagickString(q,image->filename,extent); |
| 2726 | break; |
| 2727 | } |
| 2728 | case 'k': |
| 2729 | { |
| 2730 | /* |
| 2731 | Number of unique colors. |
| 2732 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2733 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
| 2734 | GetNumberColors(image,(FILE *) NULL,&image->exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2735 | break; |
| 2736 | } |
| 2737 | case 'l': |
| 2738 | { |
| 2739 | /* |
| 2740 | Image label. |
| 2741 | */ |
| 2742 | value=GetImageProperty(image,"label"); |
| 2743 | if (value == (const char *) NULL) |
| 2744 | break; |
| 2745 | length=strlen(value); |
| 2746 | if ((size_t) (q-interpret_text+length+1) >= extent) |
| 2747 | { |
| 2748 | extent+=length; |
| 2749 | interpret_text=(char *) ResizeQuantumMemory(interpret_text, |
| 2750 | extent+MaxTextExtent,sizeof(*interpret_text)); |
| 2751 | if (interpret_text == (char *) NULL) |
| 2752 | break; |
| 2753 | q=interpret_text+strlen(interpret_text); |
| 2754 | } |
| 2755 | q+=CopyMagickString(q,value,extent); |
| 2756 | break; |
| 2757 | } |
| 2758 | case 'm': |
| 2759 | { |
| 2760 | /* |
| 2761 | Image format. |
| 2762 | */ |
| 2763 | q+=CopyMagickString(q,image->magick,extent); |
| 2764 | break; |
| 2765 | } |
| 2766 | case 'M': |
| 2767 | { |
| 2768 | /* |
| 2769 | Image magick filename. |
| 2770 | */ |
| 2771 | q+=CopyMagickString(q,image->magick_filename,extent); |
| 2772 | break; |
| 2773 | } |
| 2774 | case 'n': |
| 2775 | { |
| 2776 | /* |
| 2777 | Number of images in the list. |
| 2778 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2779 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2780 | GetImageListLength(image)); |
| 2781 | break; |
| 2782 | } |
| 2783 | case 'o': |
| 2784 | { |
| 2785 | /* |
| 2786 | Image output filename. |
| 2787 | */ |
| 2788 | q+=CopyMagickString(q,text_info->filename,extent); |
| 2789 | break; |
| 2790 | } |
| 2791 | case 'p': |
| 2792 | { |
| 2793 | register const Image |
| 2794 | *p; |
| 2795 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2796 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2797 | page; |
| 2798 | |
| 2799 | /* |
| 2800 | Image page number. |
| 2801 | */ |
| 2802 | p=image; |
| 2803 | for (page=1; GetPreviousImageInList(p) != (Image *) NULL; page++) |
| 2804 | p=GetPreviousImageInList(p); |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2805 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) page); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2806 | break; |
| 2807 | } |
| 2808 | case 'q': |
| 2809 | { |
| 2810 | /* |
| 2811 | Image depth. |
| 2812 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2813 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) image->depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | } |
| 2816 | case 'r': |
| 2817 | { |
| 2818 | ColorspaceType |
| 2819 | colorspace; |
| 2820 | |
| 2821 | /* |
| 2822 | Image storage class and colorspace. |
| 2823 | */ |
| 2824 | colorspace=image->colorspace; |
| 2825 | if (IsGrayImage(image,&image->exception) != MagickFalse) |
| 2826 | colorspace=GRAYColorspace; |
| 2827 | q+=FormatMagickString(q,extent,"%s%s%s",MagickOptionToMnemonic( |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2828 | MagickClassOptions,(ssize_t) image->storage_class), |
| 2829 | MagickOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2830 | image->matte != MagickFalse ? "Matte" : ""); |
| 2831 | break; |
| 2832 | } |
| 2833 | case 's': |
| 2834 | { |
| 2835 | /* |
| 2836 | Image scene number. |
| 2837 | */ |
| 2838 | if (text_info->number_scenes == 0) |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2839 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) image->scene); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2840 | else |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2841 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
| 2842 | text_info->scene); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | } |
| 2845 | case 'u': |
| 2846 | { |
| 2847 | /* |
| 2848 | Unique filename. |
| 2849 | */ |
| 2850 | (void) CopyMagickString(filename,text_info->unique,extent); |
| 2851 | q+=CopyMagickString(q,filename,extent); |
| 2852 | break; |
| 2853 | } |
| 2854 | case 'w': |
| 2855 | { |
| 2856 | /* |
| 2857 | Image width. |
| 2858 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2859 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
| 2860 | (image->columns != 0 ? image->columns : image->magick_columns)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | } |
| 2863 | case 'x': |
| 2864 | { |
| 2865 | /* |
| 2866 | Image horizontal resolution. |
| 2867 | */ |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2868 | q+=FormatMagickString(q,extent,"%g %s",image->x_resolution, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2869 | MagickOptionToMnemonic(MagickResolutionOptions,(ssize_t) |
| 2870 | image->units)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | } |
| 2873 | case 'y': |
| 2874 | { |
| 2875 | /* |
| 2876 | Image vertical resolution. |
| 2877 | */ |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2878 | q+=FormatMagickString(q,extent,"%g %s",image->y_resolution, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2879 | MagickOptionToMnemonic(MagickResolutionOptions,(ssize_t) |
| 2880 | image->units)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2881 | break; |
| 2882 | } |
| 2883 | case 'z': |
| 2884 | { |
| 2885 | /* |
| 2886 | Image depth. |
| 2887 | */ |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2888 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) image->depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | } |
| 2891 | case 'A': |
| 2892 | { |
| 2893 | /* |
| 2894 | Image alpha channel. |
| 2895 | */ |
| 2896 | q+=FormatMagickString(q,extent,"%s",MagickOptionToMnemonic( |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2897 | MagickBooleanOptions,(ssize_t) image->matte)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2898 | break; |
| 2899 | } |
| 2900 | case 'C': |
| 2901 | { |
| 2902 | /* |
| 2903 | Image compression method. |
| 2904 | */ |
| 2905 | q+=FormatMagickString(q,extent,"%s",MagickOptionToMnemonic( |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2906 | MagickCompressOptions,(ssize_t) image->compression)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2907 | break; |
| 2908 | } |
| 2909 | case 'D': |
| 2910 | { |
| 2911 | /* |
| 2912 | Image dispose method. |
| 2913 | */ |
| 2914 | q+=FormatMagickString(q,extent,"%s",MagickOptionToMnemonic( |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2915 | MagickDisposeOptions,(ssize_t) image->dispose)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2916 | break; |
| 2917 | } |
| 2918 | case 'G': |
| 2919 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2920 | q+=FormatMagickString(q,extent,"%lux%lu",(unsigned long) |
| 2921 | image->magick_columns,(unsigned long) image->magick_rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2922 | break; |
| 2923 | } |
| 2924 | case 'H': |
| 2925 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2926 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
| 2927 | image->page.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2928 | break; |
| 2929 | } |
| 2930 | case 'O': |
| 2931 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2932 | q+=FormatMagickString(q,extent,"%+ld%+ld",(long) image->page.x, |
| 2933 | (long) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2934 | break; |
| 2935 | } |
| 2936 | case 'P': |
| 2937 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2938 | q+=FormatMagickString(q,extent,"%lux%lu",(unsigned long) |
| 2939 | image->page.width,(unsigned long) image->page.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2940 | break; |
| 2941 | } |
| 2942 | case 'Q': |
| 2943 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2944 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) image->quality); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2945 | break; |
| 2946 | } |
| 2947 | case 'S': |
| 2948 | { |
| 2949 | /* |
| 2950 | Image scenes. |
| 2951 | */ |
| 2952 | if (text_info->number_scenes == 0) |
| 2953 | q+=CopyMagickString(q,"2147483647",extent); |
| 2954 | else |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2955 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) |
| 2956 | (text_info->scene+text_info->number_scenes)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2957 | break; |
| 2958 | } |
| 2959 | case 'T': |
| 2960 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2961 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) image->delay); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2962 | break; |
| 2963 | } |
| 2964 | case 'W': |
| 2965 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2966 | q+=FormatMagickString(q,extent,"%lu",(unsigned long) image->page.width); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2967 | break; |
| 2968 | } |
| 2969 | case 'X': |
| 2970 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2971 | q+=FormatMagickString(q,extent,"%+ld",(long) image->page.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2972 | break; |
| 2973 | } |
| 2974 | case 'Y': |
| 2975 | { |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2976 | q+=FormatMagickString(q,extent,"%+ld",(long) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2977 | break; |
| 2978 | } |
| 2979 | case 'Z': |
| 2980 | { |
| 2981 | /* |
| 2982 | Unique filename. |
| 2983 | */ |
| 2984 | (void) CopyMagickString(filename,text_info->zero,extent); |
| 2985 | q+=CopyMagickString(q,filename,extent); |
| 2986 | break; |
| 2987 | } |
| 2988 | case '[': |
| 2989 | { |
| 2990 | char |
| 2991 | pattern[MaxTextExtent]; |
| 2992 | |
| 2993 | const char |
| 2994 | *key, |
| 2995 | *value; |
| 2996 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2997 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2998 | depth; |
| 2999 | |
| 3000 | /* |
| 3001 | Image value. |
| 3002 | */ |
| 3003 | if (strchr(p,']') == (char *) NULL) |
| 3004 | break; |
| 3005 | depth=1; |
| 3006 | p++; |
| 3007 | for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++) |
| 3008 | { |
| 3009 | if (*p == '[') |
| 3010 | depth++; |
| 3011 | if (*p == ']') |
| 3012 | depth--; |
| 3013 | if (depth <= 0) |
| 3014 | break; |
| 3015 | pattern[i]=(*p++); |
| 3016 | } |
| 3017 | pattern[i]='\0'; |
| 3018 | value=GetImageProperty(image,pattern); |
| 3019 | if (value != (const char *) NULL) |
| 3020 | { |
| 3021 | length=strlen(value); |
| 3022 | if ((size_t) (q-interpret_text+length+1) >= extent) |
| 3023 | { |
| 3024 | extent+=length; |
| 3025 | interpret_text=(char *) ResizeQuantumMemory(interpret_text, |
| 3026 | extent+MaxTextExtent,sizeof(*interpret_text)); |
| 3027 | if (interpret_text == (char *) NULL) |
| 3028 | break; |
| 3029 | q=interpret_text+strlen(interpret_text); |
| 3030 | } |
| 3031 | (void) CopyMagickString(q,value,extent); |
| 3032 | q+=length; |
| 3033 | break; |
| 3034 | } |
| 3035 | else |
| 3036 | if (IsGlob(pattern) != MagickFalse) |
| 3037 | { |
| 3038 | /* |
| 3039 | Iterate over image properties. |
| 3040 | */ |
| 3041 | ResetImagePropertyIterator(image); |
| 3042 | key=GetNextImageProperty(image); |
| 3043 | while (key != (const char *) NULL) |
| 3044 | { |
| 3045 | if (GlobExpression(key,pattern,MagickTrue) != MagickFalse) |
| 3046 | { |
| 3047 | value=GetImageProperty(image,key); |
| 3048 | if (value != (const char *) NULL) |
| 3049 | { |
| 3050 | length=strlen(key)+strlen(value)+2; |
| 3051 | if ((size_t) (q-interpret_text+length+1) >= extent) |
| 3052 | { |
| 3053 | extent+=length; |
| 3054 | interpret_text=(char *) ResizeQuantumMemory( |
| 3055 | interpret_text,extent+MaxTextExtent, |
| 3056 | sizeof(*interpret_text)); |
| 3057 | if (interpret_text == (char *) NULL) |
| 3058 | break; |
| 3059 | q=interpret_text+strlen(interpret_text); |
| 3060 | } |
| 3061 | q+=FormatMagickString(q,extent,"%s=%s\n",key,value); |
| 3062 | } |
| 3063 | } |
| 3064 | key=GetNextImageProperty(image); |
| 3065 | } |
| 3066 | } |
| 3067 | value=GetMagickProperty(text_info,image,pattern); |
| 3068 | if (value != (const char *) NULL) |
| 3069 | { |
| 3070 | length=strlen(value); |
| 3071 | if ((size_t) (q-interpret_text+length+1) >= extent) |
| 3072 | { |
| 3073 | extent+=length; |
| 3074 | interpret_text=(char *) ResizeQuantumMemory(interpret_text, |
| 3075 | extent+MaxTextExtent,sizeof(*interpret_text)); |
| 3076 | if (interpret_text == (char *) NULL) |
| 3077 | break; |
| 3078 | q=interpret_text+strlen(interpret_text); |
| 3079 | } |
| 3080 | (void) CopyMagickString(q,value,extent); |
| 3081 | q+=length; |
cristy | 458b5fe | 2010-05-12 00:54:41 +0000 | [diff] [blame] | 3082 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3083 | } |
| 3084 | if (image_info == (ImageInfo *) NULL) |
| 3085 | break; |
| 3086 | value=GetImageOption(image_info,pattern); |
| 3087 | if (value != (char *) NULL) |
| 3088 | { |
| 3089 | length=strlen(value); |
| 3090 | if ((size_t) (q-interpret_text+length+1) >= extent) |
| 3091 | { |
| 3092 | extent+=length; |
| 3093 | interpret_text=(char *) ResizeQuantumMemory(interpret_text, |
| 3094 | extent+MaxTextExtent,sizeof(*interpret_text)); |
| 3095 | if (interpret_text == (char *) NULL) |
| 3096 | break; |
| 3097 | q=interpret_text+strlen(interpret_text); |
| 3098 | } |
| 3099 | (void) CopyMagickString(q,value,extent); |
| 3100 | q+=length; |
cristy | 458b5fe | 2010-05-12 00:54:41 +0000 | [diff] [blame] | 3101 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3102 | } |
| 3103 | break; |
| 3104 | } |
| 3105 | case '@': |
| 3106 | { |
| 3107 | RectangleInfo |
| 3108 | page; |
| 3109 | |
| 3110 | /* |
| 3111 | Image bounding box. |
| 3112 | */ |
| 3113 | page=GetImageBoundingBox(image,&image->exception); |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 3114 | q+=FormatMagickString(q,MaxTextExtent,"%lux%lu%+ld%+ld",(unsigned long) |
| 3115 | page.width,(unsigned long) page.height,(long) page.x,(long) page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3116 | break; |
| 3117 | } |
| 3118 | case '#': |
| 3119 | { |
| 3120 | /* |
| 3121 | Image signature. |
| 3122 | */ |
| 3123 | (void) SignatureImage(image); |
| 3124 | value=GetImageProperty(image,"signature"); |
| 3125 | if (value == (const char *) NULL) |
| 3126 | break; |
| 3127 | q+=CopyMagickString(q,value,extent); |
| 3128 | break; |
| 3129 | } |
| 3130 | case '%': |
| 3131 | { |
| 3132 | *q++=(*p); |
| 3133 | break; |
| 3134 | } |
| 3135 | default: |
| 3136 | { |
| 3137 | *q++='%'; |
| 3138 | *q++=(*p); |
| 3139 | break; |
| 3140 | } |
| 3141 | } |
| 3142 | } |
| 3143 | *q='\0'; |
| 3144 | text_info=DestroyImageInfo(text_info); |
| 3145 | if (text != (const char *) embed_text) |
| 3146 | text=DestroyString(text); |
| 3147 | (void) SubstituteString(&interpret_text,"<","<"); |
| 3148 | (void) SubstituteString(&interpret_text,">",">"); |
| 3149 | return(interpret_text); |
| 3150 | } |
| 3151 | |
| 3152 | /* |
| 3153 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3154 | % % |
| 3155 | % % |
| 3156 | % % |
| 3157 | % R e m o v e I m a g e P r o p e r t y % |
| 3158 | % % |
| 3159 | % % |
| 3160 | % % |
| 3161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3162 | % |
| 3163 | % RemoveImageProperty() removes a property from the image and returns its |
| 3164 | % value. |
| 3165 | % |
| 3166 | % The format of the RemoveImageProperty method is: |
| 3167 | % |
| 3168 | % char *RemoveImageProperty(Image *image,const char *property) |
| 3169 | % |
| 3170 | % A description of each parameter follows: |
| 3171 | % |
| 3172 | % o image: the image. |
| 3173 | % |
| 3174 | % o property: the image property. |
| 3175 | % |
| 3176 | */ |
| 3177 | MagickExport char *RemoveImageProperty(Image *image, |
| 3178 | const char *property) |
| 3179 | { |
| 3180 | char |
| 3181 | *value; |
| 3182 | |
| 3183 | assert(image != (Image *) NULL); |
| 3184 | assert(image->signature == MagickSignature); |
| 3185 | if (image->debug != MagickFalse) |
| 3186 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 3187 | image->filename); |
| 3188 | if (image->properties == (void *) NULL) |
| 3189 | return((char *) NULL); |
| 3190 | value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties, |
| 3191 | property); |
| 3192 | return(value); |
| 3193 | } |
| 3194 | |
| 3195 | /* |
| 3196 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3197 | % % |
| 3198 | % % |
| 3199 | % % |
| 3200 | % R e s e t I m a g e P r o p e r t y I t e r a t o r % |
| 3201 | % % |
| 3202 | % % |
| 3203 | % % |
| 3204 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3205 | % |
| 3206 | % ResetImagePropertyIterator() resets the image properties iterator. Use it |
| 3207 | % in conjunction with GetNextImageProperty() to iterate over all the values |
| 3208 | % associated with an image property. |
| 3209 | % |
| 3210 | % The format of the ResetImagePropertyIterator method is: |
| 3211 | % |
| 3212 | % ResetImagePropertyIterator(Image *image) |
| 3213 | % |
| 3214 | % A description of each parameter follows: |
| 3215 | % |
| 3216 | % o image: the image. |
| 3217 | % |
| 3218 | */ |
| 3219 | MagickExport void ResetImagePropertyIterator(const Image *image) |
| 3220 | { |
| 3221 | assert(image != (Image *) NULL); |
| 3222 | assert(image->signature == MagickSignature); |
| 3223 | if (image->debug != MagickFalse) |
| 3224 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 3225 | image->filename); |
| 3226 | if (image->properties == (void *) NULL) |
| 3227 | return; |
| 3228 | ResetSplayTreeIterator((SplayTreeInfo *) image->properties); |
| 3229 | } |
| 3230 | |
| 3231 | /* |
| 3232 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3233 | % % |
| 3234 | % % |
| 3235 | % % |
| 3236 | % S e t I m a g e P r o p e r t y % |
| 3237 | % % |
| 3238 | % % |
| 3239 | % % |
| 3240 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3241 | % |
| 3242 | % SetImageProperty() associates an value with an image property. |
| 3243 | % |
| 3244 | % The format of the SetImageProperty method is: |
| 3245 | % |
| 3246 | % MagickBooleanType SetImageProperty(Image *image,const char *property, |
| 3247 | % const char *value) |
| 3248 | % |
| 3249 | % A description of each parameter follows: |
| 3250 | % |
| 3251 | % o image: the image. |
| 3252 | % |
| 3253 | % o property: the image property. |
| 3254 | % |
| 3255 | % o values: the image property values. |
| 3256 | % |
| 3257 | */ |
| 3258 | MagickExport MagickBooleanType SetImageProperty(Image *image, |
| 3259 | const char *property,const char *value) |
| 3260 | { |
| 3261 | MagickBooleanType |
| 3262 | status; |
| 3263 | |
| 3264 | MagickStatusType |
| 3265 | flags; |
| 3266 | |
| 3267 | assert(image != (Image *) NULL); |
| 3268 | assert(image->signature == MagickSignature); |
| 3269 | if (image->debug != MagickFalse) |
| 3270 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 3271 | image->filename); |
| 3272 | if (image->properties == (void *) NULL) |
| 3273 | image->properties=NewSplayTree(CompareSplayTreeString, |
| 3274 | RelinquishMagickMemory,RelinquishMagickMemory); |
| 3275 | if ((value == (const char *) NULL) || (*value == '\0')) |
| 3276 | return(DeleteImageProperty(image,property)); |
| 3277 | status=MagickTrue; |
| 3278 | switch (*property) |
| 3279 | { |
| 3280 | case 'B': |
| 3281 | case 'b': |
| 3282 | { |
| 3283 | if (LocaleCompare(property,"bias") == 0) |
| 3284 | { |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 3285 | image->bias=SiPrefixToDouble(value,QuantumRange); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3286 | break; |
| 3287 | } |
| 3288 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3289 | ConstantString(property),ConstantString(value)); |
| 3290 | break; |
| 3291 | } |
| 3292 | case 'C': |
| 3293 | case 'c': |
| 3294 | { |
| 3295 | if (LocaleCompare(property,"colorspace") == 0) |
| 3296 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3297 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3298 | colorspace; |
| 3299 | |
| 3300 | colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse, |
| 3301 | value); |
| 3302 | if (colorspace < 0) |
| 3303 | break; |
| 3304 | (void) SetImageColorspace(image,(ColorspaceType) colorspace); |
| 3305 | break; |
| 3306 | } |
| 3307 | if (LocaleCompare(property,"compose") == 0) |
| 3308 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3309 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3310 | compose; |
| 3311 | |
| 3312 | compose=ParseMagickOption(MagickComposeOptions,MagickFalse,value); |
| 3313 | if (compose < 0) |
| 3314 | break; |
| 3315 | image->compose=(CompositeOperator) compose; |
| 3316 | break; |
| 3317 | } |
| 3318 | if (LocaleCompare(property,"compress") == 0) |
| 3319 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3320 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3321 | compression; |
| 3322 | |
| 3323 | compression=ParseMagickOption(MagickCompressOptions,MagickFalse, |
| 3324 | value); |
| 3325 | if (compression < 0) |
| 3326 | break; |
| 3327 | image->compression=(CompressionType) compression; |
| 3328 | break; |
| 3329 | } |
| 3330 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3331 | ConstantString(property),ConstantString(value)); |
| 3332 | break; |
| 3333 | } |
| 3334 | case 'D': |
| 3335 | case 'd': |
| 3336 | { |
| 3337 | if (LocaleCompare(property,"delay") == 0) |
| 3338 | { |
| 3339 | GeometryInfo |
| 3340 | geometry_info; |
| 3341 | |
| 3342 | flags=ParseGeometry(value,&geometry_info); |
| 3343 | if ((flags & GreaterValue) != 0) |
| 3344 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3345 | if (image->delay > (size_t) floor(geometry_info.rho+0.5)) |
| 3346 | image->delay=(size_t) floor(geometry_info.rho+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3347 | } |
| 3348 | else |
| 3349 | if ((flags & LessValue) != 0) |
| 3350 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3351 | if (image->delay < (size_t) floor(geometry_info.rho+0.5)) |
| 3352 | image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3353 | } |
| 3354 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3355 | image->delay=(size_t) floor(geometry_info.rho+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3356 | if ((flags & SigmaValue) != 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3357 | image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3358 | break; |
| 3359 | } |
| 3360 | if (LocaleCompare(property,"depth") == 0) |
| 3361 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 3362 | image->depth=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3363 | break; |
| 3364 | } |
| 3365 | if (LocaleCompare(property,"dispose") == 0) |
| 3366 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3367 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3368 | dispose; |
| 3369 | |
| 3370 | dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,value); |
| 3371 | if (dispose < 0) |
| 3372 | break; |
| 3373 | image->dispose=(DisposeType) dispose; |
| 3374 | break; |
| 3375 | } |
| 3376 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3377 | ConstantString(property),ConstantString(value)); |
| 3378 | break; |
| 3379 | } |
| 3380 | case 'G': |
| 3381 | case 'g': |
| 3382 | { |
| 3383 | if (LocaleCompare(property,"gravity") == 0) |
| 3384 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3385 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3386 | gravity; |
| 3387 | |
| 3388 | gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,value); |
| 3389 | if (gravity < 0) |
| 3390 | break; |
| 3391 | image->gravity=(GravityType) gravity; |
| 3392 | break; |
| 3393 | } |
| 3394 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3395 | ConstantString(property),ConstantString(value)); |
| 3396 | break; |
| 3397 | } |
| 3398 | case 'I': |
| 3399 | case 'i': |
| 3400 | { |
| 3401 | if (LocaleCompare(property,"intent") == 0) |
| 3402 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3403 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3404 | rendering_intent; |
| 3405 | |
| 3406 | rendering_intent=ParseMagickOption(MagickIntentOptions,MagickFalse, |
| 3407 | value); |
| 3408 | if (rendering_intent < 0) |
| 3409 | break; |
| 3410 | image->rendering_intent=(RenderingIntent) rendering_intent; |
| 3411 | break; |
| 3412 | } |
| 3413 | if (LocaleCompare(property,"interpolate") == 0) |
| 3414 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3415 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3416 | interpolate; |
| 3417 | |
| 3418 | interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse, |
| 3419 | value); |
| 3420 | if (interpolate < 0) |
| 3421 | break; |
| 3422 | image->interpolate=(InterpolatePixelMethod) interpolate; |
| 3423 | break; |
| 3424 | } |
| 3425 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3426 | ConstantString(property),ConstantString(value)); |
| 3427 | break; |
| 3428 | } |
| 3429 | case 'L': |
| 3430 | case 'l': |
| 3431 | { |
| 3432 | if (LocaleCompare(property,"loop") == 0) |
| 3433 | { |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 3434 | image->iterations=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3435 | break; |
| 3436 | } |
| 3437 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3438 | ConstantString(property),ConstantString(value)); |
| 3439 | break; |
| 3440 | } |
| 3441 | case 'P': |
| 3442 | case 'p': |
| 3443 | { |
| 3444 | if (LocaleCompare(property,"page") == 0) |
| 3445 | { |
| 3446 | char |
| 3447 | *geometry; |
| 3448 | |
| 3449 | geometry=GetPageGeometry(value); |
| 3450 | flags=ParseAbsoluteGeometry(geometry,&image->page); |
| 3451 | geometry=DestroyString(geometry); |
| 3452 | break; |
| 3453 | } |
cristy | 071dd7b | 2010-04-09 13:04:54 +0000 | [diff] [blame] | 3454 | if (LocaleCompare(property,"profile") == 0) |
| 3455 | { |
| 3456 | ImageInfo |
| 3457 | *image_info; |
| 3458 | |
| 3459 | StringInfo |
| 3460 | *profile; |
| 3461 | |
| 3462 | image_info=AcquireImageInfo(); |
| 3463 | (void) CopyMagickString(image_info->filename,value,MaxTextExtent); |
| 3464 | (void) SetImageInfo(image_info,1,&image->exception); |
| 3465 | profile=FileToStringInfo(image_info->filename,~0UL,&image->exception); |
| 3466 | if (profile != (StringInfo *) NULL) |
| 3467 | status=SetImageProfile(image,image_info->magick,profile); |
| 3468 | image_info=DestroyImageInfo(image_info); |
| 3469 | break; |
| 3470 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3471 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3472 | ConstantString(property),ConstantString(value)); |
| 3473 | break; |
| 3474 | } |
| 3475 | case 'R': |
| 3476 | case 'r': |
| 3477 | { |
| 3478 | if (LocaleCompare(property,"rendering-intent") == 0) |
| 3479 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3480 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3481 | rendering_intent; |
| 3482 | |
| 3483 | rendering_intent=ParseMagickOption(MagickIntentOptions,MagickFalse, |
| 3484 | value); |
| 3485 | if (rendering_intent < 0) |
| 3486 | break; |
| 3487 | image->rendering_intent=(RenderingIntent) rendering_intent; |
| 3488 | break; |
| 3489 | } |
| 3490 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3491 | ConstantString(property),ConstantString(value)); |
| 3492 | break; |
| 3493 | } |
| 3494 | case 'T': |
| 3495 | case 't': |
| 3496 | { |
| 3497 | if (LocaleCompare(property,"tile-offset") == 0) |
| 3498 | { |
| 3499 | char |
| 3500 | *geometry; |
| 3501 | |
| 3502 | geometry=GetPageGeometry(value); |
| 3503 | flags=ParseAbsoluteGeometry(geometry,&image->tile_offset); |
| 3504 | geometry=DestroyString(geometry); |
| 3505 | break; |
| 3506 | } |
| 3507 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3508 | ConstantString(property),ConstantString(value)); |
| 3509 | break; |
| 3510 | } |
| 3511 | default: |
| 3512 | { |
| 3513 | status=AddValueToSplayTree((SplayTreeInfo *) image->properties, |
| 3514 | ConstantString(property),ConstantString(value)); |
| 3515 | break; |
| 3516 | } |
| 3517 | } |
| 3518 | return(status); |
| 3519 | } |