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