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