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