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