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