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