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