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