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