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