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