MagickCore 7.1.2-18
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 components=1;
1569 EXIFGPSFractions("%.20g/%.20g,%.20g/%.20g,%.20g/%.20g",
1570 (double) ReadPropertyUnsignedLong(endian,p),
1571 (double) ReadPropertyUnsignedLong(endian,p+4),
1572 (double) ReadPropertyUnsignedLong(endian,p+8),
1573 (double) ReadPropertyUnsignedLong(endian,p+12),
1574 (double) ReadPropertyUnsignedLong(endian,p+16),
1575 (double) ReadPropertyUnsignedLong(endian,p+20));
1576 break;
1577 }
1578 EXIFMultipleFractions("%.20g/%.20g",(double)
1579 ReadPropertyUnsignedLong(endian,p),(double)
1580 ReadPropertyUnsignedLong(endian,p+4));
1581 break;
1582 }
1583 case EXIF_FMT_SRATIONAL:
1584 {
1585 EXIFMultipleFractions("%.20g/%.20g",(double)
1586 ReadPropertySignedLong(endian,p),(double)
1587 ReadPropertySignedLong(endian,p+4));
1588 break;
1589 }
1590 case EXIF_FMT_SINGLE:
1591 {
1592 EXIFMultipleValues("%.20g",(double)
1593 ReadPropertySignedLong(endian,p));
1594 break;
1595 }
1596 case EXIF_FMT_DOUBLE:
1597 {
1598 EXIFMultipleValues("%.20g",(double)
1599 ReadPropertySignedLong(endian,p));
1600 break;
1601 }
1602 case EXIF_FMT_STRING:
1603 case EXIF_FMT_UNDEFINED:
1604 default:
1605 {
1606 if ((p < exif) || (p > (exif+length-number_bytes)))
1607 break;
1608 value=(char *) NULL;
1609 if (~((size_t) number_bytes) >= 1)
1610 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1611 sizeof(*value));
1612 if (value != (char *) NULL)
1613 {
1614 for (i=0; i < (ssize_t) number_bytes; i++)
1615 {
1616 value[i]='.';
1617 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1618 value[i]=(char) p[i];
1619 }
1620 value[i]='\0';
1621 }
1622 break;
1623 }
1624 }
1625 if (value != (char *) NULL)
1626 {
1627 char
1628 *key;
1629
1630 key=AcquireString(property);
1631 switch (all)
1632 {
1633 case 1:
1634 {
1635 const char
1636 *description;
1637
1638 description="unknown";
1639 for (i=0; ; i++)
1640 {
1641 if (EXIFTag[i].tag == 0)
1642 break;
1643 if (EXIFTag[i].tag == tag_value)
1644 {
1645 description=EXIFTag[i].description;
1646 break;
1647 }
1648 }
1649 (void) FormatLocaleString(key,MagickPathExtent,"%s",
1650 description);
1651 if (level == 2)
1652 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1653 break;
1654 }
1655 case 2:
1656 {
1657 if (tag_value < 0x10000)
1658 (void) FormatLocaleString(key,MagickPathExtent,"#%04lx",
1659 (unsigned long) tag_value);
1660 else
1661 if (tag_value < 0x20000)
1662 (void) FormatLocaleString(key,MagickPathExtent,"@%04lx",
1663 (unsigned long) (tag_value & 0xffff));
1664 else
1665 (void) FormatLocaleString(key,MagickPathExtent,"unknown");
1666 break;
1667 }
1668 default:
1669 {
1670 if (level == 2)
1671 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1672 }
1673 }
1674 if ((image->properties == (void *) NULL) ||
1675 (GetValueFromSplayTree((SplayTreeInfo *) image->properties,key) == (const void *) NULL))
1676 (void) SetImageProperty((Image *) image,key,value,exception);
1677 value=DestroyString(value);
1678 key=DestroyString(key);
1679 }
1680 }
1681 if ((tag_value == TAG_EXIF_OFFSET) ||
1682 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1683 {
1684 ssize_t
1685 tag_offset1;
1686
1687 tag_offset1=(ssize_t) ReadPropertySignedLong(endian,p);
1688 if (((size_t) tag_offset1 < length) &&
1689 (level < (MaxDirectoryStack-2)))
1690 {
1691 ssize_t
1692 tag_offset2;
1693
1694 tag_offset2=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1695 0);
1696 directory_stack[level].directory=directory;
1697 entry++;
1698 directory_stack[level].entry=entry;
1699 directory_stack[level].offset=tag_offset;
1700 level++;
1701 /*
1702 Check for duplicate tag.
1703 */
1704 for (i=0; i < level; i++)
1705 if (directory_stack[i].directory == (exif+tag_offset1))
1706 break;
1707 if (i < level)
1708 break; /* duplicate tag */
1709 directory_stack[level].directory=exif+tag_offset1;
1710 directory_stack[level].offset=tag_offset2;
1711 directory_stack[level].entry=0;
1712 level++;
1713 if ((directory+2+(12*number_entries)+4) > (exif+length))
1714 break;
1715 tag_offset1=(ssize_t) ReadPropertySignedLong(endian,directory+
1716 2+(12*number_entries));
1717 if ((tag_offset1 != 0) && ((size_t) tag_offset1 < length) &&
1718 (level < (MaxDirectoryStack-2)))
1719 {
1720 directory_stack[level].directory=exif+tag_offset1;
1721 directory_stack[level].entry=0;
1722 directory_stack[level].offset=tag_offset2;
1723 level++;
1724 }
1725 }
1726 break;
1727 }
1728 }
1729 } while (level > 0);
1730 exif_resources=DestroySplayTree(exif_resources);
1731}
1732
1733#if defined(MAGICKCORE_LCMS_DELEGATE)
1734static void GetICCProperty(const Image *image,ExceptionInfo *exception)
1735{
1736
1737 const StringInfo
1738 *profile;
1739
1740 cmsHPROFILE
1741 icc_profile;
1742
1743 /*
1744 Return ICC profile property.
1745 */
1746 profile=GetImageProfile(image,"icc");
1747 if (profile == (StringInfo *) NULL)
1748 profile=GetImageProfile(image,"icm");
1749 if (profile == (StringInfo *) NULL)
1750 return;
1751 if (GetStringInfoLength(profile) < 128)
1752 return; /* minimum ICC profile length */
1753 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
1754 (cmsUInt32Number) GetStringInfoLength(profile));
1755 if (icc_profile != (cmsHPROFILE *) NULL)
1756 {
1757#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
1758 const char
1759 *name;
1760
1761 name=cmsTakeProductName(icc_profile);
1762 if (name != (const char *) NULL)
1763 (void) SetImageProperty((Image *) image,"icc:name",name,exception);
1764#else
1765 StringInfo
1766 *info;
1767
1768 unsigned int
1769 extent;
1770
1771 info=AcquireStringInfo(0);
1772 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,"en","US",
1773 NULL,0);
1774 if (extent != 0)
1775 {
1776 SetStringInfoLength(info,extent+1);
1777 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,"en",
1778 "US",(char *) GetStringInfoDatum(info),extent);
1779 if (extent != 0)
1780 (void) SetImageProperty((Image *) image,"icc:description",
1781 (char *) GetStringInfoDatum(info),exception);
1782 }
1783 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,"en","US",
1784 NULL,0);
1785 if (extent != 0)
1786 {
1787 SetStringInfoLength(info,extent+1);
1788 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,"en",
1789 "US",(char *) GetStringInfoDatum(info),extent);
1790 if (extent != 0)
1791 (void) SetImageProperty((Image *) image,"icc:manufacturer",
1792 (char *) GetStringInfoDatum(info),exception);
1793 }
1794 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en","US",
1795 NULL,0);
1796 if (extent != 0)
1797 {
1798 SetStringInfoLength(info,extent+1);
1799 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en","US",
1800 (char *) GetStringInfoDatum(info),extent);
1801 if (extent != 0)
1802 (void) SetImageProperty((Image *) image,"icc:model",
1803 (char *) GetStringInfoDatum(info),exception);
1804 }
1805 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,"en","US",
1806 NULL,0);
1807 if (extent != 0)
1808 {
1809 SetStringInfoLength(info,extent+1);
1810 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,"en",
1811 "US",(char *) GetStringInfoDatum(info),extent);
1812 if (extent != 0)
1813 (void) SetImageProperty((Image *) image,"icc:copyright",
1814 (char *) GetStringInfoDatum(info),exception);
1815 }
1816 info=DestroyStringInfo(info);
1817#endif
1818 (void) cmsCloseProfile(icc_profile);
1819 }
1820}
1821#endif
1822
1823static MagickBooleanType SkipXMPValue(const char *value)
1824{
1825 if (value == (const char*) NULL)
1826 return(MagickTrue);
1827 while (*value != '\0')
1828 {
1829 if (isspace((int) ((unsigned char) *value)) == 0)
1830 return(MagickFalse);
1831 value++;
1832 }
1833 return(MagickTrue);
1834}
1835
1836static void GetXMPProperty(const Image *image,const char *property)
1837{
1838 char
1839 *xmp_profile;
1840
1841 const char
1842 *content;
1843
1844 const StringInfo
1845 *profile;
1846
1847 ExceptionInfo
1848 *exception;
1849
1850 const char
1851 *p;
1852
1853 XMLTreeInfo
1854 *child,
1855 *description,
1856 *node,
1857 *rdf,
1858 *xmp;
1859
1860 profile=GetImageProfile(image,"xmp");
1861 if (profile == (StringInfo *) NULL)
1862 return;
1863 if (GetStringInfoLength(profile) < 17)
1864 return;
1865 if ((property == (const char *) NULL) || (*property == '\0'))
1866 return;
1867 xmp_profile=StringInfoToString(profile);
1868 if (xmp_profile == (char *) NULL)
1869 return;
1870 for (p=xmp_profile; *p != '\0'; p++)
1871 if ((*p == '<') && (*(p+1) == 'x'))
1872 break;
1873 exception=AcquireExceptionInfo();
1874 xmp=NewXMLTree((char *) p,exception);
1875 xmp_profile=DestroyString(xmp_profile);
1876 exception=DestroyExceptionInfo(exception);
1877 if (xmp == (XMLTreeInfo *) NULL)
1878 return;
1879 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1880 if (rdf != (XMLTreeInfo *) NULL)
1881 {
1882 if (image->properties == (void *) NULL)
1883 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1884 RelinquishMagickMemory,RelinquishMagickMemory);
1885 description=GetXMLTreeChild(rdf,"rdf:Description");
1886 while (description != (XMLTreeInfo *) NULL)
1887 {
1888 char
1889 *property;
1890
1891 size_t
1892 property_length;
1893
1894 node=GetXMLTreeChild(description,(const char *) NULL);
1895 while (node != (XMLTreeInfo *) NULL)
1896 {
1897 child=GetXMLTreeChild(node,(const char *) NULL);
1898 content=GetXMLTreeContent(node);
1899 if ((child == (XMLTreeInfo *) NULL) &&
1900 (SkipXMPValue(content) == MagickFalse))
1901 {
1902 property=ConstantString(GetXMLTreeTag(node));
1903 (void) SubstituteString(&property,"exif:","xmp:");
1904 property_length=strlen(property);
1905 if ((property_length <= 2) || (*(property+(property_length-2)) != ':') ||
1906 (*(property+(property_length-1)) != '*'))
1907 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1908 ConstantString(property),ConstantString(content));
1909 property=DestroyString(property);
1910 }
1911 while (child != (XMLTreeInfo *) NULL)
1912 {
1913 content=GetXMLTreeContent(child);
1914 if (SkipXMPValue(content) == MagickFalse)
1915 {
1916 property=ConstantString(GetXMLTreeTag(node));
1917 (void) SubstituteString(&property,"exif:","xmp:");
1918 property_length=strlen(property);
1919 if ((property_length <= 2) || (*(property+(property_length-2)) != ':') ||
1920 (*(property+(property_length-1)) != '*'))
1921 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1922 ConstantString(property),ConstantString(content));
1923 property=DestroyString(property);
1924 }
1925 child=GetXMLTreeSibling(child);
1926 }
1927 node=GetXMLTreeSibling(node);
1928 }
1929 description=GetNextXMLTreeTag(description);
1930 }
1931 }
1932 xmp=DestroyXMLTree(xmp);
1933}
1934
1935static char *TracePSClippath(const unsigned char *blob,size_t length)
1936{
1937 char
1938 *path,
1939 *message;
1940
1941 MagickBooleanType
1942 in_subpath;
1943
1944 PointInfo
1945 first[3],
1946 last[3],
1947 point[3];
1948
1949 ssize_t
1950 i,
1951 x;
1952
1953 ssize_t
1954 knot_count,
1955 selector,
1956 y;
1957
1958 path=AcquireString((char *) NULL);
1959 if (path == (char *) NULL)
1960 return((char *) NULL);
1961 message=AcquireString((char *) NULL);
1962 (void) FormatLocaleString(message,MagickPathExtent,"/ClipImage\n");
1963 (void) ConcatenateString(&path,message);
1964 (void) FormatLocaleString(message,MagickPathExtent,"{\n");
1965 (void) ConcatenateString(&path,message);
1966 (void) FormatLocaleString(message,MagickPathExtent,
1967 " /c {curveto} bind def\n");
1968 (void) ConcatenateString(&path,message);
1969 (void) FormatLocaleString(message,MagickPathExtent,
1970 " /l {lineto} bind def\n");
1971 (void) ConcatenateString(&path,message);
1972 (void) FormatLocaleString(message,MagickPathExtent,
1973 " /m {moveto} bind def\n");
1974 (void) ConcatenateString(&path,message);
1975 (void) FormatLocaleString(message,MagickPathExtent,
1976 " /v {currentpoint 6 2 roll curveto} bind def\n");
1977 (void) ConcatenateString(&path,message);
1978 (void) FormatLocaleString(message,MagickPathExtent,
1979 " /y {2 copy curveto} bind def\n");
1980 (void) ConcatenateString(&path,message);
1981 (void) FormatLocaleString(message,MagickPathExtent,
1982 " /z {closepath} bind def\n");
1983 (void) ConcatenateString(&path,message);
1984 (void) FormatLocaleString(message,MagickPathExtent," newpath\n");
1985 (void) ConcatenateString(&path,message);
1986 /*
1987 The clipping path format is defined in "Adobe Photoshop File Formats
1988 Specification" version 6.0 downloadable from adobe.com.
1989 */
1990 (void) memset(point,0,sizeof(point));
1991 (void) memset(first,0,sizeof(first));
1992 (void) memset(last,0,sizeof(last));
1993 knot_count=0;
1994 in_subpath=MagickFalse;
1995 while (length > 0)
1996 {
1997 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1998 switch (selector)
1999 {
2000 case 0:
2001 case 3:
2002 {
2003 if (knot_count != 0)
2004 {
2005 blob+=24;
2006 length=(size_t) ((ssize_t) length-MagickMin(24,(ssize_t) length));
2007 break;
2008 }
2009 /*
2010 Expected subpath length record.
2011 */
2012 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
2013 blob+=22;
2014 length=(size_t) ((ssize_t) length-MagickMin(22,(ssize_t) length));
2015 break;
2016 }
2017 case 1:
2018 case 2:
2019 case 4:
2020 case 5:
2021 {
2022 if (knot_count == 0)
2023 {
2024 /*
2025 Unexpected subpath knot
2026 */
2027 blob+=24;
2028 length=(size_t) ((ssize_t) length-MagickMin(24,(ssize_t) length));
2029 break;
2030 }
2031 /*
2032 Add sub-path knot
2033 */
2034 for (i=0; i < 3; i++)
2035 {
2036 y=(ssize_t) ReadPropertyMSBLong(&blob,&length);
2037 x=(ssize_t) ReadPropertyMSBLong(&blob,&length);
2038 point[i].x=(double) x/4096.0/4096.0;
2039 point[i].y=1.0-(double) y/4096.0/4096.0;
2040 }
2041 if (in_subpath == MagickFalse)
2042 {
2043 (void) FormatLocaleString(message,MagickPathExtent," %g %g m\n",
2044 point[1].x,point[1].y);
2045 for (i=0; i < 3; i++)
2046 {
2047 first[i]=point[i];
2048 last[i]=point[i];
2049 }
2050 }
2051 else
2052 {
2053 /*
2054 Handle special cases when Bezier curves are used to describe
2055 corners and straight lines.
2056 */
2057 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
2058 (point[0].x == point[1].x) && (point[0].y == point[1].y))
2059 (void) FormatLocaleString(message,MagickPathExtent,
2060 " %g %g l\n",point[1].x,point[1].y);
2061 else
2062 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
2063 (void) FormatLocaleString(message,MagickPathExtent,
2064 " %g %g %g %g v\n",point[0].x,point[0].y,
2065 point[1].x,point[1].y);
2066 else
2067 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
2068 (void) FormatLocaleString(message,MagickPathExtent,
2069 " %g %g %g %g y\n",last[2].x,last[2].y,
2070 point[1].x,point[1].y);
2071 else
2072 (void) FormatLocaleString(message,MagickPathExtent,
2073 " %g %g %g %g %g %g c\n",last[2].x,
2074 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
2075 for (i=0; i < 3; i++)
2076 last[i]=point[i];
2077 }
2078 (void) ConcatenateString(&path,message);
2079 in_subpath=MagickTrue;
2080 knot_count--;
2081 /*
2082 Close the subpath if there are no more knots.
2083 */
2084 if (knot_count == 0)
2085 {
2086 /*
2087 Same special handling as above except we compare to the
2088 first point in the path and close the path.
2089 */
2090 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
2091 (first[0].x == first[1].x) && (first[0].y == first[1].y))
2092 (void) FormatLocaleString(message,MagickPathExtent,
2093 " %g %g l z\n",first[1].x,first[1].y);
2094 else
2095 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
2096 (void) FormatLocaleString(message,MagickPathExtent,
2097 " %g %g %g %g v z\n",first[0].x,first[0].y,
2098 first[1].x,first[1].y);
2099 else
2100 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
2101 (void) FormatLocaleString(message,MagickPathExtent,
2102 " %g %g %g %g y z\n",last[2].x,last[2].y,
2103 first[1].x,first[1].y);
2104 else
2105 (void) FormatLocaleString(message,MagickPathExtent,
2106 " %g %g %g %g %g %g c z\n",last[2].x,
2107 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
2108 (void) ConcatenateString(&path,message);
2109 in_subpath=MagickFalse;
2110 }
2111 break;
2112 }
2113 case 6:
2114 case 7:
2115 case 8:
2116 default:
2117 {
2118 blob+=24;
2119 length=(size_t) ((ssize_t) length-MagickMin(24,(ssize_t) length));
2120 break;
2121 }
2122 }
2123 }
2124 /*
2125 Returns an empty PS path if the path has no knots.
2126 */
2127 (void) FormatLocaleString(message,MagickPathExtent," eoclip\n");
2128 (void) ConcatenateString(&path,message);
2129 (void) FormatLocaleString(message,MagickPathExtent,"} bind def");
2130 (void) ConcatenateString(&path,message);
2131 message=DestroyString(message);
2132 return(path);
2133}
2134
2135static inline void TraceBezierCurve(char *message,PointInfo *last,
2136 PointInfo *point)
2137{
2138 /*
2139 Handle special cases when Bezier curves are used to describe
2140 corners and straight lines.
2141 */
2142 if (((last+1)->x == (last+2)->x) && ((last+1)->y == (last+2)->y) &&
2143 (point->x == (point+1)->x) && (point->y == (point+1)->y))
2144 (void) FormatLocaleString(message,MagickPathExtent,
2145 "L %g %g\n",point[1].x,point[1].y);
2146 else
2147 (void) FormatLocaleString(message,MagickPathExtent,"C %g %g %g %g %g %g\n",
2148 (last+2)->x,(last+2)->y,point->x,point->y,(point+1)->x,(point+1)->y);
2149}
2150
2151static char *TraceSVGClippath(const unsigned char *blob,size_t length,
2152 const size_t columns,const size_t rows)
2153{
2154 char
2155 *path,
2156 *message;
2157
2158 MagickBooleanType
2159 in_subpath;
2160
2161 PointInfo
2162 first[3],
2163 last[3],
2164 point[3];
2165
2166 ssize_t
2167 i;
2168
2169 ssize_t
2170 knot_count,
2171 selector,
2172 x,
2173 y;
2174
2175 path=AcquireString((char *) NULL);
2176 if (path == (char *) NULL)
2177 return((char *) NULL);
2178 message=AcquireString((char *) NULL);
2179 (void) FormatLocaleString(message,MagickPathExtent,(
2180 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
2181 "<svg xmlns=\"http://www.w3.org/2000/svg\""
2182 " width=\"%.20g\" height=\"%.20g\">\n"
2183 "<g>\n"
2184 "<path fill-rule=\"evenodd\" style=\"fill:#000000;stroke:#000000;"
2185 "stroke-width:0;stroke-antialiasing:false\" d=\"\n"),(double) columns,
2186 (double) rows);
2187 (void) ConcatenateString(&path,message);
2188 (void) memset(point,0,sizeof(point));
2189 (void) memset(first,0,sizeof(first));
2190 (void) memset(last,0,sizeof(last));
2191 knot_count=0;
2192 in_subpath=MagickFalse;
2193 while (length != 0)
2194 {
2195 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
2196 switch (selector)
2197 {
2198 case 0:
2199 case 3:
2200 {
2201 if (knot_count != 0)
2202 {
2203 blob+=24;
2204 length=(size_t) ((ssize_t) length-MagickMin(24,(ssize_t) length));
2205 break;
2206 }
2207 /*
2208 Expected subpath length record.
2209 */
2210 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
2211 blob+=22;
2212 length=(size_t) ((ssize_t) length-MagickMin(22,(ssize_t) length));
2213 break;
2214 }
2215 case 1:
2216 case 2:
2217 case 4:
2218 case 5:
2219 {
2220 if (knot_count == 0)
2221 {
2222 /*
2223 Unexpected subpath knot.
2224 */
2225 blob+=24;
2226 length=(size_t) ((ssize_t) length-MagickMin(24,(ssize_t) length));
2227 break;
2228 }
2229 /*
2230 Add sub-path knot
2231 */
2232 for (i=0; i < 3; i++)
2233 {
2234 y=(ssize_t) ReadPropertyMSBLong(&blob,&length);
2235 x=(ssize_t) ReadPropertyMSBLong(&blob,&length);
2236 point[i].x=(double) x*columns/4096.0/4096.0;
2237 point[i].y=(double) y*rows/4096.0/4096.0;
2238 }
2239 if (in_subpath == MagickFalse)
2240 {
2241 (void) FormatLocaleString(message,MagickPathExtent,"M %g %g\n",
2242 point[1].x,point[1].y);
2243 for (i=0; i < 3; i++)
2244 {
2245 first[i]=point[i];
2246 last[i]=point[i];
2247 }
2248 }
2249 else
2250 {
2251 TraceBezierCurve(message,last,point);
2252 for (i=0; i < 3; i++)
2253 last[i]=point[i];
2254 }
2255 (void) ConcatenateString(&path,message);
2256 in_subpath=MagickTrue;
2257 knot_count--;
2258 /*
2259 Close the subpath if there are no more knots.
2260 */
2261 if (knot_count == 0)
2262 {
2263 TraceBezierCurve(message,last,first);
2264 (void) ConcatenateString(&path,message);
2265 in_subpath=MagickFalse;
2266 }
2267 break;
2268 }
2269 case 6:
2270 case 7:
2271 case 8:
2272 default:
2273 {
2274 blob+=24;
2275 length=(size_t) ((ssize_t) length-MagickMin(24,(ssize_t) length));
2276 break;
2277 }
2278 }
2279 }
2280 /*
2281 Return an empty SVG image if the path does not have knots.
2282 */
2283 (void) ConcatenateString(&path,"\"/>\n</g>\n</svg>\n");
2284 message=DestroyString(message);
2285 return(path);
2286}
2287
2288MagickExport const char *GetImageProperty(const Image *image,
2289 const char *property,ExceptionInfo *exception)
2290{
2291 MagickBooleanType
2292 read_from_properties;
2293
2294 const char
2295 *p;
2296
2297 size_t
2298 property_length;
2299
2300 assert(image != (Image *) NULL);
2301 assert(image->signature == MagickCoreSignature);
2302 if (IsEventLogging() != MagickFalse)
2303 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2304 if ((property == (const char *) NULL) || (*property == '\0'))
2305 return((const char *) NULL);
2306 read_from_properties=MagickTrue;
2307 property_length=strlen(property);
2308 if ((property_length > 2) && (*(property+(property_length-2)) == ':') &&
2309 (*(property+(property_length-1)) == '*'))
2310 read_from_properties=MagickFalse;
2311 if (read_from_properties != MagickFalse)
2312 {
2313 p=(const char *) NULL;
2314 if (image->properties != (void *) NULL)
2315 {
2316 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2317 image->properties,property);
2318 if (p != (const char *) NULL)
2319 return(p);
2320 }
2321 if (strchr(property,':') == (char *) NULL)
2322 return(p);
2323 }
2324 switch (*property)
2325 {
2326 case '8':
2327 {
2328 if (LocaleNCompare("8bim:",property,5) == 0)
2329 {
2330 Get8BIMProperty(image,property,exception);
2331 break;
2332 }
2333 break;
2334 }
2335 case 'E':
2336 case 'e':
2337 {
2338 if (LocaleNCompare("exif:",property,5) == 0)
2339 {
2340 GetEXIFProperty(image,property,exception);
2341 break;
2342 }
2343 break;
2344 }
2345 case 'I':
2346 case 'i':
2347 {
2348 if ((LocaleNCompare("icc:",property,4) == 0) ||
2349 (LocaleNCompare("icm:",property,4) == 0))
2350 {
2351#if defined(MAGICKCORE_LCMS_DELEGATE)
2352 GetICCProperty(image,exception);
2353#endif
2354 break;
2355 }
2356 if (LocaleNCompare("iptc:",property,5) == 0)
2357 {
2358 GetIPTCProperty(image,property,exception);
2359 break;
2360 }
2361 break;
2362 }
2363 case 'X':
2364 case 'x':
2365 {
2366 if (LocaleNCompare("xmp:",property,4) == 0)
2367 {
2368 GetXMPProperty(image,property);
2369 break;
2370 }
2371 break;
2372 }
2373 default:
2374 break;
2375 }
2376 if ((image->properties != (void *) NULL) &&
2377 (read_from_properties != MagickFalse))
2378 {
2379 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2380 image->properties,property);
2381 return(p);
2382 }
2383 return((const char *) NULL);
2384}
2385␌
2386/*
2387%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2388% %
2389% %
2390% %
2391+ G e t M a g i c k P r o p e r t y %
2392% %
2393% %
2394% %
2395%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2396%
2397% GetMagickProperty() gets attributes or calculated values that is associated
2398% with a fixed known property name, or single letter property. It may be
2399% called if no image is defined (IMv7), in which case only global image_info
2400% values are available:
2401%
2402% \n newline
2403% \r carriage return
2404% < less-than character.
2405% > greater-than character.
2406% & ampersand character.
2407% %% a percent sign
2408% %b file size of image read in
2409% %c comment meta-data property
2410% %d directory component of path
2411% %e filename extension or suffix
2412% %f filename (including suffix)
2413% %g layer canvas page geometry (equivalent to "%Wx%H%X%Y")
2414% %h current image height in pixels
2415% %i image filename (note: becomes output filename for "info:")
2416% %k CALCULATED: number of unique colors
2417% %l label meta-data property
2418% %m image file format (file magic)
2419% %n number of images in current image sequence
2420% %o output filename (used for delegates)
2421% %p index of image in current image list
2422% %q quantum depth (compile-time constant)
2423% %r image class and colorspace
2424% %s scene number (from input unless re-assigned)
2425% %t filename without directory or extension (suffix)
2426% %u unique temporary filename (used for delegates)
2427% %w current width in pixels
2428% %x x resolution (density)
2429% %y y resolution (density)
2430% %z image depth (as read in unless modified, image save depth)
2431% %A image transparency channel enabled (true/false)
2432% %B file size of image in bytes
2433% %C image compression type
2434% %D image GIF dispose method
2435% %G original image size (%wx%h; before any resizes)
2436% %H page (canvas) height
2437% %M Magick filename (original file exactly as given, including read mods)
2438% %O page (canvas) offset ( = %X%Y )
2439% %P page (canvas) size ( = %Wx%H )
2440% %Q image compression quality ( 0 = default )
2441% %S ?? scenes ??
2442% %T image time delay (in centi-seconds)
2443% %U image resolution units
2444% %W page (canvas) width
2445% %X page (canvas) x offset (including sign)
2446% %Y page (canvas) y offset (including sign)
2447% %Z unique filename (used for delegates)
2448% %@ CALCULATED: trim bounding box (without actually trimming)
2449% %# CALCULATED: 'signature' hash of image values
2450%
2451% This routine only handles specifically known properties. It does not
2452% handle special prefixed properties, profiles, or expressions. Nor does
2453% it return any free-form property strings.
2454%
2455% The returned string is stored in a structure somewhere, and should not be
2456% directly freed. If the string was generated (common) the string will be
2457% stored as as either as artifact or option 'magick-property'. These may be
2458% deleted (cleaned up) when no longer required, but neither artifact or
2459% option is guaranteed to exist.
2460%
2461% The format of the GetMagickProperty method is:
2462%
2463% const char *GetMagickProperty(ImageInfo *image_info,Image *image,
2464% const char *property,ExceptionInfo *exception)
2465%
2466% A description of each parameter follows:
2467%
2468% o image_info: the image info (optional)
2469%
2470% o image: the image (optional)
2471%
2472% o key: the key.
2473%
2474% o exception: return any errors or warnings in this structure.
2475%
2476*/
2477static const char *GetMagickPropertyLetter(ImageInfo *image_info,
2478 Image *image,const char letter,ExceptionInfo *exception)
2479{
2480#define WarnNoImageReturn(format,arg) \
2481 if (image == (Image *) NULL ) { \
2482 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2483 "NoImageForProperty",format,arg); \
2484 return((const char *) NULL); \
2485 }
2486#define WarnNoImageInfoReturn(format,arg) \
2487 if (image_info == (ImageInfo *) NULL ) { \
2488 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2489 "NoImageInfoForProperty",format,arg); \
2490 return((const char *) NULL); \
2491 }
2492
2493 char
2494 value[MagickPathExtent]; /* formatted string to store as an artifact */
2495
2496 const char
2497 *string; /* return a string already stored somewhere */
2498
2499 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
2500 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2501 else
2502 if ((image_info != (ImageInfo *) NULL) &&
2503 (IsEventLogging() != MagickFalse))
2504 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2505 *value='\0'; /* formatted string */
2506 string=(char *) NULL; /* constant string reference */
2507 /*
2508 Get properties that are directly defined by images.
2509 */
2510 switch (letter)
2511 {
2512 case 'b': /* image size read in - in bytes */
2513 {
2514 WarnNoImageReturn("\"%%%c\"",letter);
2515 (void) FormatMagickSize(image->extent,MagickFalse,"B",MagickPathExtent,
2516 value);
2517 if (image->extent == 0)
2518 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
2519 MagickPathExtent,value);
2520 break;
2521 }
2522 case 'c': /* image comment property - empty string by default */
2523 {
2524 WarnNoImageReturn("\"%%%c\"",letter);
2525 string=GetImageProperty(image,"comment",exception);
2526 if ( string == (const char *) NULL )
2527 string="";
2528 break;
2529 }
2530 case 'd': /* Directory component of filename */
2531 {
2532 WarnNoImageReturn("\"%%%c\"",letter);
2533 GetPathComponent(image->magick_filename,HeadPath,value);
2534 if (*value == '\0')
2535 string="";
2536 break;
2537 }
2538 case 'e': /* Filename extension (suffix) of image file */
2539 {
2540 WarnNoImageReturn("\"%%%c\"",letter);
2541 GetPathComponent(image->magick_filename,ExtensionPath,value);
2542 if (*value == '\0')
2543 string="";
2544 break;
2545 }
2546 case 'f': /* Filename without directory component */
2547 {
2548 WarnNoImageReturn("\"%%%c\"",letter);
2549 GetPathComponent(image->magick_filename,TailPath,value);
2550 if (*value == '\0')
2551 string="";
2552 break;
2553 }
2554 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
2555 {
2556 WarnNoImageReturn("\"%%%c\"",letter);
2557 (void) FormatLocaleString(value,MagickPathExtent,
2558 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
2559 image->page.height,(double) image->page.x,(double) image->page.y);
2560 break;
2561 }
2562 case 'h': /* Image height (current) */
2563 {
2564 WarnNoImageReturn("\"%%%c\"",letter);
2565 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2566 (image->rows != 0 ? image->rows : image->magick_rows));
2567 break;
2568 }
2569 case 'i': /* Filename last used for an image (read or write) */
2570 {
2571 WarnNoImageReturn("\"%%%c\"",letter);
2572 string=image->filename;
2573 break;
2574 }
2575 case 'k': /* Number of unique colors */
2576 {
2577 /*
2578 FUTURE: ensure this does not generate the formatted comment!
2579 */
2580 WarnNoImageReturn("\"%%%c\"",letter);
2581 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2582 GetNumberColors(image,(FILE *) NULL,exception));
2583 break;
2584 }
2585 case 'l': /* Image label property - empty string by default */
2586 {
2587 WarnNoImageReturn("\"%%%c\"",letter);
2588 string=GetImageProperty(image,"label",exception);
2589 if (string == (const char *) NULL)
2590 string="";
2591 break;
2592 }
2593 case 'm': /* Image format (file magick) */
2594 {
2595 WarnNoImageReturn("\"%%%c\"",letter);
2596 string=image->magick;
2597 break;
2598 }
2599 case 'n': /* Number of images in the list. */
2600 {
2601 if ( image != (Image *) NULL )
2602 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2603 GetImageListLength(image));
2604 else
2605 string="0"; /* no images or scenes */
2606 break;
2607 }
2608 case 'o': /* Output Filename - for delegate use only */
2609 {
2610 WarnNoImageInfoReturn("\"%%%c\"",letter);
2611 string=image_info->filename;
2612 break;
2613 }
2614 case 'p': /* Image index in current image list */
2615 {
2616 WarnNoImageReturn("\"%%%c\"",letter);
2617 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2618 GetImageIndexInList(image));
2619 break;
2620 }
2621 case 'q': /* Quantum depth of image in memory */
2622 {
2623 WarnNoImageReturn("\"%%%c\"",letter);
2624 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2625 MAGICKCORE_QUANTUM_DEPTH);
2626 break;
2627 }
2628 case 'r': /* Image storage class, colorspace, and alpha enabled. */
2629 {
2630 ColorspaceType
2631 colorspace;
2632
2633 WarnNoImageReturn("\"%%%c\"",letter);
2634 colorspace=image->colorspace;
2635 (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
2636 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
2637 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
2638 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
2639 "Alpha" : "");
2640 break;
2641 }
2642 case 's': /* Image scene number */
2643 {
2644#if 0 /* this seems non-sensical -- simplifying */
2645 if (image_info->number_scenes != 0)
2646 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2647 image_info->scene);
2648 else if (image != (Image *) NULL)
2649 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2650 image->scene);
2651 else
2652 string="0";
2653#else
2654 WarnNoImageReturn("\"%%%c\"",letter);
2655 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2656 image->scene);
2657#endif
2658 break;
2659 }
2660 case 't': /* Base filename without directory or extension */
2661 {
2662 WarnNoImageReturn("\"%%%c\"",letter);
2663 GetPathComponent(image->magick_filename,BasePath,value);
2664 if (*value == '\0')
2665 string="";
2666 break;
2667 }
2668 case 'u': /* Unique filename */
2669 {
2670 WarnNoImageInfoReturn("\"%%%c\"",letter);
2671 string=image_info->unique;
2672 break;
2673 }
2674 case 'w': /* Image width (current) */
2675 {
2676 WarnNoImageReturn("\"%%%c\"",letter);
2677 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2678 (image->columns != 0 ? image->columns : image->magick_columns));
2679 break;
2680 }
2681 case 'x': /* Image horizontal resolution (with units) */
2682 {
2683 WarnNoImageReturn("\"%%%c\"",letter);
2684 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
2685 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
2686 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
2687 DefaultResolution);
2688 break;
2689 }
2690 case 'y': /* Image vertical resolution (with units) */
2691 {
2692 WarnNoImageReturn("\"%%%c\"",letter);
2693 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
2694 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
2695 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
2696 DefaultResolution);
2697 break;
2698 }
2699 case 'z': /* Image depth as read in */
2700 {
2701 WarnNoImageReturn("\"%%%c\"",letter);
2702 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2703 image->depth);
2704 break;
2705 }
2706 case 'A': /* Image alpha channel */
2707 {
2708 WarnNoImageReturn("\"%%%c\"",letter);
2709 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
2710 image->alpha_trait);
2711 break;
2712 }
2713 case 'B': /* image size read in - in bytes */
2714 {
2715 WarnNoImageReturn("\"%%%c\"",letter);
2716 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2717 image->extent);
2718 if (image->extent == 0)
2719 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2720 GetBlobSize(image));
2721 break;
2722 }
2723 case 'C': /* Image compression method. */
2724 {
2725 WarnNoImageReturn("\"%%%c\"",letter);
2726 string=CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
2727 image->compression);
2728 break;
2729 }
2730 case 'D': /* Image dispose method. */
2731 {
2732 WarnNoImageReturn("\"%%%c\"",letter);
2733 string=CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t)
2734 image->dispose);
2735 break;
2736 }
2737 case 'G': /* Image size as geometry = "%wx%h" */
2738 {
2739 WarnNoImageReturn("\"%%%c\"",letter);
2740 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",(double)
2741 image->magick_columns,(double) image->magick_rows);
2742 break;
2743 }
2744 case 'H': /* layer canvas height */
2745 {
2746 WarnNoImageReturn("\"%%%c\"",letter);
2747 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2748 image->page.height);
2749 break;
2750 }
2751 case 'M': /* Magick filename - filename given incl. coder & read mods */
2752 {
2753 WarnNoImageReturn("\"%%%c\"",letter);
2754 string=image->magick_filename;
2755 break;
2756 }
2757 case 'N': /* Number of images in the list. */
2758 {
2759 if ((image != (Image *) NULL) && (image->next == (Image *) NULL))
2760 (void) FormatLocaleString(value,MagickPathExtent,"%.20g\n",(double)
2761 GetImageListLength(image));
2762 else
2763 string="";
2764 break;
2765 }
2766 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2767 {
2768 WarnNoImageReturn("\"%%%c\"",letter);
2769 (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
2770 image->page.x,(long) image->page.y);
2771 break;
2772 }
2773 case 'P': /* layer canvas page size = "%Wx%H" */
2774 {
2775 WarnNoImageReturn("\"%%%c\"",letter);
2776 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",(double)
2777 image->page.width,(double) image->page.height);
2778 break;
2779 }
2780 case 'Q': /* image compression quality */
2781 {
2782 WarnNoImageReturn("\"%%%c\"",letter);
2783 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2784 (image->quality == 0 ? 92 : image->quality));
2785 break;
2786 }
2787 case 'S': /* Number of scenes in image list. */
2788 {
2789 WarnNoImageInfoReturn("\"%%%c\"",letter);
2790#if 0 /* What is this number? -- it makes no sense - simplifying */
2791 if (image_info->number_scenes == 0)
2792 string="2147483647";
2793 else if ( image != (Image *) NULL )
2794 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2795 image_info->scene+image_info->number_scenes);
2796 else
2797 string="0";
2798#else
2799 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2800 (image_info->number_scenes == 0 ? 2147483647 :
2801 image_info->number_scenes));
2802#endif
2803 break;
2804 }
2805 case 'T': /* image time delay for animations */
2806 {
2807 WarnNoImageReturn("\"%%%c\"",letter);
2808 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2809 image->delay);
2810 break;
2811 }
2812 case 'U': /* Image resolution units. */
2813 {
2814 WarnNoImageReturn("\"%%%c\"",letter);
2815 string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2816 image->units);
2817 break;
2818 }
2819 case 'W': /* layer canvas width */
2820 {
2821 WarnNoImageReturn("\"%%%c\"",letter);
2822 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2823 image->page.width);
2824 break;
2825 }
2826 case 'X': /* layer canvas X offset */
2827 {
2828 WarnNoImageReturn("\"%%%c\"",letter);
2829 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
2830 image->page.x);
2831 break;
2832 }
2833 case 'Y': /* layer canvas Y offset */
2834 {
2835 WarnNoImageReturn("\"%%%c\"",letter);
2836 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
2837 image->page.y);
2838 break;
2839 }
2840 case '%': /* percent escaped */
2841 {
2842 string="%";
2843 break;
2844 }
2845 case '@': /* Trim bounding box, without actually Trimming! */
2846 {
2847 RectangleInfo
2848 page;
2849
2850 WarnNoImageReturn("\"%%%c\"",letter);
2851 page=GetImageBoundingBox(image,exception);
2852 (void) FormatLocaleString(value,MagickPathExtent,
2853 "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
2854 (double) page.x,(double)page.y);
2855 break;
2856 }
2857 case '#':
2858 {
2859 /*
2860 Image signature.
2861 */
2862 WarnNoImageReturn("\"%%%c\"",letter);
2863 if ((image->columns != 0) && (image->rows != 0))
2864 (void) SignatureImage(image,exception);
2865 string=GetImageProperty(image,"signature",exception);
2866 break;
2867 }
2868 }
2869 if (string != (char *) NULL)
2870 return(string);
2871 if (*value != '\0')
2872 {
2873 /*
2874 Create a cloned copy of result.
2875 */
2876 if (image != (Image *) NULL)
2877 {
2878 (void) SetImageArtifact(image,"magick-property",value);
2879 return(GetImageArtifact(image,"magick-property"));
2880 }
2881 else
2882 {
2883 (void) SetImageOption(image_info,"magick-property",value);
2884 return(GetImageOption(image_info,"magick-property"));
2885 }
2886 }
2887 return((char *) NULL);
2888}
2889
2890MagickExport const char *GetMagickProperty(ImageInfo *image_info,
2891 Image *image,const char *property,ExceptionInfo *exception)
2892{
2893 char
2894 value[MagickPathExtent];
2895
2896 const char
2897 *string;
2898
2899 assert(property != (const char *) NULL);
2900 assert(property[0] != '\0');
2901 assert(image != (Image *) NULL || image_info != (ImageInfo *) NULL );
2902 if (property[1] == '\0') /* single letter property request */
2903 return(GetMagickPropertyLetter(image_info,image,*property,exception));
2904 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
2905 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2906 else
2907 if ((image_info != (ImageInfo *) NULL) &&
2908 (IsEventLogging() != MagickFalse))
2909 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2910 *value='\0'; /* formated string */
2911 string=(char *) NULL; /* constant string reference */
2912 switch (*property)
2913 {
2914 case 'b':
2915 {
2916 if (LocaleCompare("basename",property) == 0)
2917 {
2918 WarnNoImageReturn("\"%%[%s]\"",property);
2919 GetPathComponent(image->magick_filename,BasePath,value);
2920 if (*value == '\0')
2921 string="";
2922 break;
2923 }
2924 if (LocaleCompare("bit-depth",property) == 0)
2925 {
2926 WarnNoImageReturn("\"%%[%s]\"",property);
2927 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2928 GetImageDepth(image,exception));
2929 break;
2930 }
2931 if (LocaleCompare("bounding-box",property) == 0)
2932 {
2933 RectangleInfo
2934 geometry;
2935
2936 WarnNoImageReturn("\"%%[%s]\"",property);
2937 geometry=GetImageBoundingBox(image,exception);
2938 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g %g,%g",
2939 (double) geometry.x,(double) geometry.y,
2940 (double) geometry.x+geometry.width,
2941 (double) geometry.y+geometry.height);
2942 break;
2943 }
2944 break;
2945 }
2946 case 'c':
2947 {
2948 if (LocaleCompare("channels",property) == 0)
2949 {
2950 WarnNoImageReturn("\"%%[%s]\"",property);
2951 (void) FormatLocaleString(value,MagickPathExtent,"%s%s %g.%g",
2952 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2953 image->colorspace),image->alpha_trait != UndefinedPixelTrait ?
2954 "a" : " ",(double) image->number_channels,(double)
2955 image->number_meta_channels);
2956 LocaleLower(value);
2957 break;
2958 }
2959 if (LocaleCompare("colors",property) == 0)
2960 {
2961 WarnNoImageReturn("\"%%[%s]\"",property);
2962 image->colors=GetNumberColors(image,(FILE *) NULL,exception);
2963 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2964 image->colors);
2965 break;
2966 }
2967 if (LocaleCompare("colorspace",property) == 0)
2968 {
2969 WarnNoImageReturn("\"%%[%s]\"",property);
2970 string=CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2971 image->colorspace);
2972 break;
2973 }
2974 if (LocaleCompare("compose",property) == 0)
2975 {
2976 WarnNoImageReturn("\"%%[%s]\"",property);
2977 string=CommandOptionToMnemonic(MagickComposeOptions,(ssize_t)
2978 image->compose);
2979 break;
2980 }
2981 if (LocaleCompare("compression",property) == 0)
2982 {
2983 WarnNoImageReturn("\"%%[%s]\"",property);
2984 string=CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
2985 image->compression);
2986 break;
2987 }
2988 if (LocaleCompare("convex-hull",property) == 0)
2989 {
2990 char
2991 *points;
2992
2993 PointInfo
2994 *convex_hull;
2995
2996 ssize_t
2997 n;
2998
2999 size_t
3000 number_points;
3001
3002 WarnNoImageReturn("\"%%[%s]\"",property);
3003 convex_hull=GetImageConvexHull(image,&number_points,exception);
3004 if (convex_hull == (PointInfo *) NULL)
3005 break;
3006 points=AcquireString("");
3007 for (n=0; n < (ssize_t) number_points; n++)
3008 {
3009 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g ",
3010 convex_hull[n].x,convex_hull[n].y);
3011 (void) ConcatenateString(&points,value);
3012 }
3013 convex_hull=(PointInfo *) RelinquishMagickMemory(convex_hull);
3014 (void) SetImageProperty(image,"convex-hull",points,exception);
3015 points=DestroyString(points);
3016 string=GetImageProperty(image,"convex-hull",exception);
3017 break;
3018 }
3019 if (LocaleCompare("convex-hull:extreme-points",property) == 0)
3020 {
3021 char
3022 *points;
3023
3024 PointInfo
3025 extreme,
3026 *convex_hull;
3027
3028 ssize_t
3029 n;
3030
3031 size_t
3032 number_points;
3033
3034 WarnNoImageReturn("\"%%[%s]\"",property);
3035 convex_hull=GetImageConvexHull(image,&number_points,exception);
3036 if (convex_hull == (PointInfo *) NULL)
3037 break;
3038 points=AcquireString("");
3039 extreme=convex_hull[0]; /* top */
3040 for (n=0; n < (ssize_t) number_points; n++)
3041 {
3042 if (convex_hull[n].y < extreme.y)
3043 {
3044 extreme=convex_hull[n];
3045 continue;
3046 }
3047 if (convex_hull[n].y != extreme.y)
3048 continue;
3049 if (convex_hull[n].x < extreme.x)
3050 extreme=convex_hull[n];
3051 }
3052 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g ",
3053 extreme.x,extreme.y);
3054 (void) ConcatenateString(&points,value);
3055 extreme=convex_hull[0]; /* right */
3056 for (n=0; n < (ssize_t) number_points; n++)
3057 {
3058 if (convex_hull[n].x > extreme.x)
3059 {
3060 extreme=convex_hull[n];
3061 continue;
3062 }
3063 if (convex_hull[n].x != extreme.x)
3064 continue;
3065 if (convex_hull[n].y < extreme.y)
3066 extreme=convex_hull[n];
3067 }
3068 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g ",
3069 extreme.x,extreme.y);
3070 (void) ConcatenateString(&points,value);
3071 extreme=convex_hull[0]; /* bottom */
3072 for (n=0; n < (ssize_t) number_points; n++)
3073 {
3074 if (convex_hull[n].y > extreme.y)
3075 {
3076 extreme=convex_hull[n];
3077 continue;
3078 }
3079 if (convex_hull[n].y != extreme.y)
3080 continue;
3081 if (convex_hull[n].x > extreme.x)
3082 extreme=convex_hull[n];
3083 }
3084 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g ",
3085 extreme.x,extreme.y);
3086 (void) ConcatenateString(&points,value);
3087 extreme=convex_hull[0]; /* left */
3088 for (n=0; n < (ssize_t) number_points; n++)
3089 {
3090 if (convex_hull[n].x < extreme.x)
3091 {
3092 extreme=convex_hull[n];
3093 continue;
3094 }
3095 if (convex_hull[n].x != extreme.x)
3096 continue;
3097 if (convex_hull[n].y > extreme.y)
3098 extreme=convex_hull[n];
3099 }
3100 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g ",
3101 extreme.x,extreme.y);
3102 (void) ConcatenateString(&points,value);
3103 convex_hull=(PointInfo *) RelinquishMagickMemory(convex_hull);
3104 (void) SetImageProperty(image,"convex-hull:extreme-points",points,
3105 exception);
3106 points=DestroyString(points);
3107 string=GetImageProperty(image,"convex-hull:extreme-points",exception);
3108 break;
3109 }
3110 if (LocaleCompare("copyright",property) == 0)
3111 {
3112 (void) CopyMagickString(value,GetMagickCopyright(),MagickPathExtent);
3113 break;
3114 }
3115 break;
3116 }
3117 case 'd':
3118 {
3119 if (LocaleCompare("depth",property) == 0)
3120 {
3121 WarnNoImageReturn("\"%%[%s]\"",property);
3122 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3123 image->depth);
3124 break;
3125 }
3126 if (LocaleCompare("directory",property) == 0)
3127 {
3128 WarnNoImageReturn("\"%%[%s]\"",property);
3129 GetPathComponent(image->magick_filename,HeadPath,value);
3130 if (*value == '\0')
3131 string="";
3132 break;
3133 }
3134 break;
3135 }
3136 case 'e':
3137 {
3138 if (LocaleCompare("entropy",property) == 0)
3139 {
3140 double
3141 entropy;
3142
3143 WarnNoImageReturn("\"%%[%s]\"",property);
3144 (void) GetImageEntropy(image,&entropy,exception);
3145 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3146 GetMagickPrecision(),entropy);
3147 break;
3148 }
3149 if (LocaleCompare("extension",property) == 0)
3150 {
3151 WarnNoImageReturn("\"%%[%s]\"",property);
3152 GetPathComponent(image->magick_filename,ExtensionPath,value);
3153 if (*value == '\0')
3154 string="";
3155 break;
3156 }
3157 break;
3158 }
3159 case 'g':
3160 {
3161 if (LocaleCompare("gamma",property) == 0)
3162 {
3163 WarnNoImageReturn("\"%%[%s]\"",property);
3164 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3165 GetMagickPrecision(),image->gamma);
3166 break;
3167 }
3168 break;
3169 }
3170 case 'h':
3171 {
3172 if (LocaleCompare("height",property) == 0)
3173 {
3174 WarnNoImageReturn("\"%%[%s]\"",property);
3175 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
3176 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
3177 break;
3178 }
3179 break;
3180 }
3181 case 'i':
3182 {
3183 if (LocaleCompare("input",property) == 0)
3184 {
3185 WarnNoImageReturn("\"%%[%s]\"",property);
3186 string=image->filename;
3187 break;
3188 }
3189 if (LocaleCompare("interlace",property) == 0)
3190 {
3191 WarnNoImageReturn("\"%%[%s]\"",property);
3192 string=CommandOptionToMnemonic(MagickInterlaceOptions,(ssize_t)
3193 image->interlace);
3194 break;
3195 }
3196 break;
3197 }
3198 case 'k':
3199 {
3200 if (LocaleCompare("kurtosis",property) == 0)
3201 {
3202 double
3203 kurtosis,
3204 skewness;
3205
3206 WarnNoImageReturn("\"%%[%s]\"",property);
3207 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
3208 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3209 GetMagickPrecision(),kurtosis);
3210 break;
3211 }
3212 break;
3213 }
3214 case 'm':
3215 {
3216 if (LocaleCompare("magick",property) == 0)
3217 {
3218 WarnNoImageReturn("\"%%[%s]\"",property);
3219 string=image->magick;
3220 break;
3221 }
3222 if ((LocaleCompare("maxima",property) == 0) ||
3223 (LocaleCompare("max",property) == 0))
3224 {
3225 double
3226 maximum,
3227 minimum;
3228
3229 WarnNoImageReturn("\"%%[%s]\"",property);
3230 (void) GetImageRange(image,&minimum,&maximum,exception);
3231 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3232 GetMagickPrecision(),maximum);
3233 break;
3234 }
3235 if (LocaleCompare("mean",property) == 0)
3236 {
3237 double
3238 mean,
3239 standard_deviation;
3240
3241 WarnNoImageReturn("\"%%[%s]\"",property);
3242 (void) GetImageMean(image,&mean,&standard_deviation,exception);
3243 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3244 GetMagickPrecision(),mean);
3245 break;
3246 }
3247 if (LocaleCompare("median",property) == 0)
3248 {
3249 double
3250 median;
3251
3252 WarnNoImageReturn("\"%%[%s]\"",property);
3253 (void) GetImageMedian(image,&median,exception);
3254 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3255 GetMagickPrecision(),median);
3256 break;
3257 }
3258 if (LocaleCompare("mime:type",property) == 0)
3259 {
3260 const MagickInfo
3261 *magick_info;
3262
3263 magick_info=GetMagickInfo(image->magick,exception);
3264 if ((magick_info != (const MagickInfo *) NULL) &&
3265 (GetMagickMimeType(magick_info) != (const char *) NULL))
3266 (void) CopyMagickString(value,GetMagickMimeType(magick_info),
3267 MagickPathExtent);
3268 break;
3269 }
3270 if ((LocaleCompare("minima",property) == 0) ||
3271 (LocaleCompare("min",property) == 0))
3272 {
3273 double
3274 maximum,
3275 minimum;
3276
3277 WarnNoImageReturn("\"%%[%s]\"",property);
3278 (void) GetImageRange(image,&minimum,&maximum,exception);
3279 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3280 GetMagickPrecision(),minimum);
3281 break;
3282 }
3283 if (LocaleNCompare("minimum-bounding-box",property,20) == 0)
3284 {
3285 char
3286 *points;
3287
3288 PointInfo
3289 *bounding_box;
3290
3291 ssize_t
3292 n;
3293
3294 size_t
3295 number_points;
3296
3297 WarnNoImageReturn("\"%%[%s]\"",property);
3298 bounding_box=GetImageMinimumBoundingBox(image,&number_points,
3299 exception);
3300 if (bounding_box == (PointInfo *) NULL)
3301 break;
3302 points=AcquireString("");
3303 for (n=0; n < (ssize_t) number_points; n++)
3304 {
3305 (void) FormatLocaleString(value,MagickPathExtent,"%g,%g ",
3306 bounding_box[n].x,bounding_box[n].y);
3307 (void) ConcatenateString(&points,value);
3308 }
3309 bounding_box=(PointInfo *) RelinquishMagickMemory(bounding_box);
3310 (void) SetImageProperty(image,"minimum-bounding-box",points,
3311 exception);
3312 points=DestroyString(points);
3313 string=GetImageProperty(image,property,exception);
3314 break;
3315 }
3316 break;
3317 }
3318 case 'o':
3319 {
3320 if (LocaleCompare("opaque",property) == 0)
3321 {
3322 WarnNoImageReturn("\"%%[%s]\"",property);
3323 string=CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t)
3324 IsImageOpaque(image,exception));
3325 break;
3326 }
3327 if (LocaleCompare("orientation",property) == 0)
3328 {
3329 WarnNoImageReturn("\"%%[%s]\"",property);
3330 string=CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
3331 image->orientation);
3332 break;
3333 }
3334 if (LocaleCompare("output",property) == 0)
3335 {
3336 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3337 (void) CopyMagickString(value,image_info->filename,MagickPathExtent);
3338 break;
3339 }
3340 break;
3341 }
3342 case 'p':
3343 {
3344 if (LocaleCompare("page",property) == 0)
3345 {
3346 WarnNoImageReturn("\"%%[%s]\"",property);
3347 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
3348 (double) image->page.width,(double) image->page.height);
3349 break;
3350 }
3351 if (LocaleNCompare("papersize:",property,10) == 0)
3352 {
3353 char
3354 *papersize;
3355
3356 WarnNoImageReturn("\"%%[%s]\"",property);
3357 *value='\0';
3358 papersize=GetPageGeometry(property+10);
3359 if (papersize != (const char *) NULL)
3360 {
3361 RectangleInfo
3362 page = { 0, 0, 0, 0 };
3363
3364 (void) ParseAbsoluteGeometry(papersize,&page);
3365 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
3366 (double) page.width,(double) page.height);
3367 papersize=DestroyString(papersize);
3368 }
3369 break;
3370 }
3371#if defined(MAGICKCORE_LCMS_DELEGATE)
3372 if (LocaleCompare("profile:icc",property) == 0 ||
3373 LocaleCompare("profile:icm",property) == 0)
3374 {
3375#if !defined(LCMS_VERSION) || (LCMS_VERSION < 2000)
3376#define cmsUInt32Number DWORD
3377#endif
3378
3379 const StringInfo
3380 *profile;
3381
3382 cmsHPROFILE
3383 icc_profile;
3384
3385 WarnNoImageReturn("\"%%[%s]\"",property);
3386 profile=GetImageProfile(image,property+8);
3387 if (profile == (StringInfo *) NULL)
3388 break;
3389 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
3390 (cmsUInt32Number) GetStringInfoLength(profile));
3391 if (icc_profile != (cmsHPROFILE *) NULL)
3392 {
3393#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
3394 string=cmsTakeProductName(icc_profile);
3395#else
3396 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
3397 "en","US",value,MagickPathExtent);
3398#endif
3399 (void) cmsCloseProfile(icc_profile);
3400 }
3401 }
3402#endif
3403 if (LocaleCompare("printsize.x",property) == 0)
3404 {
3405 WarnNoImageReturn("\"%%[%s]\"",property);
3406 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3407 GetMagickPrecision(),(double) MagickSafeReciprocal(
3408 image->resolution.x)*image->columns);
3409 break;
3410 }
3411 if (LocaleCompare("printsize.y",property) == 0)
3412 {
3413 WarnNoImageReturn("\"%%[%s]\"",property);
3414 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3415 GetMagickPrecision(),(double) MagickSafeReciprocal(
3416 image->resolution.y)*image->rows);
3417 break;
3418 }
3419 if (LocaleCompare("profiles",property) == 0)
3420 {
3421 const char
3422 *name;
3423
3424 WarnNoImageReturn("\"%%[%s]\"",property);
3425 ResetImageProfileIterator(image);
3426 name=GetNextImageProfile(image);
3427 if (name != (char *) NULL)
3428 {
3429 (void) CopyMagickString(value,name,MagickPathExtent);
3430 name=GetNextImageProfile(image);
3431 while (name != (char *) NULL)
3432 {
3433 ConcatenateMagickString(value,",",MagickPathExtent);
3434 ConcatenateMagickString(value,name,MagickPathExtent);
3435 name=GetNextImageProfile(image);
3436 }
3437 }
3438 break;
3439 }
3440 break;
3441 }
3442 case 'q':
3443 {
3444 if (LocaleCompare("quality",property) == 0)
3445 {
3446 WarnNoImageReturn("\"%%[%s]\"",property);
3447 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3448 image->quality);
3449 break;
3450 }
3451 break;
3452 }
3453 case 'r':
3454 {
3455 if (LocaleCompare("resolution.x",property) == 0)
3456 {
3457 WarnNoImageReturn("\"%%[%s]\"",property);
3458 (void) FormatLocaleString(value,MagickPathExtent,"%g",
3459 image->resolution.x);
3460 break;
3461 }
3462 if (LocaleCompare("resolution.y",property) == 0)
3463 {
3464 WarnNoImageReturn("\"%%[%s]\"",property);
3465 (void) FormatLocaleString(value,MagickPathExtent,"%g",
3466 image->resolution.y);
3467 break;
3468 }
3469 break;
3470 }
3471 case 's':
3472 {
3473 if (LocaleCompare("scene",property) == 0)
3474 {
3475 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3476 if (image_info->number_scenes != 0)
3477 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3478 image_info->scene);
3479 else {
3480 WarnNoImageReturn("\"%%[%s]\"",property);
3481 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3482 image->scene);
3483 }
3484 break;
3485 }
3486 if (LocaleCompare("scenes",property) == 0)
3487 {
3488 /* FUTURE: equivalent to %n? */
3489 WarnNoImageReturn("\"%%[%s]\"",property);
3490 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3491 GetImageListLength(image));
3492 break;
3493 }
3494 if (LocaleCompare("size",property) == 0)
3495 {
3496 WarnNoImageReturn("\"%%[%s]\"",property);
3497 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
3498 MagickPathExtent,value);
3499 break;
3500 }
3501 if (LocaleCompare("skewness",property) == 0)
3502 {
3503 double
3504 kurtosis,
3505 skewness;
3506
3507 WarnNoImageReturn("\"%%[%s]\"",property);
3508 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
3509 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3510 GetMagickPrecision(),skewness);
3511 break;
3512 }
3513 if (LocaleCompare("standard-deviation",property) == 0)
3514 {
3515 double
3516 mean,
3517 standard_deviation;
3518
3519 WarnNoImageReturn("\"%%[%s]\"",property);
3520 (void) GetImageMean(image,&mean,&standard_deviation,exception);
3521 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3522 GetMagickPrecision(),standard_deviation);
3523 break;
3524 }
3525 break;
3526 }
3527 case 't':
3528 {
3529 if (LocaleCompare("type",property) == 0)
3530 {
3531 WarnNoImageReturn("\"%%[%s]\"",property);
3532 string=CommandOptionToMnemonic(MagickTypeOptions,(ssize_t)
3533 IdentifyImageType(image,exception));
3534 break;
3535 }
3536 break;
3537 }
3538 case 'u':
3539 {
3540 if (LocaleCompare("unique",property) == 0)
3541 {
3542 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3543 string=image_info->unique;
3544 break;
3545 }
3546 if (LocaleCompare("units",property) == 0)
3547 {
3548 WarnNoImageReturn("\"%%[%s]\"",property);
3549 string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
3550 image->units);
3551 break;
3552 }
3553 break;
3554 }
3555 case 'v':
3556 {
3557 if (LocaleCompare("version",property) == 0)
3558 {
3559 string=GetMagickVersion((size_t *) NULL);
3560 break;
3561 }
3562 break;
3563 }
3564 case 'w':
3565 {
3566 if (LocaleCompare("width",property) == 0)
3567 {
3568 WarnNoImageReturn("\"%%[%s]\"",property);
3569 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3570 (image->magick_columns != 0 ? image->magick_columns : 256));
3571 break;
3572 }
3573 break;
3574 }
3575 }
3576 if (string != (char *) NULL)
3577 return(string);
3578 if (*value != '\0')
3579 {
3580 /*
3581 Create a cloned copy of result, that will get cleaned up, eventually.
3582 */
3583 if (image != (Image *) NULL)
3584 {
3585 (void) SetImageArtifact(image,"magick-property",value);
3586 return(GetImageArtifact(image,"magick-property"));
3587 }
3588 else
3589 {
3590 (void) SetImageOption(image_info,"magick-property",value);
3591 return(GetImageOption(image_info,"magick-property"));
3592 }
3593 }
3594 return((char *) NULL);
3595}
3596#undef WarnNoImageReturn
3597␌
3598/*
3599%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3600% %
3601% %
3602% %
3603% G e t N e x t I m a g e P r o p e r t y %
3604% %
3605% %
3606% %
3607%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3608%
3609% GetNextImageProperty() gets the next free-form string property name.
3610%
3611% The format of the GetNextImageProperty method is:
3612%
3613% char *GetNextImageProperty(const Image *image)
3614%
3615% A description of each parameter follows:
3616%
3617% o image: the image.
3618%
3619*/
3620MagickExport const char *GetNextImageProperty(const Image *image)
3621{
3622 assert(image != (Image *) NULL);
3623 assert(image->signature == MagickCoreSignature);
3624 if (IsEventLogging() != MagickFalse)
3625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3626 image->filename);
3627 if (image->properties == (void *) NULL)
3628 return((const char *) NULL);
3629 return((const char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
3630}
3631␌
3632/*
3633%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3634% %
3635% %
3636% %
3637% I n t e r p r e t I m a g e P r o p e r t i e s %
3638% %
3639% %
3640% %
3641%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3642%
3643% InterpretImageProperties() replaces any embedded formatting characters with
3644% the appropriate image property and returns the interpreted text.
3645%
3646% This searches for and replaces
3647% \n \r \% replaced by newline, return, and percent resp.
3648% &lt; &gt; &amp; replaced by '<', '>', '&' resp.
3649% %% replaced by percent
3650%
3651% %x %[x] where 'x' is a single letter prosperity, case sensitive).
3652% %[type:name] where 'type' a is special and known prefix.
3653% %[name] where 'name' is a specifically known attribute, calculated
3654% value, or a per-image property string name, or a per-image
3655% 'artifact' (as generated from a global option).
3656% It may contain ':' as long as the prefix is not special.
3657%
3658% Single letter % substitutions will only happen if the character before the
3659% percent is NOT a number. But braced substitutions will always be performed.
3660% This prevents the typical usage of percent in a interpreted geometry
3661% argument from being substituted when the percent is a geometry flag.
3662%
3663% If 'glob-expressions' ('*' or '?' characters) is used for 'name' it may be
3664% used as a search pattern to print multiple lines of "name=value\n" pairs of
3665% the associated set of properties.
3666%
3667% The returned string must be freed using DestroyString() by the caller.
3668%
3669% The format of the InterpretImageProperties method is:
3670%
3671% char *InterpretImageProperties(ImageInfo *image_info,
3672% Image *image,const char *embed_text,ExceptionInfo *exception)
3673%
3674% A description of each parameter follows:
3675%
3676% o image_info: the image info. (required)
3677%
3678% o image: the image. (optional)
3679%
3680% o embed_text: the address of a character string containing the embedded
3681% formatting characters.
3682%
3683% o exception: return any errors or warnings in this structure.
3684%
3685*/
3686MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
3687 const char *embed_text,ExceptionInfo *exception)
3688{
3689#define ExtendInterpretText(string_length) \
3690{ \
3691 size_t length=(string_length); \
3692 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
3693 { \
3694 extent+=length; \
3695 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
3696 MagickPathExtent,sizeof(*interpret_text)); \
3697 if (interpret_text == (char *) NULL) \
3698 { \
3699 if (property_image != image) \
3700 property_image=DestroyImage(property_image); \
3701 if (property_info != image_info) \
3702 property_info=DestroyImageInfo(property_info); \
3703 return((char *) NULL); \
3704 } \
3705 q=interpret_text+strlen(interpret_text); \
3706 } \
3707}
3708
3709#define AppendKeyValue2Text(key,value)\
3710{ \
3711 size_t length=strlen(key)+strlen(value)+2; \
3712 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
3713 { \
3714 extent+=length; \
3715 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
3716 MagickPathExtent,sizeof(*interpret_text)); \
3717 if (interpret_text == (char *) NULL) \
3718 { \
3719 if (property_image != image) \
3720 property_image=DestroyImage(property_image); \
3721 if (property_info != image_info) \
3722 property_info=DestroyImageInfo(property_info); \
3723 return((char *) NULL); \
3724 } \
3725 q=interpret_text+strlen(interpret_text); \
3726 } \
3727 q+=(ptrdiff_t) FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
3728}
3729
3730#define AppendString2Text(string) \
3731{ \
3732 size_t length = strlen((string)); \
3733 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
3734 { \
3735 extent+=length; \
3736 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
3737 MagickPathExtent,sizeof(*interpret_text)); \
3738 if (interpret_text == (char *) NULL) \
3739 { \
3740 if (property_image != image) \
3741 property_image=DestroyImage(property_image); \
3742 if (property_info != image_info) \
3743 property_info=DestroyImageInfo(property_info); \
3744 return((char *) NULL); \
3745 } \
3746 q=interpret_text+strlen(interpret_text); \
3747 } \
3748 (void) CopyMagickString(q,(string),extent); \
3749 q+=(ptrdiff_t) length; \
3750}
3751
3752 char
3753 *interpret_text,
3754 *q; /* current position in interpret_text */
3755
3756 const char
3757 *p; /* position in embed_text string being expanded */
3758
3759 Image
3760 *property_image;
3761
3762 ImageInfo
3763 *property_info;
3764
3765 MagickBooleanType
3766 number;
3767
3768 size_t
3769 extent; /* allocated length of interpret_text */
3770
3771 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
3772 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3773 else
3774 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
3775 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3776 image_info->filename);
3777 else
3778 if (IsEventLogging() != MagickFalse)
3779 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no image");
3780 if (embed_text == (const char *) NULL)
3781 return(ConstantString(""));
3782 p=embed_text;
3783 while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
3784 p++;
3785 if (*p == '\0')
3786 return(ConstantString(""));
3787 if ((*p == '@') && (IsPathAccessible(p+1) != MagickFalse))
3788 {
3789 /*
3790 Handle a '@' replace string from file.
3791 */
3792 interpret_text=FileToString(p,~0UL,exception);
3793 if (interpret_text != (char *) NULL)
3794 return(interpret_text);
3795 }
3796 /*
3797 Translate any embedded format characters.
3798 */
3799 if (image_info != (ImageInfo *) NULL)
3800 property_info=image_info;
3801 else
3802 property_info=CloneImageInfo(image_info);
3803 if ((image != (Image *) NULL) && (image->columns != 0) && (image->rows != 0))
3804 property_image=image;
3805 else
3806 {
3807 property_image=AcquireImage(image_info,exception);
3808 (void) SetImageExtent(property_image,1,1,exception);
3809 (void) SetImageBackgroundColor(property_image,exception);
3810 }
3811 interpret_text=AcquireString(embed_text); /* new string with extra space */
3812 extent=MagickPathExtent; /* allocated space in string */
3813 number=MagickFalse; /* is last char a number? */
3814 for (q=interpret_text; *p!='\0'; number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
3815 {
3816 /*
3817 Look for the various escapes, (and handle other specials)
3818 */
3819 *q='\0';
3820 ExtendInterpretText(MagickPathExtent);
3821 switch (*p)
3822 {
3823 case '\\':
3824 {
3825 switch (*(p+1))
3826 {
3827 case '\0':
3828 continue;
3829 case 'r': /* convert to RETURN */
3830 {
3831 *q++='\r';
3832 p++;
3833 continue;
3834 }
3835 case 'n': /* convert to NEWLINE */
3836 {
3837 *q++='\n';
3838 p++;
3839 continue;
3840 }
3841 case '\n': /* EOL removal UNIX,MacOSX */
3842 {
3843 p++;
3844 continue;
3845 }
3846 case '\r': /* EOL removal DOS,Windows */
3847 {
3848 p++;
3849 if (*p == '\n') /* return-newline EOL */
3850 p++;
3851 continue;
3852 }
3853 default:
3854 {
3855 p++;
3856 *q++=(*p);
3857 }
3858 }
3859 continue;
3860 }
3861 case '&':
3862 {
3863 if (LocaleNCompare("&lt;",p,4) == 0)
3864 {
3865 *q++='<';
3866 p+=(ptrdiff_t) 3;
3867 }
3868 else
3869 if (LocaleNCompare("&gt;",p,4) == 0)
3870 {
3871 *q++='>';
3872 p+=(ptrdiff_t) 3;
3873 }
3874 else
3875 if (LocaleNCompare("&amp;",p,5) == 0)
3876 {
3877 *q++='&';
3878 p+=(ptrdiff_t) 4;
3879 }
3880 else
3881 *q++=(*p);
3882 continue;
3883 }
3884 case '%':
3885 break; /* continue to next set of handlers */
3886 default:
3887 {
3888 *q++=(*p); /* any thing else is 'as normal' */
3889 continue;
3890 }
3891 }
3892 p++; /* advance beyond the percent */
3893 /*
3894 Doubled Percent - or percent at end of string.
3895 */
3896 if ((*p == '\0') || (*p == '\'') || (*p == '"'))
3897 p--;
3898 if (*p == '%')
3899 {
3900 *q++='%';
3901 continue;
3902 }
3903 /*
3904 Single letter escapes %c.
3905 */
3906 if (*p != '[')
3907 {
3908 const char
3909 *string;
3910
3911 if (number != MagickFalse)
3912 {
3913 /*
3914 But only if not preceded by a number!
3915 */
3916 *q++='%'; /* do NOT substitute the percent */
3917 p--; /* back up one */
3918 continue;
3919 }
3920 string=GetMagickPropertyLetter(property_info,image,*p,exception);
3921 if (string != (char *) NULL)
3922 {
3923 AppendString2Text(string);
3924 (void) DeleteImageArtifact(property_image,"magick-property");
3925 (void) DeleteImageOption(property_info,"magick-property");
3926 continue;
3927 }
3928 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3929 "UnknownImageProperty","\"%%%c\"",*p);
3930 continue;
3931 }
3932 {
3933 char
3934 pattern[2*MagickPathExtent] = "\0";
3935
3936 const char
3937 *key,
3938 *string;
3939
3940 ssize_t
3941 len;
3942
3943 ssize_t
3944 depth;
3945
3946 /*
3947 Braced Percent Escape %[...].
3948 */
3949 p++; /* advance p to just inside the opening brace */
3950 depth=1;
3951 if (*p == ']')
3952 {
3953 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3954 "UnknownImageProperty","\"%%[]\"");
3955 break;
3956 }
3957 for (len=0; len < (MagickPathExtent-1L) && (*p != '\0'); )
3958 {
3959 if ((*p == '\\') && (*(p+1) != '\0'))
3960 {
3961 /*
3962 Skip escaped braces within braced pattern.
3963 */
3964 pattern[len++]=(*p++);
3965 pattern[len++]=(*p++);
3966 continue;
3967 }
3968 if (*p == '[')
3969 depth++;
3970 if (*p == ']')
3971 depth--;
3972 if (depth <= 0)
3973 break;
3974 pattern[len++]=(*p++);
3975 }
3976 pattern[len]='\0';
3977 if (depth != 0)
3978 {
3979 /*
3980 Check for unmatched final ']' for "%[...]".
3981 */
3982 if (len >= 64)
3983 {
3984 pattern[61] = '.'; /* truncate string for error message */
3985 pattern[62] = '.';
3986 pattern[63] = '.';
3987 pattern[64] = '\0';
3988 }
3989 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3990 "UnbalancedBraces","\"%%[%s\"",pattern);
3991 interpret_text=DestroyString(interpret_text);
3992 if (property_image != image)
3993 property_image=DestroyImage(property_image);
3994 if (property_info != image_info)
3995 property_info=DestroyImageInfo(property_info);
3996 return((char *) NULL);
3997 }
3998 /*
3999 Special Lookup Prefixes %[prefix:...].
4000 */
4001 if (LocaleNCompare("fx:",pattern,3) == 0)
4002 {
4003 double
4004 value;
4005
4006 FxInfo
4007 *fx_info;
4008
4009 MagickBooleanType
4010 status;
4011
4012 /*
4013 FX - value calculator.
4014 */
4015 fx_info=AcquireFxInfo(property_image,pattern+3,exception);
4016 if (fx_info == (FxInfo *) NULL)
4017 continue;
4018 status=FxEvaluateChannelExpression(fx_info,CompositePixelChannel,0,0,
4019 &value,exception);
4020 fx_info=DestroyFxInfo(fx_info);
4021 if (status != MagickFalse)
4022 {
4023 char
4024 result[MagickPathExtent];
4025
4026 (void) FormatLocaleString(result,MagickPathExtent,"%.*g",
4027 GetMagickPrecision(),(double) value);
4028 AppendString2Text(result);
4029 }
4030 continue;
4031 }
4032 if (LocaleNCompare("hex:",pattern,4) == 0)
4033 {
4034 double
4035 value;
4036
4037 FxInfo
4038 *fx_info;
4039
4040 MagickStatusType
4041 status;
4042
4043 PixelInfo
4044 pixel;
4045
4046 /*
4047 Pixel - color value calculator.
4048 */
4049 GetPixelInfo(property_image,&pixel);
4050 fx_info=AcquireFxInfo(property_image,pattern+4,exception);
4051 if (fx_info == (FxInfo *) NULL)
4052 continue;
4053 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
4054 &value,exception);
4055 pixel.red=(double) QuantumRange*value;
4056 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4057 GreenPixelChannel,0,0,&value,exception);
4058 pixel.green=(double) QuantumRange*value;
4059 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4060 BluePixelChannel,0,0,&value,exception);
4061 pixel.blue=(double) QuantumRange*value;
4062 if (property_image->colorspace == CMYKColorspace)
4063 {
4064 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4065 BlackPixelChannel,0,0,&value,exception);
4066 pixel.black=(double) QuantumRange*value;
4067 }
4068 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4069 AlphaPixelChannel,0,0,&value,exception);
4070 pixel.alpha=(double) QuantumRange*value;
4071 fx_info=DestroyFxInfo(fx_info);
4072 if (status != MagickFalse)
4073 {
4074 char
4075 hex[MagickPathExtent];
4076
4077 GetColorTuple(&pixel,MagickTrue,hex);
4078 AppendString2Text(hex+1);
4079 }
4080 continue;
4081 }
4082 if (LocaleNCompare("pixel:",pattern,6) == 0)
4083 {
4084 double
4085 value;
4086
4087 FxInfo
4088 *fx_info;
4089
4090 MagickStatusType
4091 status;
4092
4093 PixelInfo
4094 pixel;
4095
4096 /*
4097 Pixel - color value calculator.
4098 */
4099 GetPixelInfo(property_image,&pixel);
4100 fx_info=AcquireFxInfo(property_image,pattern+6,exception);
4101 if (fx_info == (FxInfo *) NULL)
4102 continue;
4103 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
4104 &value,exception);
4105 pixel.red=(double) QuantumRange*value;
4106 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4107 GreenPixelChannel,0,0,&value,exception);
4108 pixel.green=(double) QuantumRange*value;
4109 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4110 BluePixelChannel,0,0,&value,exception);
4111 pixel.blue=(double) QuantumRange*value;
4112 if (property_image->colorspace == CMYKColorspace)
4113 {
4114 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4115 BlackPixelChannel,0,0,&value,exception);
4116 pixel.black=(double) QuantumRange*value;
4117 }
4118 status&=(MagickStatusType) FxEvaluateChannelExpression(fx_info,
4119 AlphaPixelChannel,0,0,&value,exception);
4120 pixel.alpha=(double) QuantumRange*value;
4121 fx_info=DestroyFxInfo(fx_info);
4122 if (status != MagickFalse)
4123 {
4124 char
4125 name[MagickPathExtent];
4126
4127 GetColorTuple(&pixel,MagickFalse,name);
4128 string=GetImageArtifact(property_image,"pixel:compliance");
4129 if (string != (char *) NULL)
4130 {
4131 ComplianceType compliance=(ComplianceType) ParseCommandOption(
4132 MagickComplianceOptions,MagickFalse,string);
4133 (void) QueryColorname(property_image,&pixel,compliance,name,
4134 exception);
4135 }
4136 AppendString2Text(name);
4137 }
4138 continue;
4139 }
4140 if (LocaleNCompare("option:",pattern,7) == 0)
4141 {
4142 /*
4143 Option - direct global option lookup (with globbing).
4144 */
4145 if (IsGlob(pattern+7) != MagickFalse)
4146 {
4147 ResetImageOptionIterator(property_info);
4148 while ((key=GetNextImageOption(property_info)) != (const char *) NULL)
4149 if (GlobExpression(key,pattern+7,MagickTrue) != MagickFalse)
4150 {
4151 string=GetImageOption(property_info,key);
4152 if (string != (const char *) NULL)
4153 AppendKeyValue2Text(key,string);
4154 /* else - assertion failure? key found but no string value! */
4155 }
4156 continue;
4157 }
4158 string=GetImageOption(property_info,pattern+7);
4159 if (string == (char *) NULL)
4160 goto PropertyLookupFailure; /* no artifact of this specific name */
4161 AppendString2Text(string);
4162 continue;
4163 }
4164 if (LocaleNCompare("artifact:",pattern,9) == 0)
4165 {
4166 /*
4167 Artifact - direct image artifact lookup (with glob).
4168 */
4169 if (IsGlob(pattern+9) != MagickFalse)
4170 {
4171 ResetImageArtifactIterator(property_image);
4172 while ((key=GetNextImageArtifact(property_image)) != (const char *) NULL)
4173 if (GlobExpression(key,pattern+9,MagickTrue) != MagickFalse)
4174 {
4175 string=GetImageArtifact(property_image,key);
4176 if (string != (const char *) NULL)
4177 AppendKeyValue2Text(key,string);
4178 /* else - assertion failure? key found but no string value! */
4179 }
4180 continue;
4181 }
4182 string=GetImageArtifact(property_image,pattern+9);
4183 if (string == (char *) NULL)
4184 goto PropertyLookupFailure; /* no artifact of this specific name */
4185 AppendString2Text(string);
4186 continue;
4187 }
4188 if (LocaleNCompare("property:",pattern,9) == 0)
4189 {
4190 /*
4191 Property - direct image property lookup (with glob).
4192 */
4193 if (IsGlob(pattern+9) != MagickFalse)
4194 {
4195 ResetImagePropertyIterator(property_image);
4196 while ((key=GetNextImageProperty(property_image)) != (const char *) NULL)
4197 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
4198 {
4199 string=GetImageProperty(property_image,key,exception);
4200 if (string != (const char *) NULL)
4201 AppendKeyValue2Text(key,string);
4202 /* else - assertion failure? */
4203 }
4204 continue;
4205 }
4206 string=GetImageProperty(property_image,pattern+9,exception);
4207 if (string == (char *) NULL)
4208 goto PropertyLookupFailure; /* no artifact of this specific name */
4209 AppendString2Text(string);
4210 continue;
4211 }
4212 /*
4213 Properties without special prefix. This handles attributes,
4214 properties, and profiles such as %[exif:...]. Note the profile
4215 properties may also include a glob expansion pattern.
4216 */
4217 string=GetImageProperty(property_image,pattern,exception);
4218 if (string != (const char *) NULL)
4219 {
4220 AppendString2Text(string);
4221 (void) DeleteImageArtifact(property_image,"magick-property");
4222 (void) DeleteImageOption(property_info,"magick-property");
4223 continue;
4224 }
4225 if (IsGlob(pattern) != MagickFalse)
4226 {
4227 /*
4228 Handle property 'glob' patterns such as:
4229 %[*] %[user:array_??] %[filename:e*]>
4230 */
4231 ResetImagePropertyIterator(property_image);
4232 while ((key=GetNextImageProperty(property_image)) != (const char *) NULL)
4233 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
4234 {
4235 string=GetImageProperty(property_image,key,exception);
4236 if (string != (const char *) NULL)
4237 AppendKeyValue2Text(key,string);
4238 /* else - assertion failure? */
4239 }
4240 continue;
4241 }
4242 /*
4243 Look for a known property or image attribute such as
4244 %[basename] %[density] %[delay]. Also handles a braced single
4245 letter: %[b] %[G] %[g].
4246 */
4247 string=GetMagickProperty(property_info,property_image,pattern,exception);
4248 if (string != (const char *) NULL)
4249 {
4250 AppendString2Text(string);
4251 continue;
4252 }
4253 /*
4254 Look for a per-image artifact. This includes option lookup
4255 (FUTURE: interpreted according to image).
4256 */
4257 string=GetImageArtifact(property_image,pattern);
4258 if (string != (char *) NULL)
4259 {
4260 AppendString2Text(string);
4261 continue;
4262 }
4263 /*
4264 No image, so direct 'option' lookup (no delayed percent escapes).
4265 */
4266 string=GetImageOption(property_info,pattern);
4267 if (string != (char *) NULL)
4268 {
4269 AppendString2Text(string);
4270 continue;
4271 }
4272PropertyLookupFailure:
4273 /*
4274 Failed to find any match anywhere!
4275 */
4276 if (len >= 64)
4277 {
4278 pattern[61] = '.'; /* truncate string for error message */
4279 pattern[62] = '.';
4280 pattern[63] = '.';
4281 pattern[64] = '\0';
4282 }
4283 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4284 "UnknownImageProperty","\"%%[%s]\"",pattern);
4285 }
4286 }
4287 *q='\0';
4288 if (property_image != image)
4289 property_image=DestroyImage(property_image);
4290 if (property_info != image_info)
4291 property_info=DestroyImageInfo(property_info);
4292 return(interpret_text);
4293}
4294␌
4295/*
4296%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4297% %
4298% %
4299% %
4300% R e m o v e I m a g e P r o p e r t y %
4301% %
4302% %
4303% %
4304%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4305%
4306% RemoveImageProperty() removes a property from the image and returns its
4307% value.
4308%
4309% In this case the ConstantString() value returned should be freed by the
4310% caller when finished.
4311%
4312% The format of the RemoveImageProperty method is:
4313%
4314% char *RemoveImageProperty(Image *image,const char *property)
4315%
4316% A description of each parameter follows:
4317%
4318% o image: the image.
4319%
4320% o property: the image property.
4321%
4322*/
4323MagickExport char *RemoveImageProperty(Image *image,const char *property)
4324{
4325 char
4326 *value;
4327
4328 assert(image != (Image *) NULL);
4329 assert(image->signature == MagickCoreSignature);
4330 if (IsEventLogging() != MagickFalse)
4331 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4332 if (image->properties == (void *) NULL)
4333 return((char *) NULL);
4334 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
4335 property);
4336 return(value);
4337}
4338␌
4339/*
4340%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4341% %
4342% %
4343% %
4344% 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 %
4345% %
4346% %
4347% %
4348%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4349%
4350% ResetImagePropertyIterator() resets the image properties iterator. Use it
4351% in conjunction with GetNextImageProperty() to iterate over all the values
4352% associated with an image property.
4353%
4354% The format of the ResetImagePropertyIterator method is:
4355%
4356% void ResetImagePropertyIterator(const Image *image)
4357%
4358% A description of each parameter follows:
4359%
4360% o image: the image.
4361%
4362*/
4363MagickExport void ResetImagePropertyIterator(const Image *image)
4364{
4365 assert(image != (Image *) NULL);
4366 assert(image->signature == MagickCoreSignature);
4367 if (IsEventLogging() != MagickFalse)
4368 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4369 if (image->properties == (void *) NULL)
4370 return;
4371 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
4372}
4373␌
4374/*
4375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4376% %
4377% %
4378% %
4379% S e t I m a g e P r o p e r t y %
4380% %
4381% %
4382% %
4383%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4384%
4385% SetImageProperty() saves the given string value either to specific known
4386% attribute or to a freeform property string.
4387%
4388% Attempting to set a property that is normally calculated will produce
4389% an exception.
4390%
4391% The format of the SetImageProperty method is:
4392%
4393% MagickBooleanType SetImageProperty(Image *image,const char *property,
4394% const char *value,ExceptionInfo *exception)
4395%
4396% A description of each parameter follows:
4397%
4398% o image: the image.
4399%
4400% o property: the image property.
4401%
4402% o values: the image property values.
4403%
4404% o exception: return any errors or warnings in this structure.
4405%
4406*/
4407MagickExport MagickBooleanType SetImageProperty(Image *image,
4408 const char *property,const char *value,ExceptionInfo *exception)
4409{
4410 MagickBooleanType
4411 status;
4412
4413 MagickStatusType
4414 flags;
4415
4416 size_t
4417 property_length;
4418
4419 assert(image != (Image *) NULL);
4420 assert(image->signature == MagickCoreSignature);
4421 if (IsEventLogging() != MagickFalse)
4422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4423 if (image->properties == (void *) NULL)
4424 image->properties=NewSplayTree(CompareSplayTreeString,
4425 RelinquishMagickMemory,RelinquishMagickMemory); /* create splay-tree */
4426 if (value == (const char *) NULL)
4427 return(DeleteImageProperty(image,property)); /* delete if NULL */
4428 if (strlen(property) <= 1)
4429 {
4430 /*
4431 Do not 'set' single letter properties - read only shorthand.
4432 */
4433 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4434 "SetReadOnlyProperty","`%s'",property);
4435 return(MagickFalse);
4436 }
4437 property_length=strlen(property);
4438 if ((property_length > 2) && (*(property+(property_length-2)) == ':') &&
4439 (*(property+(property_length-1)) == '*'))
4440 {
4441 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4442 "SetReadOnlyProperty","`%s'",property);
4443 return(MagickFalse);
4444 }
4445 /*
4446 FUTURE: binary chars or quotes in key should produce a error
4447 Set attributes with known names or special prefixes
4448 return result is found, or break to set a free form property
4449 */
4450 status=MagickTrue;
4451 switch (*property)
4452 {
4453#if 0 /* Percent escape's sets values with this prefix: for later use
4454 Throwing an exception causes this setting to fail */
4455 case '8':
4456 {
4457 if (LocaleNCompare("8bim:",property,5) == 0)
4458 {
4459 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4460 "SetReadOnlyProperty","`%s'",property);
4461 return(MagickFalse);
4462 }
4463 break;
4464 }
4465#endif
4466 case 'B':
4467 case 'b':
4468 {
4469 if (LocaleCompare("background",property) == 0)
4470 {
4471 (void) QueryColorCompliance(value,AllCompliance,
4472 &image->background_color,exception);
4473 /* check for FUTURE: value exception?? */
4474 /* also add user input to splay tree */
4475 }
4476 break; /* not an attribute, add as a property */
4477 }
4478 case 'C':
4479 case 'c':
4480 {
4481 if (LocaleCompare("channels",property) == 0)
4482 {
4483 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4484 "SetReadOnlyProperty","`%s'",property);
4485 return(MagickFalse);
4486 }
4487 if (LocaleCompare("colorspace",property) == 0)
4488 {
4489 ssize_t
4490 colorspace;
4491
4492 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4493 value);
4494 if (colorspace < 0)
4495 return(MagickFalse); /* FUTURE: value exception?? */
4496 return(SetImageColorspace(image,(ColorspaceType) colorspace,exception));
4497 }
4498 if (LocaleCompare("compose",property) == 0)
4499 {
4500 ssize_t
4501 compose;
4502
4503 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
4504 if (compose < 0)
4505 return(MagickFalse); /* FUTURE: value exception?? */
4506 image->compose=(CompositeOperator) compose;
4507 return(MagickTrue);
4508 }
4509 if (LocaleCompare("compress",property) == 0)
4510 {
4511 ssize_t
4512 compression;
4513
4514 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
4515 value);
4516 if (compression < 0)
4517 return(MagickFalse); /* FUTURE: value exception?? */
4518 image->compression=(CompressionType) compression;
4519 return(MagickTrue);
4520 }
4521 break; /* not an attribute, add as a property */
4522 }
4523 case 'D':
4524 case 'd':
4525 {
4526 if (LocaleCompare("delay",property) == 0)
4527 {
4528 GeometryInfo
4529 geometry_info;
4530
4531 flags=ParseGeometry(value,&geometry_info);
4532 if ((flags & GreaterValue) != 0)
4533 {
4534 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
4535 image->delay=(size_t) floor(geometry_info.rho+0.5);
4536 }
4537 else
4538 if ((flags & LessValue) != 0)
4539 {
4540 if ((double) image->delay < floor(geometry_info.rho+0.5))
4541 image->delay=(size_t) CastDoubleToSsizeT(floor(
4542 geometry_info.sigma+0.5));
4543 }
4544 else
4545 image->delay=(size_t) floor(geometry_info.rho+0.5);
4546 if ((flags & SigmaValue) != 0)
4547 image->ticks_per_second=CastDoubleToSsizeT(floor(
4548 geometry_info.sigma+0.5));
4549 return(MagickTrue);
4550 }
4551 if (LocaleCompare("delay_units",property) == 0)
4552 {
4553 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4554 "SetReadOnlyProperty","`%s'",property);
4555 return(MagickFalse);
4556 }
4557 if (LocaleCompare("density",property) == 0)
4558 {
4559 GeometryInfo
4560 geometry_info;
4561
4562 flags=ParseGeometry(value,&geometry_info);
4563 if ((flags & RhoValue) != 0)
4564 image->resolution.x=geometry_info.rho;
4565 image->resolution.y=image->resolution.x;
4566 if ((flags & SigmaValue) != 0)
4567 image->resolution.y=geometry_info.sigma;
4568 return(MagickTrue);
4569 }
4570 if (LocaleCompare("depth",property) == 0)
4571 {
4572 image->depth=StringToUnsignedLong(value);
4573 return(MagickTrue);
4574 }
4575 if (LocaleCompare("dispose",property) == 0)
4576 {
4577 ssize_t
4578 dispose;
4579
4580 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
4581 if (dispose < 0)
4582 return(MagickFalse); /* FUTURE: value exception?? */
4583 image->dispose=(DisposeType) dispose;
4584 return(MagickTrue);
4585 }
4586 break; /* not an attribute, add as a property */
4587 }
4588#if 0 /* Percent escape's sets values with this prefix: for later use
4589 Throwing an exception causes this setting to fail */
4590 case 'E':
4591 case 'e':
4592 {
4593 if (LocaleNCompare("exif:",property,5) == 0)
4594 {
4595 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4596 "SetReadOnlyProperty","`%s'",property);
4597 return(MagickFalse);
4598 }
4599 break; /* not an attribute, add as a property */
4600 }
4601 case 'F':
4602 case 'f':
4603 {
4604 if (LocaleNCompare("fx:",property,3) == 0)
4605 {
4606 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4607 "SetReadOnlyProperty","`%s'",property);
4608 return(MagickFalse);
4609 }
4610 break; /* not an attribute, add as a property */
4611 }
4612#endif
4613 case 'G':
4614 case 'g':
4615 {
4616 if (LocaleCompare("gamma",property) == 0)
4617 {
4618 image->gamma=StringToDouble(value,(char **) NULL);
4619 return(MagickTrue);
4620 }
4621 if (LocaleCompare("gravity",property) == 0)
4622 {
4623 ssize_t
4624 gravity;
4625
4626 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
4627 if (gravity < 0)
4628 return(MagickFalse); /* FUTURE: value exception?? */
4629 image->gravity=(GravityType) gravity;
4630 return(MagickTrue);
4631 }
4632 break; /* not an attribute, add as a property */
4633 }
4634 case 'H':
4635 case 'h':
4636 {
4637 if (LocaleCompare("height",property) == 0)
4638 {
4639 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4640 "SetReadOnlyProperty","`%s'",property);
4641 return(MagickFalse);
4642 }
4643 break; /* not an attribute, add as a property */
4644 }
4645 case 'I':
4646 case 'i':
4647 {
4648 if (LocaleCompare("intensity",property) == 0)
4649 {
4650 ssize_t
4651 intensity;
4652
4653 intensity=ParseCommandOption(MagickIntensityOptions,MagickFalse,
4654 value);
4655 if (intensity < 0)
4656 return(MagickFalse);
4657 image->intensity=(PixelIntensityMethod) intensity;
4658 return(MagickTrue);
4659 }
4660 if (LocaleCompare("intent",property) == 0)
4661 {
4662 ssize_t
4663 rendering_intent;
4664
4665 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4666 value);
4667 if (rendering_intent < 0)
4668 return(MagickFalse); /* FUTURE: value exception?? */
4669 image->rendering_intent=(RenderingIntent) rendering_intent;
4670 return(MagickTrue);
4671 }
4672 if (LocaleCompare("interpolate",property) == 0)
4673 {
4674 ssize_t
4675 interpolate;
4676
4677 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
4678 value);
4679 if (interpolate < 0)
4680 return(MagickFalse); /* FUTURE: value exception?? */
4681 image->interpolate=(PixelInterpolateMethod) interpolate;
4682 return(MagickTrue);
4683 }
4684#if 0 /* Percent escape's sets values with this prefix: for later use
4685 Throwing an exception causes this setting to fail */
4686 if (LocaleNCompare("iptc:",property,5) == 0)
4687 {
4688 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4689 "SetReadOnlyProperty","`%s'",property);
4690 return(MagickFalse);
4691 }
4692#endif
4693 break; /* not an attribute, add as a property */
4694 }
4695 case 'K':
4696 case 'k':
4697 if (LocaleCompare("kurtosis",property) == 0)
4698 {
4699 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4700 "SetReadOnlyProperty","`%s'",property);
4701 return(MagickFalse);
4702 }
4703 break; /* not an attribute, add as a property */
4704 case 'L':
4705 case 'l':
4706 {
4707 if (LocaleCompare("loop",property) == 0)
4708 {
4709 image->iterations=StringToUnsignedLong(value);
4710 return(MagickTrue);
4711 }
4712 break; /* not an attribute, add as a property */
4713 }
4714 case 'M':
4715 case 'm':
4716 if ((LocaleCompare("magick",property) == 0) ||
4717 (LocaleCompare("max",property) == 0) ||
4718 (LocaleCompare("mean",property) == 0) ||
4719 (LocaleCompare("min",property) == 0) ||
4720 (LocaleCompare("min",property) == 0))
4721 {
4722 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4723 "SetReadOnlyProperty","`%s'",property);
4724 return(MagickFalse);
4725 }
4726 break; /* not an attribute, add as a property */
4727 case 'O':
4728 case 'o':
4729 if (LocaleCompare("opaque",property) == 0)
4730 {
4731 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4732 "SetReadOnlyProperty","`%s'",property);
4733 return(MagickFalse);
4734 }
4735 break; /* not an attribute, add as a property */
4736 case 'P':
4737 case 'p':
4738 {
4739 if (LocaleCompare("page",property) == 0)
4740 {
4741 char
4742 *geometry;
4743
4744 geometry=GetPageGeometry(value);
4745 flags=ParseAbsoluteGeometry(geometry,&image->page);
4746 geometry=DestroyString(geometry);
4747 return(MagickTrue);
4748 }
4749#if 0 /* Percent escape's sets values with this prefix: for later use
4750 Throwing an exception causes this setting to fail */
4751 if (LocaleNCompare("pixel:",property,6) == 0)
4752 {
4753 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4754 "SetReadOnlyProperty","`%s'",property);
4755 return(MagickFalse);
4756 }
4757#endif
4758 break; /* not an attribute, add as a property */
4759 }
4760 case 'R':
4761 case 'r':
4762 {
4763 if (LocaleCompare("rendering-intent",property) == 0)
4764 {
4765 ssize_t
4766 rendering_intent;
4767
4768 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4769 value);
4770 if (rendering_intent < 0)
4771 return(MagickFalse); /* FUTURE: value exception?? */
4772 image->rendering_intent=(RenderingIntent) rendering_intent;
4773 return(MagickTrue);
4774 }
4775 break; /* not an attribute, add as a property */
4776 }
4777 case 'S':
4778 case 's':
4779 if ((LocaleCompare("size",property) == 0) ||
4780 (LocaleCompare("skewness",property) == 0) ||
4781 (LocaleCompare("scenes",property) == 0) ||
4782 (LocaleCompare("standard-deviation",property) == 0))
4783 {
4784 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4785 "SetReadOnlyProperty","`%s'",property);
4786 return(MagickFalse);
4787 }
4788 break; /* not an attribute, add as a property */
4789 case 'T':
4790 case 't':
4791 {
4792 if (LocaleCompare("tile-offset",property) == 0)
4793 {
4794 char
4795 *geometry;
4796
4797 geometry=GetPageGeometry(value);
4798 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4799 geometry=DestroyString(geometry);
4800 return(MagickTrue);
4801 }
4802 if (LocaleCompare("type",property) == 0)
4803 {
4804 ssize_t
4805 type;
4806
4807 type=ParseCommandOption(MagickTypeOptions,MagickFalse,value);
4808 if (type < 0)
4809 return(MagickFalse);
4810 image->type=(ImageType) type;
4811 return(MagickTrue);
4812 }
4813 break; /* not an attribute, add as a property */
4814 }
4815 case 'U':
4816 case 'u':
4817 {
4818 if (LocaleCompare("units",property) == 0)
4819 {
4820 ssize_t
4821 units;
4822
4823 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
4824 if (units < 0)
4825 return(MagickFalse); /* FUTURE: value exception?? */
4826 image->units=(ResolutionType) units;
4827 return(MagickTrue);
4828 }
4829 break; /* not an attribute, add as a property */
4830 }
4831 case 'V':
4832 case 'v':
4833 {
4834 if (LocaleCompare("version",property) == 0)
4835 {
4836 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4837 "SetReadOnlyProperty","`%s'",property);
4838 return(MagickFalse);
4839 }
4840 break; /* not an attribute, add as a property */
4841 }
4842 case 'W':
4843 case 'w':
4844 {
4845 if (LocaleCompare("width",property) == 0)
4846 {
4847 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4848 "SetReadOnlyProperty","`%s'",property);
4849 return(MagickFalse);
4850 }
4851 break; /* not an attribute, add as a property */
4852 }
4853#if 0 /* Percent escape's sets values with this prefix: for later use
4854 Throwing an exception causes this setting to fail */
4855 case 'X':
4856 case 'x':
4857 {
4858 if (LocaleNCompare("xmp:",property,4) == 0)
4859 {
4860 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
4861 "SetReadOnlyProperty","`%s'",property);
4862 return(MagickFalse);
4863 }
4864 break; /* not an attribute, add as a property */
4865 }
4866#endif
4867 }
4868 /* Default: not an attribute, add as a property */
4869 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
4870 ConstantString(property),ConstantString(value));
4871 /* FUTURE: error if status is bad? */
4872 return(status);
4873}