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