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