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