blob: ab13b65b1881f427b9a081b35219c584b0a5e556 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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% http://www.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*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/attribute.h"
45#include "MagickCore/cache.h"
46#include "MagickCore/color.h"
47#include "MagickCore/compare.h"
48#include "MagickCore/constitute.h"
49#include "MagickCore/draw.h"
50#include "MagickCore/effect.h"
51#include "MagickCore/exception.h"
52#include "MagickCore/exception-private.h"
53#include "MagickCore/fx.h"
54#include "MagickCore/fx-private.h"
55#include "MagickCore/gem.h"
56#include "MagickCore/geometry.h"
57#include "MagickCore/histogram.h"
58#include "MagickCore/image.h"
59#include "MagickCore/image.h"
60#include "MagickCore/layer.h"
cristy7832dc22011-09-05 01:21:53 +000061#include "MagickCore/locale-private.h"
cristy4c08aed2011-07-01 19:47:50 +000062#include "MagickCore/list.h"
63#include "MagickCore/magick.h"
64#include "MagickCore/memory_.h"
65#include "MagickCore/monitor.h"
66#include "MagickCore/montage.h"
67#include "MagickCore/option.h"
68#include "MagickCore/profile.h"
69#include "MagickCore/property.h"
70#include "MagickCore/quantum.h"
71#include "MagickCore/resource_.h"
72#include "MagickCore/splay-tree.h"
cristy7832dc22011-09-05 01:21:53 +000073#include "MagickCore/signature.h"
cristy4c08aed2011-07-01 19:47:50 +000074#include "MagickCore/statistic.h"
75#include "MagickCore/string_.h"
76#include "MagickCore/string-private.h"
77#include "MagickCore/token.h"
cristy7832dc22011-09-05 01:21:53 +000078#include "MagickCore/token-private.h"
cristy4c08aed2011-07-01 19:47:50 +000079#include "MagickCore/utility.h"
cristyd1dd6e42011-09-04 01:46:08 +000080#include "MagickCore/utility-private.h"
cristy4c08aed2011-07-01 19:47:50 +000081#include "MagickCore/version.h"
82#include "MagickCore/xml-tree.h"
cristy433d1182011-09-04 13:38:52 +000083#include "MagickCore/xml-tree-private.h"
cristy3ed852e2009-09-05 21:47:34 +000084
85/*
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87% %
88% %
89% %
90% C l o n e I m a g e P r o p e r t i e s %
91% %
92% %
93% %
94%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95%
96% CloneImageProperties() clones one or more image properties.
97%
98% The format of the CloneImageProperties method is:
99%
100% MagickBooleanType CloneImageProperties(Image *image,
101% const Image *clone_image)
102%
103% A description of each parameter follows:
104%
105% o image: the image.
106%
107% o clone_image: the clone image.
108%
109*/
110MagickExport MagickBooleanType CloneImageProperties(Image *image,
111 const Image *clone_image)
112{
113 assert(image != (Image *) NULL);
114 assert(image->signature == MagickSignature);
115 if (image->debug != MagickFalse)
116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
117 assert(clone_image != (const Image *) NULL);
118 assert(clone_image->signature == MagickSignature);
119 if (clone_image->debug != MagickFalse)
120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
121 clone_image->filename);
122 (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
123 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
124 MaxTextExtent);
125 image->compression=clone_image->compression;
126 image->quality=clone_image->quality;
127 image->depth=clone_image->depth;
128 image->background_color=clone_image->background_color;
129 image->border_color=clone_image->border_color;
130 image->matte_color=clone_image->matte_color;
131 image->transparent_color=clone_image->transparent_color;
132 image->gamma=clone_image->gamma;
133 image->chromaticity=clone_image->chromaticity;
134 image->rendering_intent=clone_image->rendering_intent;
135 image->black_point_compensation=clone_image->black_point_compensation;
136 image->units=clone_image->units;
137 image->montage=(char *) NULL;
138 image->directory=(char *) NULL;
139 (void) CloneString(&image->geometry,clone_image->geometry);
140 image->offset=clone_image->offset;
141 image->x_resolution=clone_image->x_resolution;
142 image->y_resolution=clone_image->y_resolution;
143 image->page=clone_image->page;
144 image->tile_offset=clone_image->tile_offset;
145 image->extract_info=clone_image->extract_info;
146 image->bias=clone_image->bias;
147 image->filter=clone_image->filter;
148 image->blur=clone_image->blur;
149 image->fuzz=clone_image->fuzz;
150 image->interlace=clone_image->interlace;
151 image->interpolate=clone_image->interpolate;
152 image->endian=clone_image->endian;
153 image->gravity=clone_image->gravity;
154 image->compose=clone_image->compose;
155 image->scene=clone_image->scene;
156 image->orientation=clone_image->orientation;
157 image->dispose=clone_image->dispose;
158 image->delay=clone_image->delay;
159 image->ticks_per_second=clone_image->ticks_per_second;
160 image->iterations=clone_image->iterations;
161 image->total_colors=clone_image->total_colors;
162 image->taint=clone_image->taint;
163 image->progress_monitor=clone_image->progress_monitor;
164 image->client_data=clone_image->client_data;
165 image->start_loop=clone_image->start_loop;
166 image->error=clone_image->error;
167 image->signature=clone_image->signature;
168 if (clone_image->properties != (void *) NULL)
169 {
170 if (image->properties != (void *) NULL)
171 DestroyImageProperties(image);
172 image->properties=CloneSplayTree((SplayTreeInfo *)
173 clone_image->properties,(void *(*)(void *)) ConstantString,
174 (void *(*)(void *)) ConstantString);
175 }
176 return(MagickTrue);
177}
178
179/*
180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181% %
182% %
183% %
184% D e f i n e I m a g e P r o p e r t y %
185% %
186% %
187% %
188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189%
190% DefineImageProperty() associates a key/value pair with an image property.
191%
192% The format of the DefineImageProperty method is:
193%
194% MagickBooleanType DefineImageProperty(Image *image,
195% const char *property)
196%
197% A description of each parameter follows:
198%
199% o image: the image.
200%
201% o property: the image property.
202%
203*/
204MagickExport MagickBooleanType DefineImageProperty(Image *image,
205 const char *property)
206{
207 char
208 key[MaxTextExtent],
209 value[MaxTextExtent];
210
211 register char
212 *p;
213
214 assert(image != (Image *) NULL);
215 assert(property != (const char *) NULL);
216 (void) CopyMagickString(key,property,MaxTextExtent-1);
217 for (p=key; *p != '\0'; p++)
218 if (*p == '=')
219 break;
220 *value='\0';
221 if (*p == '=')
222 (void) CopyMagickString(value,p+1,MaxTextExtent);
223 *p='\0';
224 return(SetImageProperty(image,key,value));
225}
226
227/*
228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229% %
230% %
231% %
232% D e l e t e I m a g e P r o p e r t y %
233% %
234% %
235% %
236%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237%
238% DeleteImageProperty() deletes an image property.
239%
240% The format of the DeleteImageProperty method is:
241%
242% MagickBooleanType DeleteImageProperty(Image *image,const char *property)
243%
244% A description of each parameter follows:
245%
246% o image: the image.
247%
248% o property: the image property.
249%
250*/
251MagickExport MagickBooleanType DeleteImageProperty(Image *image,
252 const char *property)
253{
254 assert(image != (Image *) NULL);
255 assert(image->signature == MagickSignature);
256 if (image->debug != MagickFalse)
257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
258 image->filename);
259 if (image->properties == (void *) NULL)
260 return(MagickFalse);
261 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
262}
263
264/*
265%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266% %
267% %
268% %
269% D e s t r o y I m a g e P r o p e r t i e s %
270% %
271% %
272% %
273%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274%
275% DestroyImageProperties() releases memory associated with image property
276% values.
277%
278% The format of the DestroyDefines method is:
279%
280% void DestroyImageProperties(Image *image)
281%
282% A description of each parameter follows:
283%
284% o image: the image.
285%
286*/
287MagickExport void DestroyImageProperties(Image *image)
288{
289 assert(image != (Image *) NULL);
290 assert(image->signature == MagickSignature);
291 if (image->debug != MagickFalse)
292 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
293 image->filename);
294 if (image->properties != (void *) NULL)
295 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
296 image->properties);
297}
298
299/*
300%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301% %
302% %
303% %
304% F o r m a t I m a g e P r o p e r t y %
305% %
306% %
307% %
308%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309%
310% FormatImageProperty() permits formatted property/value pairs to be saved as
glennrp2cc891a2010-12-24 13:44:32 +0000311% an image property.
cristy3ed852e2009-09-05 21:47:34 +0000312%
313% The format of the FormatImageProperty method is:
314%
315% MagickBooleanType FormatImageProperty(Image *image,const char *property,
316% const char *format,...)
317%
318% A description of each parameter follows.
319%
320% o image: The image.
321%
322% o property: The attribute property.
323%
324% o format: A string describing the format to use to write the remaining
325% arguments.
326%
327*/
cristydb584ae2011-05-20 14:50:53 +0000328MagickExport MagickBooleanType FormatImageProperty(Image *image,
329 const char *property,const char *format,...)
cristy3ed852e2009-09-05 21:47:34 +0000330{
331 char
332 value[MaxTextExtent];
333
cristy20ec7592011-05-29 01:28:05 +0000334 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000335 n;
336
cristy3ed852e2009-09-05 21:47:34 +0000337 va_list
338 operands;
339
340 va_start(operands,format);
cristydb584ae2011-05-20 14:50:53 +0000341 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
342 (void) n;
cristy3ed852e2009-09-05 21:47:34 +0000343 va_end(operands);
cristydb584ae2011-05-20 14:50:53 +0000344 return(SetImageProperty(image,property,value));
cristy3ed852e2009-09-05 21:47:34 +0000345}
346
347/*
348%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349% %
350% %
351% %
352% G e t I m a g e P r o p e r t y %
353% %
354% %
355% %
356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357%
358% GetImageProperty() gets a value associated with an image property.
359%
360% The format of the GetImageProperty method is:
361%
362% const char *GetImageProperty(const Image *image,const char *key)
363%
364% A description of each parameter follows:
365%
366% o image: the image.
367%
368% o key: the key.
369%
370*/
371
372static char
cristybb503372010-05-27 20:51:26 +0000373 *TracePSClippath(const unsigned char *,size_t,const size_t,
374 const size_t),
375 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
376 const size_t);
cristy3ed852e2009-09-05 21:47:34 +0000377
378static MagickBooleanType GetIPTCProperty(const Image *image,const char *key)
379{
380 char
381 *attribute,
382 *message;
383
384 const StringInfo
385 *profile;
386
cristycee97112010-05-28 00:44:52 +0000387 long
cristy3ed852e2009-09-05 21:47:34 +0000388 count,
389 dataset,
390 record;
391
cristybb503372010-05-27 20:51:26 +0000392 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000393 i;
394
395 size_t
396 length;
397
398 profile=GetImageProfile(image,"iptc");
399 if (profile == (StringInfo *) NULL)
400 profile=GetImageProfile(image,"8bim");
401 if (profile == (StringInfo *) NULL)
402 return(MagickFalse);
403 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
404 if (count != 2)
405 return(MagickFalse);
406 attribute=(char *) NULL;
cristybb503372010-05-27 20:51:26 +0000407 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
cristy3ed852e2009-09-05 21:47:34 +0000408 {
409 length=1;
cristybb503372010-05-27 20:51:26 +0000410 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
cristy3ed852e2009-09-05 21:47:34 +0000411 continue;
412 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
413 length|=GetStringInfoDatum(profile)[i+4];
cristycee97112010-05-28 00:44:52 +0000414 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
415 ((long) GetStringInfoDatum(profile)[i+2] == record))
cristy3ed852e2009-09-05 21:47:34 +0000416 {
417 message=(char *) NULL;
418 if (~length >= 1)
419 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
420 if (message != (char *) NULL)
421 {
422 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
423 profile)+i+5,length+1);
424 (void) ConcatenateString(&attribute,message);
425 (void) ConcatenateString(&attribute,";");
426 message=DestroyString(message);
427 }
428 }
429 i+=5;
430 }
431 if ((attribute == (char *) NULL) || (*attribute == ';'))
432 {
433 if (attribute != (char *) NULL)
434 attribute=DestroyString(attribute);
435 return(MagickFalse);
436 }
437 attribute[strlen(attribute)-1]='\0';
438 (void) SetImageProperty((Image *) image,key,(const char *) attribute);
439 attribute=DestroyString(attribute);
440 return(MagickTrue);
441}
442
cristybb503372010-05-27 20:51:26 +0000443static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000444{
445 if (x > y)
446 return(x);
447 return(y);
448}
449
450static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
451{
452 int
453 c;
454
455 if (*length < 1)
456 return(EOF);
457 c=(int) (*(*p)++);
458 (*length)--;
459 return(c);
460}
461
cristybb503372010-05-27 20:51:26 +0000462static inline size_t ReadPropertyMSBLong(const unsigned char **p,
cristy3ed852e2009-09-05 21:47:34 +0000463 size_t *length)
464{
465 int
466 c;
467
cristybb503372010-05-27 20:51:26 +0000468 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000469 i;
470
471 unsigned char
472 buffer[4];
473
cristybb503372010-05-27 20:51:26 +0000474 size_t
cristy3ed852e2009-09-05 21:47:34 +0000475 value;
476
477 if (*length < 4)
478 return(~0UL);
479 for (i=0; i < 4; i++)
480 {
481 c=(int) (*(*p)++);
482 (*length)--;
483 buffer[i]=(unsigned char) c;
484 }
cristybb503372010-05-27 20:51:26 +0000485 value=(size_t) (buffer[0] << 24);
cristy3ed852e2009-09-05 21:47:34 +0000486 value|=buffer[1] << 16;
487 value|=buffer[2] << 8;
488 value|=buffer[3];
489 return(value & 0xffffffff);
490}
491
492static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
493 size_t *length)
494{
495 int
496 c;
497
cristybb503372010-05-27 20:51:26 +0000498 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000499 i;
500
501 unsigned char
502 buffer[2];
503
504 unsigned short
505 value;
506
507 if (*length < 2)
508 return((unsigned short) ~0U);
509 for (i=0; i < 2; i++)
510 {
511 c=(int) (*(*p)++);
512 (*length)--;
513 buffer[i]=(unsigned char) c;
514 }
515 value=(unsigned short) (buffer[0] << 8);
516 value|=buffer[1];
517 return((unsigned short) (value & 0xffff));
518}
519
520static MagickBooleanType Get8BIMProperty(const Image *image,const char *key)
521{
522 char
523 *attribute,
524 format[MaxTextExtent],
525 name[MaxTextExtent],
526 *resource;
527
528 const StringInfo
529 *profile;
530
531 const unsigned char
532 *info;
533
cristycee97112010-05-28 00:44:52 +0000534 long
cristy3ed852e2009-09-05 21:47:34 +0000535 start,
cristycee97112010-05-28 00:44:52 +0000536 stop;
cristy3ed852e2009-09-05 21:47:34 +0000537
538 MagickBooleanType
539 status;
540
cristybb503372010-05-27 20:51:26 +0000541 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000542 i;
543
544 ssize_t
cristycee97112010-05-28 00:44:52 +0000545 count,
546 id,
547 sub_number;
cristy3ed852e2009-09-05 21:47:34 +0000548
549 size_t
550 length;
551
552 /*
glennrp2cc891a2010-12-24 13:44:32 +0000553 There are no newlines in path names, so it's safe as terminator.
cristy3ed852e2009-09-05 21:47:34 +0000554 */
555 profile=GetImageProfile(image,"8bim");
556 if (profile == (StringInfo *) NULL)
557 return(MagickFalse);
558 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
559 format);
560 if ((count != 2) && (count != 3) && (count != 4))
561 return(MagickFalse);
562 if (count < 4)
563 (void) CopyMagickString(format,"SVG",MaxTextExtent);
564 if (count < 3)
565 *name='\0';
566 sub_number=1;
567 if (*name == '#')
cristyad740052010-07-03 01:38:03 +0000568 sub_number=(ssize_t) StringToLong(&name[1]);
cristy3ed852e2009-09-05 21:47:34 +0000569 sub_number=MagickMax(sub_number,1L);
570 resource=(char *) NULL;
571 status=MagickFalse;
572 length=GetStringInfoLength(profile);
573 info=GetStringInfoDatum(profile);
574 while ((length > 0) && (status == MagickFalse))
575 {
576 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
577 continue;
578 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
579 continue;
580 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
581 continue;
582 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
583 continue;
cristybb503372010-05-27 20:51:26 +0000584 id=(ssize_t) ReadPropertyMSBShort(&info,&length);
cristycee97112010-05-28 00:44:52 +0000585 if (id < (ssize_t) start)
cristy3ed852e2009-09-05 21:47:34 +0000586 continue;
cristycee97112010-05-28 00:44:52 +0000587 if (id > (ssize_t) stop)
cristy3ed852e2009-09-05 21:47:34 +0000588 continue;
589 if (resource != (char *) NULL)
590 resource=DestroyString(resource);
591 count=(ssize_t) ReadPropertyByte(&info,&length);
592 if ((count != 0) && ((size_t) count <= length))
593 {
594 resource=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +0000595 if (~(1UL*count) >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +0000596 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
597 sizeof(*resource));
598 if (resource != (char *) NULL)
599 {
cristybb503372010-05-27 20:51:26 +0000600 for (i=0; i < (ssize_t) count; i++)
cristy3ed852e2009-09-05 21:47:34 +0000601 resource[i]=(char) ReadPropertyByte(&info,&length);
602 resource[count]='\0';
603 }
604 }
605 if ((count & 0x01) == 0)
606 (void) ReadPropertyByte(&info,&length);
cristy55a91cd2010-12-01 00:57:40 +0000607 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
cristy3ed852e2009-09-05 21:47:34 +0000608 if ((*name != '\0') && (*name != '#'))
609 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
610 {
611 /*
612 No name match, scroll forward and try next.
613 */
614 info+=count;
615 length-=count;
616 continue;
617 }
618 if ((*name == '#') && (sub_number != 1))
619 {
620 /*
621 No numbered match, scroll forward and try next.
622 */
623 sub_number--;
624 info+=count;
625 length-=count;
626 continue;
627 }
628 /*
629 We have the resource of interest.
630 */
631 attribute=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +0000632 if (~(1UL*count) >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +0000633 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
634 sizeof(*attribute));
635 if (attribute != (char *) NULL)
636 {
637 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
638 attribute[count]='\0';
639 info+=count;
640 length-=count;
641 if ((id <= 1999) || (id >= 2999))
642 (void) SetImageProperty((Image *) image,key,(const char *)
643 attribute);
644 else
645 {
646 char
647 *path;
648
649 if (LocaleCompare(format,"svg") == 0)
650 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
651 image->columns,image->rows);
652 else
653 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
654 image->columns,image->rows);
655 (void) SetImageProperty((Image *) image,key,(const char *) path);
656 path=DestroyString(path);
657 }
658 attribute=DestroyString(attribute);
659 status=MagickTrue;
660 }
661 }
662 if (resource != (char *) NULL)
663 resource=DestroyString(resource);
664 return(status);
665}
666
667static inline unsigned short ReadPropertyShort(const EndianType endian,
668 const unsigned char *buffer)
669{
670 unsigned short
671 value;
672
673 if (endian == MSBEndian)
674 {
675 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
676 ((unsigned char *) buffer)[1]);
677 return((unsigned short) (value & 0xffff));
678 }
679 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
680 return((unsigned short) (value & 0xffff));
681}
682
cristybb503372010-05-27 20:51:26 +0000683static inline size_t ReadPropertyLong(const EndianType endian,
cristy3ed852e2009-09-05 21:47:34 +0000684 const unsigned char *buffer)
685{
cristybb503372010-05-27 20:51:26 +0000686 size_t
cristy3ed852e2009-09-05 21:47:34 +0000687 value;
688
689 if (endian == MSBEndian)
690 {
cristybb503372010-05-27 20:51:26 +0000691 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
cristy3ed852e2009-09-05 21:47:34 +0000692 (buffer[2] << 8) | buffer[3]);
cristybb503372010-05-27 20:51:26 +0000693 return((size_t) (value & 0xffffffff));
cristy3ed852e2009-09-05 21:47:34 +0000694 }
cristybb503372010-05-27 20:51:26 +0000695 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
cristy3ed852e2009-09-05 21:47:34 +0000696 (buffer[1] << 8 ) | (buffer[0]));
cristybb503372010-05-27 20:51:26 +0000697 return((size_t) (value & 0xffffffff));
cristy3ed852e2009-09-05 21:47:34 +0000698}
699
700static MagickBooleanType GetEXIFProperty(const Image *image,
701 const char *property)
702{
703#define MaxDirectoryStack 16
704#define EXIF_DELIMITER "\n"
705#define EXIF_NUM_FORMATS 12
706#define EXIF_FMT_BYTE 1
707#define EXIF_FMT_STRING 2
708#define EXIF_FMT_USHORT 3
709#define EXIF_FMT_ULONG 4
710#define EXIF_FMT_URATIONAL 5
711#define EXIF_FMT_SBYTE 6
712#define EXIF_FMT_UNDEFINED 7
713#define EXIF_FMT_SSHORT 8
714#define EXIF_FMT_SLONG 9
715#define EXIF_FMT_SRATIONAL 10
716#define EXIF_FMT_SINGLE 11
717#define EXIF_FMT_DOUBLE 12
718#define TAG_EXIF_OFFSET 0x8769
719#define TAG_GPS_OFFSET 0x8825
720#define TAG_INTEROP_OFFSET 0xa005
721
722#define EXIFMultipleValues(size, format, arg) \
723{ \
cristybb503372010-05-27 20:51:26 +0000724 ssize_t \
cristy3ed852e2009-09-05 21:47:34 +0000725 component; \
726 \
727 size_t \
728 length; \
729 \
730 unsigned char \
731 *p1; \
732 \
733 length=0; \
734 p1=p; \
735 for (component=0; component < components; component++) \
736 { \
cristyb51dff52011-05-19 16:55:47 +0000737 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
cristy3ed852e2009-09-05 21:47:34 +0000738 format", ",arg); \
cristy37e0b382011-06-07 13:31:21 +0000739 if (length >= (MaxTextExtent-1)) \
cristy3ed852e2009-09-05 21:47:34 +0000740 length=MaxTextExtent-1; \
741 p1+=size; \
742 } \
743 if (length > 1) \
744 buffer[length-2]='\0'; \
745 value=AcquireString(buffer); \
746}
747
748#define EXIFMultipleFractions(size, format, arg1, arg2) \
749{ \
cristybb503372010-05-27 20:51:26 +0000750 ssize_t \
cristy3ed852e2009-09-05 21:47:34 +0000751 component; \
752 \
753 size_t \
754 length; \
755 \
756 unsigned char \
757 *p1; \
758 \
759 length=0; \
760 p1=p; \
761 for (component=0; component < components; component++) \
762 { \
cristyb51dff52011-05-19 16:55:47 +0000763 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
cristy3ed852e2009-09-05 21:47:34 +0000764 format", ",arg1, arg2); \
cristy37e0b382011-06-07 13:31:21 +0000765 if (length >= (MaxTextExtent-1)) \
cristy3ed852e2009-09-05 21:47:34 +0000766 length=MaxTextExtent-1; \
767 p1+=size; \
768 } \
769 if (length > 1) \
770 buffer[length-2]='\0'; \
771 value=AcquireString(buffer); \
772}
773
774 typedef struct _DirectoryInfo
775 {
776 const unsigned char
777 *directory;
778
cristybb503372010-05-27 20:51:26 +0000779 size_t
cristy3ed852e2009-09-05 21:47:34 +0000780 entry,
781 offset;
782 } DirectoryInfo;
783
784 typedef struct _TagInfo
785 {
cristybb503372010-05-27 20:51:26 +0000786 size_t
cristy3ed852e2009-09-05 21:47:34 +0000787 tag;
788
789 const char
790 *description;
791 } TagInfo;
792
793 static TagInfo
794 EXIFTag[] =
795 {
796 { 0x001, "exif:InteroperabilityIndex" },
797 { 0x002, "exif:InteroperabilityVersion" },
798 { 0x100, "exif:ImageWidth" },
799 { 0x101, "exif:ImageLength" },
800 { 0x102, "exif:BitsPerSample" },
801 { 0x103, "exif:Compression" },
802 { 0x106, "exif:PhotometricInterpretation" },
803 { 0x10a, "exif:FillOrder" },
804 { 0x10d, "exif:DocumentName" },
805 { 0x10e, "exif:ImageDescription" },
806 { 0x10f, "exif:Make" },
807 { 0x110, "exif:Model" },
808 { 0x111, "exif:StripOffsets" },
809 { 0x112, "exif:Orientation" },
810 { 0x115, "exif:SamplesPerPixel" },
811 { 0x116, "exif:RowsPerStrip" },
812 { 0x117, "exif:StripByteCounts" },
813 { 0x11a, "exif:XResolution" },
814 { 0x11b, "exif:YResolution" },
815 { 0x11c, "exif:PlanarConfiguration" },
816 { 0x11d, "exif:PageName" },
817 { 0x11e, "exif:XPosition" },
818 { 0x11f, "exif:YPosition" },
819 { 0x118, "exif:MinSampleValue" },
820 { 0x119, "exif:MaxSampleValue" },
821 { 0x120, "exif:FreeOffsets" },
822 { 0x121, "exif:FreeByteCounts" },
823 { 0x122, "exif:GrayResponseUnit" },
824 { 0x123, "exif:GrayResponseCurve" },
825 { 0x124, "exif:T4Options" },
826 { 0x125, "exif:T6Options" },
827 { 0x128, "exif:ResolutionUnit" },
828 { 0x12d, "exif:TransferFunction" },
829 { 0x131, "exif:Software" },
830 { 0x132, "exif:DateTime" },
831 { 0x13b, "exif:Artist" },
832 { 0x13e, "exif:WhitePoint" },
833 { 0x13f, "exif:PrimaryChromaticities" },
834 { 0x140, "exif:ColorMap" },
835 { 0x141, "exif:HalfToneHints" },
836 { 0x142, "exif:TileWidth" },
837 { 0x143, "exif:TileLength" },
838 { 0x144, "exif:TileOffsets" },
839 { 0x145, "exif:TileByteCounts" },
840 { 0x14a, "exif:SubIFD" },
841 { 0x14c, "exif:InkSet" },
842 { 0x14d, "exif:InkNames" },
843 { 0x14e, "exif:NumberOfInks" },
844 { 0x150, "exif:DotRange" },
845 { 0x151, "exif:TargetPrinter" },
846 { 0x152, "exif:ExtraSample" },
847 { 0x153, "exif:SampleFormat" },
848 { 0x154, "exif:SMinSampleValue" },
849 { 0x155, "exif:SMaxSampleValue" },
850 { 0x156, "exif:TransferRange" },
851 { 0x157, "exif:ClipPath" },
852 { 0x158, "exif:XClipPathUnits" },
853 { 0x159, "exif:YClipPathUnits" },
854 { 0x15a, "exif:Indexed" },
855 { 0x15b, "exif:JPEGTables" },
856 { 0x15f, "exif:OPIProxy" },
857 { 0x200, "exif:JPEGProc" },
858 { 0x201, "exif:JPEGInterchangeFormat" },
859 { 0x202, "exif:JPEGInterchangeFormatLength" },
860 { 0x203, "exif:JPEGRestartInterval" },
861 { 0x205, "exif:JPEGLosslessPredictors" },
862 { 0x206, "exif:JPEGPointTransforms" },
863 { 0x207, "exif:JPEGQTables" },
864 { 0x208, "exif:JPEGDCTables" },
865 { 0x209, "exif:JPEGACTables" },
866 { 0x211, "exif:YCbCrCoefficients" },
867 { 0x212, "exif:YCbCrSubSampling" },
868 { 0x213, "exif:YCbCrPositioning" },
869 { 0x214, "exif:ReferenceBlackWhite" },
870 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
871 { 0x301, "exif:Gamma" },
872 { 0x302, "exif:ICCProfileDescriptor" },
873 { 0x303, "exif:SRGBRenderingIntent" },
874 { 0x320, "exif:ImageTitle" },
875 { 0x5001, "exif:ResolutionXUnit" },
876 { 0x5002, "exif:ResolutionYUnit" },
877 { 0x5003, "exif:ResolutionXLengthUnit" },
878 { 0x5004, "exif:ResolutionYLengthUnit" },
879 { 0x5005, "exif:PrintFlags" },
880 { 0x5006, "exif:PrintFlagsVersion" },
881 { 0x5007, "exif:PrintFlagsCrop" },
882 { 0x5008, "exif:PrintFlagsBleedWidth" },
883 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
884 { 0x500A, "exif:HalftoneLPI" },
885 { 0x500B, "exif:HalftoneLPIUnit" },
886 { 0x500C, "exif:HalftoneDegree" },
887 { 0x500D, "exif:HalftoneShape" },
888 { 0x500E, "exif:HalftoneMisc" },
889 { 0x500F, "exif:HalftoneScreen" },
890 { 0x5010, "exif:JPEGQuality" },
891 { 0x5011, "exif:GridSize" },
892 { 0x5012, "exif:ThumbnailFormat" },
893 { 0x5013, "exif:ThumbnailWidth" },
894 { 0x5014, "exif:ThumbnailHeight" },
895 { 0x5015, "exif:ThumbnailColorDepth" },
896 { 0x5016, "exif:ThumbnailPlanes" },
897 { 0x5017, "exif:ThumbnailRawBytes" },
898 { 0x5018, "exif:ThumbnailSize" },
899 { 0x5019, "exif:ThumbnailCompressedSize" },
900 { 0x501a, "exif:ColorTransferFunction" },
901 { 0x501b, "exif:ThumbnailData" },
902 { 0x5020, "exif:ThumbnailImageWidth" },
903 { 0x5021, "exif:ThumbnailImageHeight" },
904 { 0x5022, "exif:ThumbnailBitsPerSample" },
905 { 0x5023, "exif:ThumbnailCompression" },
906 { 0x5024, "exif:ThumbnailPhotometricInterp" },
907 { 0x5025, "exif:ThumbnailImageDescription" },
908 { 0x5026, "exif:ThumbnailEquipMake" },
909 { 0x5027, "exif:ThumbnailEquipModel" },
910 { 0x5028, "exif:ThumbnailStripOffsets" },
911 { 0x5029, "exif:ThumbnailOrientation" },
912 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
913 { 0x502b, "exif:ThumbnailRowsPerStrip" },
914 { 0x502c, "exif:ThumbnailStripBytesCount" },
915 { 0x502d, "exif:ThumbnailResolutionX" },
916 { 0x502e, "exif:ThumbnailResolutionY" },
917 { 0x502f, "exif:ThumbnailPlanarConfig" },
918 { 0x5030, "exif:ThumbnailResolutionUnit" },
919 { 0x5031, "exif:ThumbnailTransferFunction" },
920 { 0x5032, "exif:ThumbnailSoftwareUsed" },
921 { 0x5033, "exif:ThumbnailDateTime" },
922 { 0x5034, "exif:ThumbnailArtist" },
923 { 0x5035, "exif:ThumbnailWhitePoint" },
924 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
925 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
926 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
927 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
928 { 0x503A, "exif:ThumbnailRefBlackWhite" },
929 { 0x503B, "exif:ThumbnailCopyRight" },
930 { 0x5090, "exif:LuminanceTable" },
931 { 0x5091, "exif:ChrominanceTable" },
932 { 0x5100, "exif:FrameDelay" },
933 { 0x5101, "exif:LoopCount" },
934 { 0x5110, "exif:PixelUnit" },
935 { 0x5111, "exif:PixelPerUnitX" },
936 { 0x5112, "exif:PixelPerUnitY" },
937 { 0x5113, "exif:PaletteHistogram" },
938 { 0x1000, "exif:RelatedImageFileFormat" },
939 { 0x1001, "exif:RelatedImageLength" },
940 { 0x1002, "exif:RelatedImageWidth" },
941 { 0x800d, "exif:ImageID" },
942 { 0x80e3, "exif:Matteing" },
943 { 0x80e4, "exif:DataType" },
944 { 0x80e5, "exif:ImageDepth" },
945 { 0x80e6, "exif:TileDepth" },
946 { 0x828d, "exif:CFARepeatPatternDim" },
947 { 0x828e, "exif:CFAPattern2" },
948 { 0x828f, "exif:BatteryLevel" },
949 { 0x8298, "exif:Copyright" },
950 { 0x829a, "exif:ExposureTime" },
951 { 0x829d, "exif:FNumber" },
952 { 0x83bb, "exif:IPTC/NAA" },
953 { 0x84e3, "exif:IT8RasterPadding" },
954 { 0x84e5, "exif:IT8ColorTable" },
955 { 0x8649, "exif:ImageResourceInformation" },
956 { 0x8769, "exif:ExifOffset" },
957 { 0x8773, "exif:InterColorProfile" },
958 { 0x8822, "exif:ExposureProgram" },
959 { 0x8824, "exif:SpectralSensitivity" },
960 { 0x8825, "exif:GPSInfo" },
961 { 0x8827, "exif:ISOSpeedRatings" },
962 { 0x8828, "exif:OECF" },
963 { 0x8829, "exif:Interlace" },
964 { 0x882a, "exif:TimeZoneOffset" },
965 { 0x882b, "exif:SelfTimerMode" },
966 { 0x9000, "exif:ExifVersion" },
967 { 0x9003, "exif:DateTimeOriginal" },
968 { 0x9004, "exif:DateTimeDigitized" },
969 { 0x9101, "exif:ComponentsConfiguration" },
970 { 0x9102, "exif:CompressedBitsPerPixel" },
971 { 0x9201, "exif:ShutterSpeedValue" },
972 { 0x9202, "exif:ApertureValue" },
973 { 0x9203, "exif:BrightnessValue" },
974 { 0x9204, "exif:ExposureBiasValue" },
975 { 0x9205, "exif:MaxApertureValue" },
976 { 0x9206, "exif:SubjectDistance" },
977 { 0x9207, "exif:MeteringMode" },
978 { 0x9208, "exif:LightSource" },
979 { 0x9209, "exif:Flash" },
980 { 0x920a, "exif:FocalLength" },
981 { 0x920b, "exif:FlashEnergy" },
982 { 0x920c, "exif:SpatialFrequencyResponse" },
983 { 0x920d, "exif:Noise" },
984 { 0x9211, "exif:ImageNumber" },
985 { 0x9212, "exif:SecurityClassification" },
986 { 0x9213, "exif:ImageHistory" },
987 { 0x9214, "exif:SubjectArea" },
988 { 0x9215, "exif:ExposureIndex" },
989 { 0x9216, "exif:TIFF-EPStandardID" },
990 { 0x927c, "exif:MakerNote" },
991 { 0x9C9b, "exif:WinXP-Title" },
992 { 0x9C9c, "exif:WinXP-Comments" },
993 { 0x9C9d, "exif:WinXP-Author" },
994 { 0x9C9e, "exif:WinXP-Keywords" },
995 { 0x9C9f, "exif:WinXP-Subject" },
996 { 0x9286, "exif:UserComment" },
997 { 0x9290, "exif:SubSecTime" },
998 { 0x9291, "exif:SubSecTimeOriginal" },
999 { 0x9292, "exif:SubSecTimeDigitized" },
1000 { 0xa000, "exif:FlashPixVersion" },
1001 { 0xa001, "exif:ColorSpace" },
1002 { 0xa002, "exif:ExifImageWidth" },
1003 { 0xa003, "exif:ExifImageLength" },
1004 { 0xa004, "exif:RelatedSoundFile" },
1005 { 0xa005, "exif:InteroperabilityOffset" },
1006 { 0xa20b, "exif:FlashEnergy" },
1007 { 0xa20c, "exif:SpatialFrequencyResponse" },
1008 { 0xa20d, "exif:Noise" },
1009 { 0xa20e, "exif:FocalPlaneXResolution" },
1010 { 0xa20f, "exif:FocalPlaneYResolution" },
1011 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1012 { 0xa214, "exif:SubjectLocation" },
1013 { 0xa215, "exif:ExposureIndex" },
1014 { 0xa216, "exif:TIFF/EPStandardID" },
1015 { 0xa217, "exif:SensingMethod" },
1016 { 0xa300, "exif:FileSource" },
1017 { 0xa301, "exif:SceneType" },
1018 { 0xa302, "exif:CFAPattern" },
1019 { 0xa401, "exif:CustomRendered" },
1020 { 0xa402, "exif:ExposureMode" },
1021 { 0xa403, "exif:WhiteBalance" },
1022 { 0xa404, "exif:DigitalZoomRatio" },
1023 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1024 { 0xa406, "exif:SceneCaptureType" },
1025 { 0xa407, "exif:GainControl" },
1026 { 0xa408, "exif:Contrast" },
1027 { 0xa409, "exif:Saturation" },
1028 { 0xa40a, "exif:Sharpness" },
1029 { 0xa40b, "exif:DeviceSettingDescription" },
1030 { 0xa40c, "exif:SubjectDistanceRange" },
1031 { 0xa420, "exif:ImageUniqueID" },
1032 { 0xc4a5, "exif:PrintImageMatching" },
cristyb3fea0e2009-11-28 01:46:20 +00001033 { 0xa500, "exif:Gamma" },
1034 { 0xc640, "exif:CR2Slice" },
cristy3ed852e2009-09-05 21:47:34 +00001035 { 0x10000, "exif:GPSVersionID" },
1036 { 0x10001, "exif:GPSLatitudeRef" },
1037 { 0x10002, "exif:GPSLatitude" },
1038 { 0x10003, "exif:GPSLongitudeRef" },
1039 { 0x10004, "exif:GPSLongitude" },
1040 { 0x10005, "exif:GPSAltitudeRef" },
1041 { 0x10006, "exif:GPSAltitude" },
1042 { 0x10007, "exif:GPSTimeStamp" },
1043 { 0x10008, "exif:GPSSatellites" },
1044 { 0x10009, "exif:GPSStatus" },
1045 { 0x1000a, "exif:GPSMeasureMode" },
1046 { 0x1000b, "exif:GPSDop" },
1047 { 0x1000c, "exif:GPSSpeedRef" },
1048 { 0x1000d, "exif:GPSSpeed" },
1049 { 0x1000e, "exif:GPSTrackRef" },
1050 { 0x1000f, "exif:GPSTrack" },
1051 { 0x10010, "exif:GPSImgDirectionRef" },
1052 { 0x10011, "exif:GPSImgDirection" },
1053 { 0x10012, "exif:GPSMapDatum" },
1054 { 0x10013, "exif:GPSDestLatitudeRef" },
1055 { 0x10014, "exif:GPSDestLatitude" },
1056 { 0x10015, "exif:GPSDestLongitudeRef" },
1057 { 0x10016, "exif:GPSDestLongitude" },
1058 { 0x10017, "exif:GPSDestBearingRef" },
1059 { 0x10018, "exif:GPSDestBearing" },
1060 { 0x10019, "exif:GPSDestDistanceRef" },
1061 { 0x1001a, "exif:GPSDestDistance" },
1062 { 0x1001b, "exif:GPSProcessingMethod" },
1063 { 0x1001c, "exif:GPSAreaInformation" },
1064 { 0x1001d, "exif:GPSDateStamp" },
1065 { 0x1001e, "exif:GPSDifferential" },
1066 { 0x0000, NULL}
1067 };
1068
1069 const StringInfo
1070 *profile;
1071
1072 const unsigned char
1073 *directory,
1074 *exif;
1075
1076 DirectoryInfo
1077 directory_stack[MaxDirectoryStack];
1078
1079 EndianType
1080 endian;
1081
cristy929ea322011-02-21 15:21:35 +00001082 MagickBooleanType
1083 status;
cristy3ed852e2009-09-05 21:47:34 +00001084
cristybb503372010-05-27 20:51:26 +00001085 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001086 i;
1087
1088 size_t
cristy3ed852e2009-09-05 21:47:34 +00001089 entry,
cristy929ea322011-02-21 15:21:35 +00001090 length,
cristy3ed852e2009-09-05 21:47:34 +00001091 number_entries,
1092 tag_offset,
1093 tag;
1094
cristy929ea322011-02-21 15:21:35 +00001095 ssize_t
1096 all,
1097 id,
1098 level,
1099 offset,
1100 tag_value;
1101
1102 static int
1103 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1104
cristy3ed852e2009-09-05 21:47:34 +00001105 /*
1106 If EXIF data exists, then try to parse the request for a tag.
1107 */
1108 profile=GetImageProfile(image,"exif");
1109 if (profile == (StringInfo *) NULL)
1110 return(MagickFalse);
1111 if ((property == (const char *) NULL) || (*property == '\0'))
1112 return(MagickFalse);
1113 while (isspace((int) ((unsigned char) *property)) != 0)
1114 property++;
1115 all=0;
1116 tag=(~0UL);
1117 switch (*(property+5))
1118 {
1119 case '*':
1120 {
1121 /*
1122 Caller has asked for all the tags in the EXIF data.
1123 */
1124 tag=0;
1125 all=1; /* return the data in description=value format */
1126 break;
1127 }
1128 case '!':
1129 {
1130 tag=0;
1131 all=2; /* return the data in tagid=value format */
1132 break;
1133 }
1134 case '#':
1135 case '@':
1136 {
1137 int
1138 c;
1139
1140 size_t
1141 n;
1142
1143 /*
1144 Check for a hex based tag specification first.
1145 */
1146 tag=(*(property+5) == '@') ? 1UL : 0UL;
1147 property+=6;
1148 n=strlen(property);
1149 if (n != 4)
1150 return(MagickFalse);
1151 /*
1152 Parse tag specification as a hex number.
1153 */
1154 n/=4;
1155 do
1156 {
cristybb503372010-05-27 20:51:26 +00001157 for (i=(ssize_t) n-1L; i >= 0; i--)
cristy3ed852e2009-09-05 21:47:34 +00001158 {
1159 c=(*property++);
1160 tag<<=4;
1161 if ((c >= '0') && (c <= '9'))
1162 tag|=(c-'0');
1163 else
1164 if ((c >= 'A') && (c <= 'F'))
1165 tag|=(c-('A'-10));
1166 else
1167 if ((c >= 'a') && (c <= 'f'))
1168 tag|=(c-('a'-10));
1169 else
1170 return(MagickFalse);
1171 }
1172 } while (*property != '\0');
1173 break;
1174 }
1175 default:
1176 {
1177 /*
1178 Try to match the text with a tag name instead.
1179 */
1180 for (i=0; ; i++)
1181 {
1182 if (EXIFTag[i].tag == 0)
1183 break;
1184 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1185 {
cristybb503372010-05-27 20:51:26 +00001186 tag=(size_t) EXIFTag[i].tag;
cristy3ed852e2009-09-05 21:47:34 +00001187 break;
1188 }
1189 }
1190 break;
1191 }
1192 }
1193 if (tag == (~0UL))
1194 return(MagickFalse);
1195 length=GetStringInfoLength(profile);
1196 exif=GetStringInfoDatum(profile);
1197 while (length != 0)
1198 {
1199 if (ReadPropertyByte(&exif,&length) != 0x45)
1200 continue;
1201 if (ReadPropertyByte(&exif,&length) != 0x78)
1202 continue;
1203 if (ReadPropertyByte(&exif,&length) != 0x69)
1204 continue;
1205 if (ReadPropertyByte(&exif,&length) != 0x66)
1206 continue;
1207 if (ReadPropertyByte(&exif,&length) != 0x00)
1208 continue;
1209 if (ReadPropertyByte(&exif,&length) != 0x00)
1210 continue;
1211 break;
1212 }
1213 if (length < 16)
1214 return(MagickFalse);
cristybb503372010-05-27 20:51:26 +00001215 id=(ssize_t) ReadPropertyShort(LSBEndian,exif);
cristy3ed852e2009-09-05 21:47:34 +00001216 endian=LSBEndian;
1217 if (id == 0x4949)
1218 endian=LSBEndian;
1219 else
1220 if (id == 0x4D4D)
1221 endian=MSBEndian;
1222 else
1223 return(MagickFalse);
1224 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1225 return(MagickFalse);
1226 /*
1227 This the offset to the first IFD.
1228 */
cristy55a91cd2010-12-01 00:57:40 +00001229 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
cristy3ed852e2009-09-05 21:47:34 +00001230 if ((size_t) offset >= length)
1231 return(MagickFalse);
1232 /*
1233 Set the pointer to the first IFD and follow it were it leads.
1234 */
cristy929ea322011-02-21 15:21:35 +00001235 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00001236 directory=exif+offset;
1237 level=0;
1238 entry=0;
1239 tag_offset=0;
1240 do
1241 {
1242 /*
1243 If there is anything on the stack then pop it off.
1244 */
1245 if (level > 0)
1246 {
1247 level--;
1248 directory=directory_stack[level].directory;
1249 entry=directory_stack[level].entry;
1250 tag_offset=directory_stack[level].offset;
1251 }
1252 /*
1253 Determine how many entries there are in the current IFD.
1254 */
1255 number_entries=ReadPropertyShort(endian,directory);
1256 for ( ; entry < number_entries; entry++)
1257 {
cristy3ed852e2009-09-05 21:47:34 +00001258 register unsigned char
1259 *p,
1260 *q;
1261
1262 size_t
cristy9d314ff2011-03-09 01:30:28 +00001263 format,
cristy3ed852e2009-09-05 21:47:34 +00001264 number_bytes;
1265
cristy9d314ff2011-03-09 01:30:28 +00001266 ssize_t
1267 components;
cristy3ed852e2009-09-05 21:47:34 +00001268
1269 q=(unsigned char *) (directory+2+(12*entry));
cristyeaedf062010-05-29 22:36:02 +00001270 tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);
cristybb503372010-05-27 20:51:26 +00001271 format=(size_t) ReadPropertyShort(endian,q+2);
cristy3ed852e2009-09-05 21:47:34 +00001272 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1273 break;
cristy55a91cd2010-12-01 00:57:40 +00001274 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
cristy3ed852e2009-09-05 21:47:34 +00001275 number_bytes=(size_t) components*tag_bytes[format];
1276 if (number_bytes <= 4)
1277 p=q+8;
1278 else
1279 {
1280 ssize_t
1281 offset;
1282
1283 /*
1284 The directory entry contains an offset.
1285 */
cristy55a91cd2010-12-01 00:57:40 +00001286 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
cristy3ed852e2009-09-05 21:47:34 +00001287 if ((size_t) (offset+number_bytes) > length)
1288 continue;
1289 p=(unsigned char *) (exif+offset);
1290 }
cristybb503372010-05-27 20:51:26 +00001291 if ((all != 0) || (tag == (size_t) tag_value))
cristy3ed852e2009-09-05 21:47:34 +00001292 {
1293 char
1294 buffer[MaxTextExtent],
1295 *value;
1296
1297 switch (format)
1298 {
1299 case EXIF_FMT_BYTE:
1300 case EXIF_FMT_UNDEFINED:
1301 {
cristy13adad02011-08-16 19:22:15 +00001302 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
cristy3ed852e2009-09-05 21:47:34 +00001303 break;
1304 }
1305 case EXIF_FMT_SBYTE:
1306 {
cristye8c25f92010-06-03 00:53:06 +00001307 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
cristy3ed852e2009-09-05 21:47:34 +00001308 break;
1309 }
1310 case EXIF_FMT_SSHORT:
1311 {
1312 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1313 break;
1314 }
1315 case EXIF_FMT_USHORT:
1316 {
1317 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1318 break;
1319 }
1320 case EXIF_FMT_ULONG:
1321 {
cristye8c25f92010-06-03 00:53:06 +00001322 EXIFMultipleValues(4,"%.20g",(double)
1323 ReadPropertyLong(endian,p1));
cristy3ed852e2009-09-05 21:47:34 +00001324 break;
1325 }
1326 case EXIF_FMT_SLONG:
1327 {
cristye8c25f92010-06-03 00:53:06 +00001328 EXIFMultipleValues(4,"%.20g",(double)
1329 ReadPropertyLong(endian,p1));
cristy3ed852e2009-09-05 21:47:34 +00001330 break;
1331 }
1332 case EXIF_FMT_URATIONAL:
1333 {
cristye8c25f92010-06-03 00:53:06 +00001334 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1335 ReadPropertyLong(endian,p1),(double)
cristy3ed852e2009-09-05 21:47:34 +00001336 ReadPropertyLong(endian,p1+4));
1337 break;
1338 }
1339 case EXIF_FMT_SRATIONAL:
1340 {
cristye8c25f92010-06-03 00:53:06 +00001341 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1342 ReadPropertyLong(endian,p1),(double)
cristy3ed852e2009-09-05 21:47:34 +00001343 ReadPropertyLong(endian,p1+4));
1344 break;
1345 }
1346 case EXIF_FMT_SINGLE:
1347 {
1348 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1349 break;
1350 }
1351 case EXIF_FMT_DOUBLE:
1352 {
1353 EXIFMultipleValues(8,"%f",*(double *) p1);
1354 break;
1355 }
1356 default:
1357 case EXIF_FMT_STRING:
1358 {
1359 value=(char *) NULL;
1360 if (~(1UL*number_bytes) >= 1)
1361 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1362 sizeof(*value));
1363 if (value != (char *) NULL)
1364 {
cristybb503372010-05-27 20:51:26 +00001365 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001366 i;
1367
cristybb503372010-05-27 20:51:26 +00001368 for (i=0; i < (ssize_t) number_bytes; i++)
cristy3ed852e2009-09-05 21:47:34 +00001369 {
1370 value[i]='.';
1371 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1372 value[i]=(char) p[i];
1373 }
1374 value[i]='\0';
1375 }
1376 break;
1377 }
1378 }
1379 if (value != (char *) NULL)
1380 {
1381 char
1382 key[MaxTextExtent];
1383
1384 register const char
1385 *p;
1386
1387 (void) CopyMagickString(key,property,MaxTextExtent);
1388 switch (all)
1389 {
1390 case 1:
1391 {
1392 const char
1393 *description;
1394
cristybb503372010-05-27 20:51:26 +00001395 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001396 i;
1397
1398 description="unknown";
1399 for (i=0; ; i++)
1400 {
1401 if (EXIFTag[i].tag == 0)
1402 break;
cristybb503372010-05-27 20:51:26 +00001403 if ((ssize_t) EXIFTag[i].tag == tag_value)
cristy3ed852e2009-09-05 21:47:34 +00001404 {
1405 description=EXIFTag[i].description;
1406 break;
1407 }
1408 }
cristyb51dff52011-05-19 16:55:47 +00001409 (void) FormatLocaleString(key,MaxTextExtent,"%s",
cristy3ed852e2009-09-05 21:47:34 +00001410 description);
1411 break;
1412 }
1413 case 2:
1414 {
1415 if (tag_value < 0x10000)
cristyb51dff52011-05-19 16:55:47 +00001416 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
cristyf2faecf2010-05-28 19:19:36 +00001417 (unsigned long) tag_value);
cristy3ed852e2009-09-05 21:47:34 +00001418 else
1419 if (tag_value < 0x20000)
cristyb51dff52011-05-19 16:55:47 +00001420 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
cristyf2faecf2010-05-28 19:19:36 +00001421 (unsigned long) (tag_value & 0xffff));
cristy3ed852e2009-09-05 21:47:34 +00001422 else
cristyb51dff52011-05-19 16:55:47 +00001423 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
cristy3ed852e2009-09-05 21:47:34 +00001424 break;
1425 }
1426 }
1427 p=(const char *) NULL;
1428 if (image->properties != (void *) NULL)
1429 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1430 image->properties,key);
1431 if (p == (const char *) NULL)
1432 (void) SetImageProperty((Image *) image,key,value);
1433 value=DestroyString(value);
cristy929ea322011-02-21 15:21:35 +00001434 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001435 }
1436 }
1437 if ((tag_value == TAG_EXIF_OFFSET) ||
1438 (tag_value == TAG_INTEROP_OFFSET) ||
1439 (tag_value == TAG_GPS_OFFSET))
1440 {
1441 size_t
1442 offset;
1443
1444 offset=(size_t) ReadPropertyLong(endian,p);
1445 if ((offset < length) && (level < (MaxDirectoryStack-2)))
1446 {
cristybb503372010-05-27 20:51:26 +00001447 size_t
cristy3ed852e2009-09-05 21:47:34 +00001448 tag_offset1;
1449
1450 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1451 directory_stack[level].directory=directory;
1452 entry++;
1453 directory_stack[level].entry=entry;
1454 directory_stack[level].offset=tag_offset;
1455 level++;
1456 directory_stack[level].directory=exif+offset;
1457 directory_stack[level].offset=tag_offset1;
1458 directory_stack[level].entry=0;
1459 level++;
1460 if ((directory+2+(12*number_entries)) > (exif+length))
1461 break;
1462 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1463 number_entries));
1464 if ((offset != 0) && (offset < length) &&
1465 (level < (MaxDirectoryStack-2)))
1466 {
1467 directory_stack[level].directory=exif+offset;
1468 directory_stack[level].entry=0;
1469 directory_stack[level].offset=tag_offset1;
1470 level++;
1471 }
1472 }
1473 break;
1474 }
1475 }
1476 } while (level > 0);
cristy929ea322011-02-21 15:21:35 +00001477 return(status);
cristy3ed852e2009-09-05 21:47:34 +00001478}
1479
cristy13adad02011-08-16 19:22:15 +00001480static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
cristy3ed852e2009-09-05 21:47:34 +00001481{
1482 char
1483 *xmp_profile;
1484
1485 const StringInfo
1486 *profile;
1487
1488 ExceptionInfo
1489 *exception;
1490
1491 MagickBooleanType
1492 status;
1493
1494 register const char
1495 *p;
1496
1497 XMLTreeInfo
1498 *child,
1499 *description,
1500 *node,
1501 *rdf,
1502 *xmp;
1503
1504 profile=GetImageProfile(image,"xmp");
1505 if (profile == (StringInfo *) NULL)
1506 return(MagickFalse);
1507 if ((property == (const char *) NULL) || (*property == '\0'))
1508 return(MagickFalse);
1509 xmp_profile=StringInfoToString(profile);
1510 if (xmp_profile == (char *) NULL)
1511 return(MagickFalse);
1512 for (p=xmp_profile; *p != '\0'; p++)
1513 if ((*p == '<') && (*(p+1) == 'x'))
1514 break;
1515 exception=AcquireExceptionInfo();
1516 xmp=NewXMLTree((char *) p,exception);
1517 xmp_profile=DestroyString(xmp_profile);
1518 exception=DestroyExceptionInfo(exception);
1519 if (xmp == (XMLTreeInfo *) NULL)
1520 return(MagickFalse);
1521 status=MagickFalse;
1522 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1523 if (rdf != (XMLTreeInfo *) NULL)
1524 {
1525 if (image->properties == (void *) NULL)
1526 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1527 RelinquishMagickMemory,RelinquishMagickMemory);
1528 description=GetXMLTreeChild(rdf,"rdf:Description");
1529 while (description != (XMLTreeInfo *) NULL)
1530 {
1531 node=GetXMLTreeChild(description,(const char *) NULL);
1532 while (node != (XMLTreeInfo *) NULL)
1533 {
1534 child=GetXMLTreeChild(node,(const char *) NULL);
1535 if (child == (XMLTreeInfo *) NULL)
1536 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1537 ConstantString(GetXMLTreeTag(node)),
1538 ConstantString(GetXMLTreeContent(node)));
1539 while (child != (XMLTreeInfo *) NULL)
1540 {
1541 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1542 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1543 ConstantString(GetXMLTreeTag(child)),
1544 ConstantString(GetXMLTreeContent(child)));
1545 child=GetXMLTreeSibling(child);
1546 }
1547 node=GetXMLTreeSibling(node);
1548 }
1549 description=GetNextXMLTreeTag(description);
1550 }
1551 }
1552 xmp=DestroyXMLTree(xmp);
1553 return(status);
1554}
1555
1556static char *TracePSClippath(const unsigned char *blob,size_t length,
cristybb503372010-05-27 20:51:26 +00001557 const size_t magick_unused(columns),
1558 const size_t magick_unused(rows))
cristy3ed852e2009-09-05 21:47:34 +00001559{
1560 char
1561 *path,
1562 *message;
1563
cristy3ed852e2009-09-05 21:47:34 +00001564 MagickBooleanType
1565 in_subpath;
1566
1567 PointInfo
1568 first[3],
1569 last[3],
1570 point[3];
1571
cristybb503372010-05-27 20:51:26 +00001572 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001573 i,
1574 x;
1575
cristy9d314ff2011-03-09 01:30:28 +00001576 ssize_t
1577 knot_count,
1578 selector,
1579 y;
1580
cristy3ed852e2009-09-05 21:47:34 +00001581 path=AcquireString((char *) NULL);
1582 if (path == (char *) NULL)
1583 return((char *) NULL);
1584 message=AcquireString((char *) NULL);
cristyb51dff52011-05-19 16:55:47 +00001585 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
cristy3ed852e2009-09-05 21:47:34 +00001586 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001587 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
cristy3ed852e2009-09-05 21:47:34 +00001588 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001589 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
cristy3ed852e2009-09-05 21:47:34 +00001590 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001591 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
cristy3ed852e2009-09-05 21:47:34 +00001592 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001593 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
cristy3ed852e2009-09-05 21:47:34 +00001594 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001595 (void) FormatLocaleString(message,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001596 " /v {currentpoint 6 2 roll curveto} bind def\n");
1597 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001598 (void) FormatLocaleString(message,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001599 " /y {2 copy curveto} bind def\n");
1600 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001601 (void) FormatLocaleString(message,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001602 " /z {closepath} bind def\n");
1603 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001604 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
cristy3ed852e2009-09-05 21:47:34 +00001605 (void) ConcatenateString(&path,message);
1606 /*
1607 The clipping path format is defined in "Adobe Photoshop File
1608 Formats Specification" version 6.0 downloadable from adobe.com.
1609 */
1610 (void) ResetMagickMemory(point,0,sizeof(point));
1611 (void) ResetMagickMemory(first,0,sizeof(first));
1612 (void) ResetMagickMemory(last,0,sizeof(last));
1613 knot_count=0;
1614 in_subpath=MagickFalse;
1615 while (length > 0)
1616 {
cristybb503372010-05-27 20:51:26 +00001617 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
cristy3ed852e2009-09-05 21:47:34 +00001618 switch (selector)
1619 {
1620 case 0:
1621 case 3:
1622 {
1623 if (knot_count != 0)
1624 {
1625 blob+=24;
1626 length-=24;
1627 break;
1628 }
1629 /*
1630 Expected subpath length record.
1631 */
cristybb503372010-05-27 20:51:26 +00001632 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
cristy3ed852e2009-09-05 21:47:34 +00001633 blob+=22;
1634 length-=22;
1635 break;
1636 }
1637 case 1:
1638 case 2:
1639 case 4:
1640 case 5:
1641 {
1642 if (knot_count == 0)
1643 {
1644 /*
1645 Unexpected subpath knot
1646 */
1647 blob+=24;
1648 length-=24;
1649 break;
1650 }
1651 /*
1652 Add sub-path knot
1653 */
1654 for (i=0; i < 3; i++)
1655 {
cristy13b9a2e2010-11-10 14:03:51 +00001656 size_t
cristy97433202009-10-27 02:05:08 +00001657 xx,
1658 yy;
1659
1660 yy=ReadPropertyMSBLong(&blob,&length);
1661 xx=ReadPropertyMSBLong(&blob,&length);
cristybb503372010-05-27 20:51:26 +00001662 x=(ssize_t) xx;
cristy97433202009-10-27 02:05:08 +00001663 if (xx > 2147483647)
cristy17df8572011-05-25 16:39:58 +00001664 x=(ssize_t) xx-4294967295U-1;
cristybb503372010-05-27 20:51:26 +00001665 y=(ssize_t) yy;
cristy97433202009-10-27 02:05:08 +00001666 if (yy > 2147483647)
cristy17df8572011-05-25 16:39:58 +00001667 y=(ssize_t) yy-4294967295U-1;
cristy3ed852e2009-09-05 21:47:34 +00001668 point[i].x=(double) x/4096/4096;
1669 point[i].y=1.0-(double) y/4096/4096;
1670 }
1671 if (in_subpath == MagickFalse)
1672 {
cristyb51dff52011-05-19 16:55:47 +00001673 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
cristy3ed852e2009-09-05 21:47:34 +00001674 point[1].x,point[1].y);
1675 for (i=0; i < 3; i++)
1676 {
1677 first[i]=point[i];
1678 last[i]=point[i];
1679 }
1680 }
1681 else
1682 {
1683 /*
1684 Handle special cases when Bezier curves are used to describe
1685 corners and straight lines.
1686 */
1687 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1688 (point[0].x == point[1].x) && (point[0].y == point[1].y))
cristyb51dff52011-05-19 16:55:47 +00001689 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001690 " %g %g l\n",point[1].x,point[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001691 else
1692 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
cristyb51dff52011-05-19 16:55:47 +00001693 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001694 " %g %g %g %g v\n",point[0].x,point[0].y,
cristy8cd5b312010-01-07 01:10:24 +00001695 point[1].x,point[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001696 else
1697 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
cristyb51dff52011-05-19 16:55:47 +00001698 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001699 " %g %g %g %g y\n",last[2].x,last[2].y,
cristy8cd5b312010-01-07 01:10:24 +00001700 point[1].x,point[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001701 else
cristyb51dff52011-05-19 16:55:47 +00001702 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001703 " %g %g %g %g %g %g c\n",last[2].x,
cristy8cd5b312010-01-07 01:10:24 +00001704 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001705 for (i=0; i < 3; i++)
1706 last[i]=point[i];
1707 }
1708 (void) ConcatenateString(&path,message);
1709 in_subpath=MagickTrue;
1710 knot_count--;
1711 /*
1712 Close the subpath if there are no more knots.
1713 */
1714 if (knot_count == 0)
1715 {
1716 /*
1717 Same special handling as above except we compare to the
1718 first point in the path and close the path.
1719 */
1720 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1721 (first[0].x == first[1].x) && (first[0].y == first[1].y))
cristyb51dff52011-05-19 16:55:47 +00001722 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001723 " %g %g l z\n",first[1].x,first[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001724 else
1725 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
cristyb51dff52011-05-19 16:55:47 +00001726 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001727 " %g %g %g %g v z\n",first[0].x,first[0].y,
cristy8cd5b312010-01-07 01:10:24 +00001728 first[1].x,first[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001729 else
1730 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
cristyb51dff52011-05-19 16:55:47 +00001731 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001732 " %g %g %g %g y z\n",last[2].x,last[2].y,
cristy8cd5b312010-01-07 01:10:24 +00001733 first[1].x,first[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001734 else
cristyb51dff52011-05-19 16:55:47 +00001735 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001736 " %g %g %g %g %g %g c z\n",last[2].x,
cristy8cd5b312010-01-07 01:10:24 +00001737 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001738 (void) ConcatenateString(&path,message);
1739 in_subpath=MagickFalse;
1740 }
1741 break;
1742 }
1743 case 6:
1744 case 7:
1745 case 8:
1746 default:
1747 {
1748 blob+=24;
1749 length-=24;
1750 break;
1751 }
1752 }
1753 }
1754 /*
1755 Returns an empty PS path if the path has no knots.
1756 */
cristyb51dff52011-05-19 16:55:47 +00001757 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
cristy3ed852e2009-09-05 21:47:34 +00001758 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001759 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
cristy3ed852e2009-09-05 21:47:34 +00001760 (void) ConcatenateString(&path,message);
1761 message=DestroyString(message);
1762 return(path);
1763}
1764
1765static char *TraceSVGClippath(const unsigned char *blob,size_t length,
cristybb503372010-05-27 20:51:26 +00001766 const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00001767{
1768 char
1769 *path,
1770 *message;
1771
cristy3ed852e2009-09-05 21:47:34 +00001772 MagickBooleanType
1773 in_subpath;
1774
1775 PointInfo
1776 first[3],
1777 last[3],
1778 point[3];
1779
cristybb503372010-05-27 20:51:26 +00001780 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001781 i;
1782
cristy9d314ff2011-03-09 01:30:28 +00001783 ssize_t
1784 knot_count,
1785 selector,
1786 x,
1787 y;
1788
cristy3ed852e2009-09-05 21:47:34 +00001789 path=AcquireString((char *) NULL);
1790 if (path == (char *) NULL)
1791 return((char *) NULL);
1792 message=AcquireString((char *) NULL);
cristyb51dff52011-05-19 16:55:47 +00001793 (void) FormatLocaleString(message,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001794 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1795 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001796 (void) FormatLocaleString(message,MaxTextExtent,
cristye8c25f92010-06-03 00:53:06 +00001797 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
cristy3ed852e2009-09-05 21:47:34 +00001798 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001799 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
cristy3ed852e2009-09-05 21:47:34 +00001800 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001801 (void) FormatLocaleString(message,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001802 "<path style=\"fill:#00000000;stroke:#00000000;");
1803 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001804 (void) FormatLocaleString(message,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +00001805 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1806 (void) ConcatenateString(&path,message);
1807 (void) ResetMagickMemory(point,0,sizeof(point));
1808 (void) ResetMagickMemory(first,0,sizeof(first));
1809 (void) ResetMagickMemory(last,0,sizeof(last));
1810 knot_count=0;
1811 in_subpath=MagickFalse;
1812 while (length != 0)
1813 {
cristybb503372010-05-27 20:51:26 +00001814 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
cristy3ed852e2009-09-05 21:47:34 +00001815 switch (selector)
1816 {
1817 case 0:
1818 case 3:
1819 {
1820 if (knot_count != 0)
1821 {
1822 blob+=24;
1823 length-=24;
1824 break;
1825 }
1826 /*
1827 Expected subpath length record.
1828 */
cristybb503372010-05-27 20:51:26 +00001829 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
cristy3ed852e2009-09-05 21:47:34 +00001830 blob+=22;
1831 length-=22;
1832 break;
1833 }
1834 case 1:
1835 case 2:
1836 case 4:
1837 case 5:
1838 {
1839 if (knot_count == 0)
1840 {
1841 /*
1842 Unexpected subpath knot.
1843 */
1844 blob+=24;
1845 length-=24;
cristy97433202009-10-27 02:05:08 +00001846 break;
1847 }
1848 /*
1849 Add sub-path knot
1850 */
1851 for (i=0; i < 3; i++)
1852 {
cristyd4982b42011-03-21 14:24:23 +00001853 size_t
cristy97433202009-10-27 02:05:08 +00001854 xx,
1855 yy;
1856
1857 yy=ReadPropertyMSBLong(&blob,&length);
1858 xx=ReadPropertyMSBLong(&blob,&length);
cristybb503372010-05-27 20:51:26 +00001859 x=(ssize_t) xx;
cristy97433202009-10-27 02:05:08 +00001860 if (xx > 2147483647)
cristy17df8572011-05-25 16:39:58 +00001861 x=(ssize_t) xx-4294967295U-1;
cristybb503372010-05-27 20:51:26 +00001862 y=(ssize_t) yy;
cristy97433202009-10-27 02:05:08 +00001863 if (yy > 2147483647)
cristy17df8572011-05-25 16:39:58 +00001864 y=(ssize_t) yy-4294967295U-1;
cristy97433202009-10-27 02:05:08 +00001865 point[i].x=(double) x*columns/4096/4096;
1866 point[i].y=(double) y*rows/4096/4096;
1867 }
1868 if (in_subpath == MagickFalse)
1869 {
cristyb51dff52011-05-19 16:55:47 +00001870 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
cristy97433202009-10-27 02:05:08 +00001871 point[1].x,point[1].y);
1872 for (i=0; i < 3; i++)
1873 {
1874 first[i]=point[i];
1875 last[i]=point[i];
1876 }
cristy3ed852e2009-09-05 21:47:34 +00001877 }
1878 else
1879 {
cristy97433202009-10-27 02:05:08 +00001880 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1881 (point[0].x == point[1].x) && (point[0].y == point[1].y))
cristyb51dff52011-05-19 16:55:47 +00001882 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
cristy97433202009-10-27 02:05:08 +00001883 point[1].x,point[1].y);
1884 else
cristyb51dff52011-05-19 16:55:47 +00001885 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001886 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
cristy97433202009-10-27 02:05:08 +00001887 point[0].x,point[0].y,point[1].x,point[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001888 for (i=0; i < 3; i++)
cristy97433202009-10-27 02:05:08 +00001889 last[i]=point[i];
1890 }
1891 (void) ConcatenateString(&path,message);
1892 in_subpath=MagickTrue;
1893 knot_count--;
1894 /*
1895 Close the subpath if there are no more knots.
1896 */
1897 if (knot_count == 0)
1898 {
1899 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1900 (first[0].x == first[1].x) && (first[0].y == first[1].y))
cristyb51dff52011-05-19 16:55:47 +00001901 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001902 "L %g,%g Z\n",first[1].x,first[1].y);
cristy3ed852e2009-09-05 21:47:34 +00001903 else
1904 {
cristyb51dff52011-05-19 16:55:47 +00001905 (void) FormatLocaleString(message,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00001906 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
cristy8cd5b312010-01-07 01:10:24 +00001907 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
cristy97433202009-10-27 02:05:08 +00001908 (void) ConcatenateString(&path,message);
cristy3ed852e2009-09-05 21:47:34 +00001909 }
cristy97433202009-10-27 02:05:08 +00001910 in_subpath=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00001911 }
cristy97433202009-10-27 02:05:08 +00001912 break;
cristy3ed852e2009-09-05 21:47:34 +00001913 }
1914 case 6:
1915 case 7:
1916 case 8:
1917 default:
1918 {
1919 blob+=24;
1920 length-=24;
1921 break;
1922 }
1923 }
1924 }
1925 /*
1926 Return an empty SVG image if the path does not have knots.
1927 */
cristyb51dff52011-05-19 16:55:47 +00001928 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
cristy3ed852e2009-09-05 21:47:34 +00001929 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001930 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
cristy3ed852e2009-09-05 21:47:34 +00001931 (void) ConcatenateString(&path,message);
cristyb51dff52011-05-19 16:55:47 +00001932 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
cristy3ed852e2009-09-05 21:47:34 +00001933 (void) ConcatenateString(&path,message);
1934 message=DestroyString(message);
1935 return(path);
1936}
1937
1938MagickExport const char *GetImageProperty(const Image *image,
1939 const char *property)
1940{
1941 ExceptionInfo
1942 *exception;
1943
1944 FxInfo
1945 *fx_info;
1946
1947 MagickRealType
1948 alpha;
1949
1950 MagickStatusType
1951 status;
1952
1953 register const char
1954 *p;
1955
1956 assert(image != (Image *) NULL);
1957 assert(image->signature == MagickSignature);
1958 if (image->debug != MagickFalse)
1959 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1960 p=(const char *) NULL;
cristy27f7af22010-06-21 12:23:21 +00001961 if (image->properties != (void *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001962 {
cristy5eb9fc82011-02-21 15:05:41 +00001963 if (property == (const char *) NULL)
1964 {
1965 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1966 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1967 image->properties);
1968 return(p);
1969 }
cristyd4982b42011-03-21 14:24:23 +00001970 if (LocaleNCompare("fx:",property,3) != 0)
1971 {
1972 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1973 image->properties,property);
1974 if (p != (const char *) NULL)
1975 return(p);
1976 }
cristy3ed852e2009-09-05 21:47:34 +00001977 }
cristy5eb9fc82011-02-21 15:05:41 +00001978 if ((property == (const char *) NULL) ||
1979 (strchr(property,':') == (char *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00001980 return(p);
1981 exception=(&((Image *) image)->exception);
1982 switch (*property)
1983 {
1984 case '8':
1985 {
1986 if (LocaleNCompare("8bim:",property,5) == 0)
1987 {
cristy5eb9fc82011-02-21 15:05:41 +00001988 if ((Get8BIMProperty(image,property) != MagickFalse) &&
1989 (image->properties != (void *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00001990 {
1991 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1992 image->properties,property);
1993 return(p);
1994 }
1995 }
1996 break;
1997 }
1998 case 'E':
1999 case 'e':
2000 {
2001 if (LocaleNCompare("exif:",property,5) == 0)
2002 {
cristy5eb9fc82011-02-21 15:05:41 +00002003 if ((GetEXIFProperty(image,property) != MagickFalse) &&
2004 (image->properties != (void *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00002005 {
2006 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2007 image->properties,property);
2008 return(p);
2009 }
2010 }
2011 break;
2012 }
2013 case 'F':
2014 case 'f':
2015 {
cristy27f7af22010-06-21 12:23:21 +00002016 if (LocaleNCompare("fx:",property,3) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002017 {
cristy27f7af22010-06-21 12:23:21 +00002018 fx_info=AcquireFxInfo(image,property+3);
cristy2bddff82011-07-25 18:39:12 +00002019 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
cristy0568ffc2011-07-25 16:54:14 +00002020 &alpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002021 fx_info=DestroyFxInfo(fx_info);
2022 if (status != MagickFalse)
2023 {
2024 char
2025 value[MaxTextExtent];
2026
cristyb51dff52011-05-19 16:55:47 +00002027 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristyf899bbc2010-08-10 18:11:20 +00002028 GetMagickPrecision(),(double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002029 (void) SetImageProperty((Image *) image,property,value);
2030 }
cristy5eb9fc82011-02-21 15:05:41 +00002031 if (image->properties != (void *) NULL)
2032 {
2033 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2034 image->properties,property);
2035 return(p);
2036 }
cristy3ed852e2009-09-05 21:47:34 +00002037 }
2038 break;
2039 }
2040 case 'I':
2041 case 'i':
2042 {
2043 if (LocaleNCompare("iptc:",property,5) == 0)
2044 {
cristy5eb9fc82011-02-21 15:05:41 +00002045 if ((GetIPTCProperty(image,property) != MagickFalse) &&
2046 (image->properties != (void *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00002047 {
2048 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2049 image->properties,property);
2050 return(p);
2051 }
2052 }
2053 break;
2054 }
2055 case 'P':
2056 case 'p':
2057 {
2058 if (LocaleNCompare("pixel:",property,6) == 0)
2059 {
cristy4c08aed2011-07-01 19:47:50 +00002060 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00002061 pixel;
2062
cristy4c08aed2011-07-01 19:47:50 +00002063 GetPixelInfo(image,&pixel);
cristy3ed852e2009-09-05 21:47:34 +00002064 fx_info=AcquireFxInfo(image,property+6);
cristy0568ffc2011-07-25 16:54:14 +00002065 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2066 &alpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002067 pixel.red=(MagickRealType) QuantumRange*alpha;
cristy0568ffc2011-07-25 16:54:14 +00002068 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2069 &alpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002070 pixel.green=(MagickRealType) QuantumRange*alpha;
cristy0568ffc2011-07-25 16:54:14 +00002071 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2072 &alpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002073 pixel.blue=(MagickRealType) QuantumRange*alpha;
cristy3ed852e2009-09-05 21:47:34 +00002074 if (image->colorspace == CMYKColorspace)
2075 {
cristy0568ffc2011-07-25 16:54:14 +00002076 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
cristy3ed852e2009-09-05 21:47:34 +00002077 &alpha,exception);
cristy4c08aed2011-07-01 19:47:50 +00002078 pixel.black=(MagickRealType) QuantumRange*alpha;
cristy3ed852e2009-09-05 21:47:34 +00002079 }
cristy0568ffc2011-07-25 16:54:14 +00002080 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2081 &alpha,exception);
cristy4c08aed2011-07-01 19:47:50 +00002082 pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
cristy3ed852e2009-09-05 21:47:34 +00002083 fx_info=DestroyFxInfo(fx_info);
2084 if (status != MagickFalse)
2085 {
2086 char
2087 name[MaxTextExtent];
2088
2089 (void) QueryMagickColorname(image,&pixel,SVGCompliance,name,
2090 exception);
2091 (void) SetImageProperty((Image *) image,property,name);
2092 return(GetImageProperty(image,property));
2093 }
2094 }
2095 break;
2096 }
2097 case 'X':
2098 case 'x':
2099 {
2100 if (LocaleNCompare("xmp:",property,4) == 0)
2101 {
cristy5eb9fc82011-02-21 15:05:41 +00002102 if ((GetXMPProperty(image,property) != MagickFalse) &&
2103 (image->properties != (void *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00002104 {
2105 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2106 image->properties,property);
2107 return(p);
2108 }
2109 }
2110 break;
2111 }
cristy5eb9fc82011-02-21 15:05:41 +00002112 default:
2113 break;
cristy3ed852e2009-09-05 21:47:34 +00002114 }
2115 return(p);
2116}
2117
2118/*
2119%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2120% %
2121% %
2122% %
2123+ G e t M a g i c k P r o p e r t y %
2124% %
2125% %
2126% %
2127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2128%
2129% GetMagickProperty() gets a value associated with an image property.
2130%
2131% The format of the GetMagickProperty method is:
2132%
cristyad785752011-07-27 23:13:03 +00002133% const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2134% const char *key)
cristy3ed852e2009-09-05 21:47:34 +00002135%
2136% A description of each parameter follows:
2137%
2138% o image_info: the image info.
2139%
2140% o image: the image.
2141%
2142% o key: the key.
2143%
2144*/
2145MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2146 Image *image,const char *property)
2147{
2148 char
2149 value[MaxTextExtent],
2150 filename[MaxTextExtent];
2151
2152 *value='\0';
cristyec6897c2010-05-12 00:43:15 +00002153 switch (*property)
cristy3ed852e2009-09-05 21:47:34 +00002154 {
2155 case 'b':
2156 {
2157 if (LocaleNCompare("base",property,4) == 0)
2158 {
2159 GetPathComponent(image->magick_filename,BasePath,filename);
2160 (void) CopyMagickString(value,filename,MaxTextExtent);
2161 break;
2162 }
2163 break;
2164 }
2165 case 'c':
2166 {
2167 if (LocaleNCompare("channels",property,8) == 0)
2168 {
2169 /*
2170 Image channels.
2171 */
cristyb51dff52011-05-19 16:55:47 +00002172 (void) FormatLocaleString(value,MaxTextExtent,"%s",
cristy042ee782011-04-22 18:48:30 +00002173 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
cristy3ed852e2009-09-05 21:47:34 +00002174 image->colorspace));
2175 LocaleLower(value);
2176 if (image->matte != MagickFalse)
2177 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2178 break;
2179 }
2180 if (LocaleNCompare("colorspace",property,10) == 0)
2181 {
2182 ColorspaceType
2183 colorspace;
2184
2185 /*
2186 Image storage class and colorspace.
2187 */
2188 colorspace=image->colorspace;
cristy4c08aed2011-07-01 19:47:50 +00002189 if (IsImageGray(image,&image->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002190 colorspace=GRAYColorspace;
cristyb51dff52011-05-19 16:55:47 +00002191 (void) FormatLocaleString(value,MaxTextExtent,"%s",
cristy042ee782011-04-22 18:48:30 +00002192 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
cristyf2faecf2010-05-28 19:19:36 +00002193 colorspace));
cristy3ed852e2009-09-05 21:47:34 +00002194 break;
2195 }
cristy63054742010-09-20 12:42:28 +00002196 if (LocaleNCompare("copyright",property,9) == 0)
2197 {
2198 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2199 break;
2200 }
cristy3ed852e2009-09-05 21:47:34 +00002201 break;
2202 }
2203 case 'd':
2204 {
2205 if (LocaleNCompare("depth",property,5) == 0)
2206 {
cristyb51dff52011-05-19 16:55:47 +00002207 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
cristyf2faecf2010-05-28 19:19:36 +00002208 image->depth);
cristy3ed852e2009-09-05 21:47:34 +00002209 break;
2210 }
2211 if (LocaleNCompare("directory",property,9) == 0)
2212 {
2213 GetPathComponent(image->magick_filename,HeadPath,filename);
2214 (void) CopyMagickString(value,filename,MaxTextExtent);
2215 break;
2216 }
2217 break;
2218 }
2219 case 'e':
2220 {
2221 if (LocaleNCompare("extension",property,9) == 0)
2222 {
2223 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2224 (void) CopyMagickString(value,filename,MaxTextExtent);
2225 break;
2226 }
2227 break;
2228 }
2229 case 'g':
2230 {
2231 if (LocaleNCompare("group",property,5) == 0)
2232 {
cristyb51dff52011-05-19 16:55:47 +00002233 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
cristyf2faecf2010-05-28 19:19:36 +00002234 (unsigned long) image_info->group);
cristy3ed852e2009-09-05 21:47:34 +00002235 break;
2236 }
2237 break;
2238 }
2239 case 'h':
2240 {
2241 if (LocaleNCompare("height",property,6) == 0)
2242 {
cristyb51dff52011-05-19 16:55:47 +00002243 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
cristye8c25f92010-06-03 00:53:06 +00002244 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
cristy3ed852e2009-09-05 21:47:34 +00002245 break;
2246 }
2247 break;
2248 }
2249 case 'i':
2250 {
2251 if (LocaleNCompare("input",property,5) == 0)
2252 {
2253 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2254 break;
2255 }
2256 break;
2257 }
2258 case 'k':
2259 {
2260 if (LocaleNCompare("kurtosis",property,8) == 0)
2261 {
2262 double
2263 kurtosis,
2264 skewness;
2265
cristyd42d9952011-07-08 14:21:50 +00002266 (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
cristyb51dff52011-05-19 16:55:47 +00002267 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristy0596f852010-01-17 20:21:09 +00002268 GetMagickPrecision(),kurtosis);
cristy3ed852e2009-09-05 21:47:34 +00002269 break;
2270 }
2271 break;
2272 }
2273 case 'm':
2274 {
2275 if (LocaleNCompare("magick",property,6) == 0)
2276 {
2277 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2278 break;
2279 }
2280 if (LocaleNCompare("max",property,3) == 0)
2281 {
2282 double
2283 maximum,
2284 minimum;
2285
cristyd42d9952011-07-08 14:21:50 +00002286 (void) GetImageRange(image,&minimum,&maximum,&image->exception);
cristyb51dff52011-05-19 16:55:47 +00002287 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristyf899bbc2010-08-10 18:11:20 +00002288 GetMagickPrecision(),maximum);
cristy3ed852e2009-09-05 21:47:34 +00002289 break;
2290 }
2291 if (LocaleNCompare("mean",property,4) == 0)
2292 {
2293 double
2294 mean,
2295 standard_deviation;
2296
cristyd42d9952011-07-08 14:21:50 +00002297 (void) GetImageMean(image,&mean,&standard_deviation,
2298 &image->exception);
cristyb51dff52011-05-19 16:55:47 +00002299 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristy0596f852010-01-17 20:21:09 +00002300 GetMagickPrecision(),mean);
cristy3ed852e2009-09-05 21:47:34 +00002301 break;
2302 }
2303 if (LocaleNCompare("min",property,3) == 0)
2304 {
2305 double
2306 maximum,
2307 minimum;
2308
cristyd42d9952011-07-08 14:21:50 +00002309 (void) GetImageRange(image,&minimum,&maximum,&image->exception);
cristyb51dff52011-05-19 16:55:47 +00002310 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristyf899bbc2010-08-10 18:11:20 +00002311 GetMagickPrecision(),minimum);
cristy3ed852e2009-09-05 21:47:34 +00002312 break;
2313 }
2314 break;
2315 }
2316 case 'n':
2317 {
2318 if (LocaleNCompare("name",property,4) == 0)
2319 {
2320 (void) CopyMagickString(value,filename,MaxTextExtent);
2321 break;
2322 }
2323 break;
2324 }
2325 case 'o':
2326 {
cristyb0094252011-03-26 12:59:45 +00002327 if (LocaleNCompare("opaque",property,6) == 0)
2328 {
2329 MagickBooleanType
2330 opaque;
2331
cristy4c08aed2011-07-01 19:47:50 +00002332 opaque=IsImageOpaque(image,&image->exception);
cristyb0094252011-03-26 12:59:45 +00002333 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2334 "true",MaxTextExtent);
2335 break;
2336 }
cristy3ed852e2009-09-05 21:47:34 +00002337 if (LocaleNCompare("output",property,6) == 0)
2338 {
2339 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2340 break;
2341 }
2342 break;
2343 }
2344 case 'p':
2345 {
2346 if (LocaleNCompare("page",property,4) == 0)
2347 {
cristyb51dff52011-05-19 16:55:47 +00002348 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
cristyad785752011-07-27 23:13:03 +00002349 GetImageIndexInList(image)+1);
cristy3ed852e2009-09-05 21:47:34 +00002350 break;
2351 }
2352 break;
2353 }
2354 case 's':
2355 {
2356 if (LocaleNCompare("size",property,4) == 0)
2357 {
2358 char
2359 format[MaxTextExtent];
2360
cristyb9080c92009-12-01 20:13:26 +00002361 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
cristyb51dff52011-05-19 16:55:47 +00002362 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
cristy3ed852e2009-09-05 21:47:34 +00002363 break;
2364 }
2365 if (LocaleNCompare("scenes",property,6) == 0)
2366 {
cristyb51dff52011-05-19 16:55:47 +00002367 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
cristye8c25f92010-06-03 00:53:06 +00002368 GetImageListLength(image));
cristy3ed852e2009-09-05 21:47:34 +00002369 break;
2370 }
2371 if (LocaleNCompare("scene",property,5) == 0)
2372 {
cristyb51dff52011-05-19 16:55:47 +00002373 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
cristyf2faecf2010-05-28 19:19:36 +00002374 image->scene);
cristy3ed852e2009-09-05 21:47:34 +00002375 if (image_info->number_scenes != 0)
cristyb51dff52011-05-19 16:55:47 +00002376 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
cristye8c25f92010-06-03 00:53:06 +00002377 image_info->scene);
cristy3ed852e2009-09-05 21:47:34 +00002378 break;
2379 }
2380 if (LocaleNCompare("skewness",property,8) == 0)
2381 {
2382 double
2383 kurtosis,
2384 skewness;
2385
cristyd42d9952011-07-08 14:21:50 +00002386 (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
cristyb51dff52011-05-19 16:55:47 +00002387 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristy0596f852010-01-17 20:21:09 +00002388 GetMagickPrecision(),skewness);
cristy3ed852e2009-09-05 21:47:34 +00002389 break;
2390 }
cristyd42d9952011-07-08 14:21:50 +00002391 if (LocaleNCompare("standard-deviation",property,18) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002392 {
2393 double
2394 mean,
2395 standard_deviation;
2396
cristyd42d9952011-07-08 14:21:50 +00002397 (void) GetImageMean(image,&mean,&standard_deviation,
2398 &image->exception);
cristyb51dff52011-05-19 16:55:47 +00002399 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
cristy0596f852010-01-17 20:21:09 +00002400 GetMagickPrecision(),standard_deviation);
cristy3ed852e2009-09-05 21:47:34 +00002401 break;
2402 }
2403 break;
2404 }
2405 case 'u':
2406 {
2407 if (LocaleNCompare("unique",property,6) == 0)
2408 {
2409 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2410 (void) CopyMagickString(value,filename,MaxTextExtent);
2411 break;
2412 }
2413 break;
2414 }
cristy63054742010-09-20 12:42:28 +00002415 case 'v':
2416 {
2417 if (LocaleNCompare("version",property,7) == 0)
2418 {
2419 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2420 MaxTextExtent);
2421 break;
2422 }
2423 break;
2424 }
cristy3ed852e2009-09-05 21:47:34 +00002425 case 'w':
2426 {
2427 if (LocaleNCompare("width",property,5) == 0)
2428 {
cristyb51dff52011-05-19 16:55:47 +00002429 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
cristyf2faecf2010-05-28 19:19:36 +00002430 (image->magick_columns != 0 ? image->magick_columns : 256));
cristy3ed852e2009-09-05 21:47:34 +00002431 break;
2432 }
2433 break;
2434 }
2435 case 'x':
2436 {
2437 if (LocaleNCompare("xresolution",property,11) == 0)
2438 {
cristyb51dff52011-05-19 16:55:47 +00002439 (void) FormatLocaleString(value,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00002440 image->x_resolution);
2441 break;
2442 }
2443 break;
2444 }
2445 case 'y':
2446 {
2447 if (LocaleNCompare("yresolution",property,11) == 0)
2448 {
cristyb51dff52011-05-19 16:55:47 +00002449 (void) FormatLocaleString(value,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00002450 image->y_resolution);
2451 break;
2452 }
2453 break;
2454 }
2455 case 'z':
2456 {
2457 if (LocaleNCompare("zero",property,4) == 0)
2458 {
2459 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2460 (void) CopyMagickString(value,filename,MaxTextExtent);
2461 break;
2462 }
2463 break;
2464 }
2465 }
2466 if (*value != '\0')
2467 {
2468 if (image->properties == (void *) NULL)
2469 image->properties=NewSplayTree(CompareSplayTreeString,
2470 RelinquishMagickMemory,RelinquishMagickMemory);
2471 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2472 ConstantString(property),ConstantString(value));
2473 }
2474 return(GetImageProperty(image,property));
2475}
2476
2477/*
2478%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2479% %
2480% %
2481% %
2482% G e t N e x t I m a g e P r o p e r t y %
2483% %
2484% %
2485% %
2486%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2487%
2488% GetNextImageProperty() gets the next image property value.
2489%
2490% The format of the GetNextImageProperty method is:
2491%
2492% char *GetNextImageProperty(const Image *image)
2493%
2494% A description of each parameter follows:
2495%
2496% o image: the image.
2497%
2498*/
2499MagickExport char *GetNextImageProperty(const Image *image)
2500{
2501 assert(image != (Image *) NULL);
2502 assert(image->signature == MagickSignature);
2503 if (image->debug != MagickFalse)
2504 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2505 image->filename);
2506 if (image->properties == (void *) NULL)
2507 return((char *) NULL);
2508 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2509}
2510
2511/*
2512%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2513% %
2514% %
2515% %
2516% I n t e r p r e t I m a g e P r o p e r t i e s %
2517% %
2518% %
2519% %
2520%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2521%
2522% InterpretImageProperties() replaces any embedded formatting characters with
glennrpaa588b82011-07-02 05:43:07 +00002523% the appropriate image property and returns the interpreted text.
cristy3ed852e2009-09-05 21:47:34 +00002524%
2525% The format of the InterpretImageProperties method is:
2526%
2527% char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
cristy018f07f2011-09-04 21:15:19 +00002528% const char *embed_text,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002529%
2530% A description of each parameter follows:
2531%
2532% o image_info: the image info.
2533%
2534% o image: the image.
2535%
2536% o embed_text: the address of a character string containing the embedded
2537% formatting characters.
2538%
cristy018f07f2011-09-04 21:15:19 +00002539% o exception: return any errors or warnings in this structure.
2540%
cristy3ed852e2009-09-05 21:47:34 +00002541*/
2542MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
cristy018f07f2011-09-04 21:15:19 +00002543 Image *image,const char *embed_text,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002544{
2545 char
2546 filename[MaxTextExtent],
2547 *interpret_text,
2548 *text;
2549
2550 const char
2551 *value;
2552
cristy3ed852e2009-09-05 21:47:34 +00002553 register char
2554 *q;
2555
2556 register const char
2557 *p;
2558
cristybb503372010-05-27 20:51:26 +00002559 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002560 i;
2561
2562 size_t
2563 extent,
2564 length;
2565
2566 assert(image != (Image *) NULL);
2567 assert(image->signature == MagickSignature);
2568 if (image->debug != MagickFalse)
2569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2570 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2571 return((char *) NULL);
2572 text=(char *) embed_text;
2573 if ((*text == '@') && ((*(text+1) == '-') ||
2574 (IsPathAccessible(text+1) != MagickFalse)))
2575 return(FileToString(embed_text+1,~0,&image->exception));
2576 /*
2577 Translate any embedded format characters.
2578 */
cristy3ed852e2009-09-05 21:47:34 +00002579 interpret_text=AcquireString(text);
2580 extent=MaxTextExtent;
2581 p=text;
2582 for (q=interpret_text; *p != '\0'; p++)
2583 {
2584 *q='\0';
2585 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2586 {
2587 extent+=MaxTextExtent;
2588 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2589 MaxTextExtent+1,sizeof(*interpret_text));
2590 if (interpret_text == (char *) NULL)
2591 break;
2592 q=interpret_text+strlen(interpret_text);
2593 }
2594 /*
2595 Process formatting characters in text.
2596 */
2597 if ((*p == '\\') && (*(p+1) == 'r'))
2598 {
2599 *q++='\r';
2600 p++;
2601 continue;
2602 }
2603 if ((*p == '\\') && (*(p+1) == 'n'))
2604 {
2605 *q++='\n';
2606 p++;
2607 continue;
2608 }
2609 if (*p == '\\')
2610 {
2611 p++;
2612 *q++=(*p);
2613 continue;
2614 }
2615 if (*p != '%')
2616 {
2617 *q++=(*p);
2618 continue;
2619 }
2620 p++;
2621 switch (*p)
2622 {
anthony698cbb12011-10-02 12:01:40 +00002623 case '[': /* multi-character substitution */
cristy3ed852e2009-09-05 21:47:34 +00002624 {
2625 char
2626 pattern[MaxTextExtent];
2627
2628 const char
2629 *key,
2630 *value;
2631
cristybb503372010-05-27 20:51:26 +00002632 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002633 depth;
2634
2635 /*
2636 Image value.
2637 */
2638 if (strchr(p,']') == (char *) NULL)
2639 break;
2640 depth=1;
2641 p++;
2642 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
2643 {
2644 if (*p == '[')
2645 depth++;
2646 if (*p == ']')
2647 depth--;
2648 if (depth <= 0)
2649 break;
2650 pattern[i]=(*p++);
2651 }
2652 pattern[i]='\0';
2653 value=GetImageProperty(image,pattern);
2654 if (value != (const char *) NULL)
2655 {
2656 length=strlen(value);
2657 if ((size_t) (q-interpret_text+length+1) >= extent)
2658 {
2659 extent+=length;
2660 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2661 extent+MaxTextExtent,sizeof(*interpret_text));
2662 if (interpret_text == (char *) NULL)
2663 break;
2664 q=interpret_text+strlen(interpret_text);
2665 }
2666 (void) CopyMagickString(q,value,extent);
2667 q+=length;
2668 break;
2669 }
2670 else
2671 if (IsGlob(pattern) != MagickFalse)
2672 {
2673 /*
2674 Iterate over image properties.
2675 */
2676 ResetImagePropertyIterator(image);
2677 key=GetNextImageProperty(image);
2678 while (key != (const char *) NULL)
2679 {
2680 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
2681 {
2682 value=GetImageProperty(image,key);
2683 if (value != (const char *) NULL)
2684 {
2685 length=strlen(key)+strlen(value)+2;
2686 if ((size_t) (q-interpret_text+length+1) >= extent)
2687 {
2688 extent+=length;
2689 interpret_text=(char *) ResizeQuantumMemory(
2690 interpret_text,extent+MaxTextExtent,
2691 sizeof(*interpret_text));
2692 if (interpret_text == (char *) NULL)
2693 break;
2694 q=interpret_text+strlen(interpret_text);
2695 }
cristyb51dff52011-05-19 16:55:47 +00002696 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
cristy3ed852e2009-09-05 21:47:34 +00002697 }
2698 }
2699 key=GetNextImageProperty(image);
2700 }
2701 }
cristy8f9fe9a2011-03-16 12:37:49 +00002702 value=GetMagickProperty(image_info,image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00002703 if (value != (const char *) NULL)
2704 {
2705 length=strlen(value);
2706 if ((size_t) (q-interpret_text+length+1) >= extent)
2707 {
2708 extent+=length;
2709 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2710 extent+MaxTextExtent,sizeof(*interpret_text));
2711 if (interpret_text == (char *) NULL)
2712 break;
2713 q=interpret_text+strlen(interpret_text);
2714 }
2715 (void) CopyMagickString(q,value,extent);
2716 q+=length;
cristy458b5fe2010-05-12 00:54:41 +00002717 break;
cristy3ed852e2009-09-05 21:47:34 +00002718 }
2719 if (image_info == (ImageInfo *) NULL)
2720 break;
2721 value=GetImageOption(image_info,pattern);
2722 if (value != (char *) NULL)
2723 {
2724 length=strlen(value);
2725 if ((size_t) (q-interpret_text+length+1) >= extent)
2726 {
2727 extent+=length;
2728 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2729 extent+MaxTextExtent,sizeof(*interpret_text));
2730 if (interpret_text == (char *) NULL)
2731 break;
2732 q=interpret_text+strlen(interpret_text);
2733 }
2734 (void) CopyMagickString(q,value,extent);
2735 q+=length;
cristy458b5fe2010-05-12 00:54:41 +00002736 break;
cristy3ed852e2009-09-05 21:47:34 +00002737 }
2738 break;
2739 }
anthony698cbb12011-10-02 12:01:40 +00002740 case 'b': /* image size as read in */
2741 {
2742 char
2743 format[MaxTextExtent];
2744
2745 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2746 ((MagickOffsetType) image->extent));
2747 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2748 (void) FormatMagickSize(image->extent,MagickFalse,format);
2749 q+=ConcatenateMagickString(q,format,extent);
2750 q+=ConcatenateMagickString(q,"B",extent);
2751 break;
2752 }
2753 case 'c': /* image comment properity */
2754 {
2755 value=GetImageProperty(image,"comment");
2756 if (value == (const char *) NULL)
2757 break;
2758 length=strlen(value);
2759 if ((size_t) (q-interpret_text+length+1) >= extent)
2760 {
2761 extent+=length;
2762 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2763 MaxTextExtent,sizeof(*interpret_text));
2764 if (interpret_text == (char *) NULL)
2765 break;
2766 q=interpret_text+strlen(interpret_text);
2767 }
2768 (void) CopyMagickString(q,value,extent);
2769 q+=length;
2770 break;
2771 }
2772 case 'd': /* Directory component of filename */
2773 {
2774 GetPathComponent(image->magick_filename,HeadPath,filename);
2775 q+=CopyMagickString(q,filename,extent);
2776 break;
2777 }
2778 case 'e': /* Filename extension (suffix) of image file */
2779 {
2780 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2781 q+=CopyMagickString(q,filename,extent);
2782 break;
2783 }
2784 case 'f': /* Filename without directory component */
2785 {
2786 GetPathComponent(image->magick_filename,TailPath,filename);
2787 q+=CopyMagickString(q,filename,extent);
2788 break;
2789 }
2790 case 't': /* Base filename without directory or extention */
2791 {
2792 GetPathComponent(image->magick_filename,BasePath,filename);
2793 q+=CopyMagickString(q,filename,extent);
2794 break;
2795 }
2796 case 'g': /* Image geometry, canvas and offset */
2797 {
2798 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2799 image->page.width,(double) image->page.height,(double) image->page.x,
2800 (double) image->page.y);
2801 break;
2802 }
2803 case 'h': /* Image height */
2804 {
2805 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2806 image->rows : image->magick_rows));
2807 break;
2808 }
2809 case 'i': /* Images filename - (output filename with "info:" ) */
2810 {
2811 q+=CopyMagickString(q,image->filename,extent);
2812 break;
2813 }
2814 case 'k': /* Number of unique colors */
2815 {
2816 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2817 (FILE *) NULL,&image->exception));
2818 break;
2819 }
2820 case 'l': /* Image label */
2821 {
2822 value=GetImageProperty(image,"label");
2823 if (value == (const char *) NULL)
2824 break;
2825 length=strlen(value);
2826 if ((size_t) (q-interpret_text+length+1) >= extent)
2827 {
2828 extent+=length;
2829 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2830 MaxTextExtent,sizeof(*interpret_text));
2831 if (interpret_text == (char *) NULL)
2832 break;
2833 q=interpret_text+strlen(interpret_text);
2834 }
2835 q+=CopyMagickString(q,value,extent);
2836 break;
2837 }
2838 case 'm': /* Image format (file magick) */
2839 {
2840 q+=CopyMagickString(q,image->magick,extent);
2841 break;
2842 }
2843 case 'M': /* Magick filename - exactly as given incl. read mods */
2844 {
2845 q+=CopyMagickString(q,image->magick_filename,extent);
2846 break;
2847 }
2848 case 'n': /* Number of images in the list. */
2849 {
2850 q+=FormatLocaleString(q,extent,"%.20g",(double)
2851 GetImageListLength(image));
2852 break;
2853 }
2854 case 'o': /* Image output filename */
2855 {
2856 q+=CopyMagickString(q,image_info->filename,extent);
2857 break;
2858 }
2859 case 'p': /* Image index in curent image list */
2860 {
2861 q+=FormatLocaleString(q,extent,"%.20g",(double)
2862 GetImageIndexInList(image));
2863 break;
2864 }
2865 case 'q': /* Quantum depth of image in memory */
2866 {
2867 q+=FormatLocaleString(q,extent,"%.20g",(double)
2868 MAGICKCORE_QUANTUM_DEPTH);
2869 break;
2870 }
2871 case 'r': /* Image storage class and colorspace. */
2872 {
2873 ColorspaceType
2874 colorspace;
2875
2876 colorspace=image->colorspace;
2877 if (IsImageGray(image,&image->exception) != MagickFalse)
2878 colorspace=GRAYColorspace;
2879 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2880 MagickClassOptions,(ssize_t) image->storage_class),
2881 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2882 image->matte != MagickFalse ? "Matte" : "");
2883 break;
2884 }
2885 case 's': /* Image scene number */
2886 {
2887 if (image_info->number_scenes == 0)
2888 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2889 else
2890 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2891 break;
2892 }
2893 case 'u': /* Unique filename */
2894 {
2895 (void) CopyMagickString(filename,image_info->unique,extent);
2896 q+=CopyMagickString(q,filename,extent);
2897 break;
2898 }
2899 case 'w': /* Image width */
2900 {
2901 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2902 image->columns : image->magick_columns));
2903 break;
2904 }
2905 case 'x': /* Image horizontal resolution (density). */
2906 {
2907 q+=FormatLocaleString(q,extent,"%g %s",image->x_resolution,
2908 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2909 image->units));
2910 break;
2911 }
2912 case 'y': /* Image vertical resolution (density) */
2913 {
2914 q+=FormatLocaleString(q,extent,"%g %s",image->y_resolution,
2915 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2916 image->units));
2917 break;
2918 }
2919 case 'z': /* Image depth as read in */
2920 {
2921 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2922 break;
2923 }
2924 case 'A': /* Image alpha channel */
2925 {
2926 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2927 MagickBooleanOptions,(ssize_t) image->matte));
2928 break;
2929 }
2930 case 'C': /* Image compression method. */
2931 {
2932 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2933 MagickCompressOptions,(ssize_t) image->compression));
2934 break;
2935 }
2936 case 'D': /* Image dispose method. */
2937 {
2938 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2939 MagickDisposeOptions,(ssize_t) image->dispose));
2940 break;
2941 }
2942 case 'G': /* Image size as geometry = "%wx%h" */
2943 {
2944 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2945 image->magick_columns,(double) image->magick_rows);
2946 break;
2947 }
2948 case 'H': /* layer canvas height */
2949 {
2950 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2951 break;
2952 }
2953 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2954 {
2955 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2956 image->page.y);
2957 break;
2958 }
2959 case 'P': /* layer canvas page size = "%Wx%H" */
2960 {
2961 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2962 (double) image->page.height);
2963 break;
2964 }
2965 case 'Q': /* image compression quality */
2966 {
2967 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2968 break;
2969 }
2970 case 'S': /* Image scenes */
2971 {
2972 if (image_info->number_scenes == 0)
2973 q+=CopyMagickString(q,"2147483647",extent);
2974 else
2975 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2976 image_info->number_scenes));
2977 break;
2978 }
2979 case 'T': /* image time delay for animations */
2980 {
2981 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
2982 break;
2983 }
2984 case 'W': /* layer canvas width */
2985 {
2986 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
2987 break;
2988 }
2989 case 'X': /* layer canvas X offset */
2990 {
2991 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
2992 break;
2993 }
2994 case 'Y': /* layer canvas Y offset */
2995 {
2996 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
2997 break;
2998 }
2999 case 'Z': /* Unique filename. */
3000 {
3001 (void) CopyMagickString(filename,image_info->zero,extent);
3002 q+=CopyMagickString(q,filename,extent);
3003 break;
3004 }
3005 case '@': /* Image bounding box. */
cristy3ed852e2009-09-05 21:47:34 +00003006 {
3007 RectangleInfo
3008 page;
3009
cristy018f07f2011-09-04 21:15:19 +00003010 page=GetImageBoundingBox(image,exception);
cristyb51dff52011-05-19 16:55:47 +00003011 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
cristye8c25f92010-06-03 00:53:06 +00003012 (double) page.width,(double) page.height,(double) page.x,(double)
3013 page.y);
cristy3ed852e2009-09-05 21:47:34 +00003014 break;
3015 }
anthony698cbb12011-10-02 12:01:40 +00003016 case '#': /* Image signature */
cristy3ed852e2009-09-05 21:47:34 +00003017 {
cristy018f07f2011-09-04 21:15:19 +00003018 (void) SignatureImage(image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003019 value=GetImageProperty(image,"signature");
3020 if (value == (const char *) NULL)
3021 break;
3022 q+=CopyMagickString(q,value,extent);
3023 break;
3024 }
anthony698cbb12011-10-02 12:01:40 +00003025 case '%': /* percent escaped */
cristy3ed852e2009-09-05 21:47:34 +00003026 {
3027 *q++=(*p);
3028 break;
3029 }
anthony698cbb12011-10-02 12:01:40 +00003030 default: /* percent not expanded */
cristy3ed852e2009-09-05 21:47:34 +00003031 {
3032 *q++='%';
3033 *q++=(*p);
3034 break;
3035 }
3036 }
3037 }
3038 *q='\0';
cristy3ed852e2009-09-05 21:47:34 +00003039 if (text != (const char *) embed_text)
3040 text=DestroyString(text);
3041 (void) SubstituteString(&interpret_text,"&lt;","<");
3042 (void) SubstituteString(&interpret_text,"&gt;",">");
3043 return(interpret_text);
3044}
3045
3046/*
3047%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3048% %
3049% %
3050% %
3051% R e m o v e I m a g e P r o p e r t y %
3052% %
3053% %
3054% %
3055%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3056%
3057% RemoveImageProperty() removes a property from the image and returns its
3058% value.
3059%
3060% The format of the RemoveImageProperty method is:
3061%
3062% char *RemoveImageProperty(Image *image,const char *property)
3063%
3064% A description of each parameter follows:
3065%
3066% o image: the image.
3067%
3068% o property: the image property.
3069%
3070*/
3071MagickExport char *RemoveImageProperty(Image *image,
3072 const char *property)
3073{
3074 char
3075 *value;
3076
3077 assert(image != (Image *) NULL);
3078 assert(image->signature == MagickSignature);
3079 if (image->debug != MagickFalse)
3080 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3081 image->filename);
3082 if (image->properties == (void *) NULL)
3083 return((char *) NULL);
3084 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3085 property);
3086 return(value);
3087}
3088
3089/*
3090%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3091% %
3092% %
3093% %
3094% 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 %
3095% %
3096% %
3097% %
3098%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3099%
3100% ResetImagePropertyIterator() resets the image properties iterator. Use it
3101% in conjunction with GetNextImageProperty() to iterate over all the values
3102% associated with an image property.
3103%
3104% The format of the ResetImagePropertyIterator method is:
3105%
3106% ResetImagePropertyIterator(Image *image)
3107%
3108% A description of each parameter follows:
3109%
3110% o image: the image.
3111%
3112*/
3113MagickExport void ResetImagePropertyIterator(const Image *image)
3114{
3115 assert(image != (Image *) NULL);
3116 assert(image->signature == MagickSignature);
3117 if (image->debug != MagickFalse)
3118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3119 image->filename);
3120 if (image->properties == (void *) NULL)
3121 return;
3122 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3123}
3124
3125/*
3126%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3127% %
3128% %
3129% %
3130% S e t I m a g e P r o p e r t y %
3131% %
3132% %
3133% %
3134%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3135%
3136% SetImageProperty() associates an value with an image property.
3137%
3138% The format of the SetImageProperty method is:
3139%
3140% MagickBooleanType SetImageProperty(Image *image,const char *property,
3141% const char *value)
3142%
3143% A description of each parameter follows:
3144%
3145% o image: the image.
3146%
3147% o property: the image property.
3148%
3149% o values: the image property values.
3150%
3151*/
3152MagickExport MagickBooleanType SetImageProperty(Image *image,
3153 const char *property,const char *value)
3154{
cristyc6c08ab2010-07-24 23:50:09 +00003155 ExceptionInfo
3156 *exception;
3157
cristy3ed852e2009-09-05 21:47:34 +00003158 MagickBooleanType
3159 status;
3160
3161 MagickStatusType
3162 flags;
3163
3164 assert(image != (Image *) NULL);
3165 assert(image->signature == MagickSignature);
3166 if (image->debug != MagickFalse)
3167 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3168 image->filename);
3169 if (image->properties == (void *) NULL)
3170 image->properties=NewSplayTree(CompareSplayTreeString,
3171 RelinquishMagickMemory,RelinquishMagickMemory);
3172 if ((value == (const char *) NULL) || (*value == '\0'))
3173 return(DeleteImageProperty(image,property));
3174 status=MagickTrue;
cristyc6c08ab2010-07-24 23:50:09 +00003175 exception=(&image->exception);
cristy3ed852e2009-09-05 21:47:34 +00003176 switch (*property)
3177 {
3178 case 'B':
3179 case 'b':
3180 {
cristyc6c08ab2010-07-24 23:50:09 +00003181 if (LocaleCompare(property,"background") == 0)
3182 {
cristy9950d572011-10-01 18:22:35 +00003183 (void) QueryColorCompliance(value,AllCompliance,
3184 &image->background_color,exception);
cristyc6c08ab2010-07-24 23:50:09 +00003185 break;
3186 }
cristy3ed852e2009-09-05 21:47:34 +00003187 if (LocaleCompare(property,"bias") == 0)
3188 {
cristyf2f27272009-12-17 14:48:46 +00003189 image->bias=SiPrefixToDouble(value,QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003190 break;
3191 }
3192 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3193 ConstantString(property),ConstantString(value));
3194 break;
3195 }
3196 case 'C':
3197 case 'c':
3198 {
3199 if (LocaleCompare(property,"colorspace") == 0)
3200 {
cristybb503372010-05-27 20:51:26 +00003201 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003202 colorspace;
3203
cristy042ee782011-04-22 18:48:30 +00003204 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003205 value);
3206 if (colorspace < 0)
3207 break;
cristy63240882011-08-05 19:05:27 +00003208 (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3209 exception);
cristy3ed852e2009-09-05 21:47:34 +00003210 break;
3211 }
3212 if (LocaleCompare(property,"compose") == 0)
3213 {
cristybb503372010-05-27 20:51:26 +00003214 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003215 compose;
3216
cristy042ee782011-04-22 18:48:30 +00003217 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
cristy3ed852e2009-09-05 21:47:34 +00003218 if (compose < 0)
3219 break;
3220 image->compose=(CompositeOperator) compose;
3221 break;
3222 }
3223 if (LocaleCompare(property,"compress") == 0)
3224 {
cristybb503372010-05-27 20:51:26 +00003225 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003226 compression;
3227
cristy042ee782011-04-22 18:48:30 +00003228 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003229 value);
3230 if (compression < 0)
3231 break;
3232 image->compression=(CompressionType) compression;
3233 break;
3234 }
3235 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3236 ConstantString(property),ConstantString(value));
3237 break;
3238 }
3239 case 'D':
3240 case 'd':
3241 {
3242 if (LocaleCompare(property,"delay") == 0)
3243 {
3244 GeometryInfo
3245 geometry_info;
3246
3247 flags=ParseGeometry(value,&geometry_info);
3248 if ((flags & GreaterValue) != 0)
3249 {
cristybb503372010-05-27 20:51:26 +00003250 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3251 image->delay=(size_t) floor(geometry_info.rho+0.5);
cristy3ed852e2009-09-05 21:47:34 +00003252 }
3253 else
3254 if ((flags & LessValue) != 0)
3255 {
cristybb503372010-05-27 20:51:26 +00003256 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
cristyc6c08ab2010-07-24 23:50:09 +00003257 image->ticks_per_second=(ssize_t)
3258 floor(geometry_info.sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00003259 }
3260 else
cristybb503372010-05-27 20:51:26 +00003261 image->delay=(size_t) floor(geometry_info.rho+0.5);
cristy3ed852e2009-09-05 21:47:34 +00003262 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00003263 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00003264 break;
3265 }
cristyfbb56842010-08-02 11:26:33 +00003266 if (LocaleCompare(property,"density") == 0)
3267 {
3268 GeometryInfo
3269 geometry_info;
3270
3271 flags=ParseGeometry(value,&geometry_info);
3272 image->x_resolution=geometry_info.rho;
3273 image->y_resolution=geometry_info.sigma;
3274 if ((flags & SigmaValue) == 0)
3275 image->y_resolution=image->x_resolution;
3276 }
cristy3ed852e2009-09-05 21:47:34 +00003277 if (LocaleCompare(property,"depth") == 0)
3278 {
cristye27293e2009-12-18 02:53:20 +00003279 image->depth=StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00003280 break;
3281 }
3282 if (LocaleCompare(property,"dispose") == 0)
3283 {
cristybb503372010-05-27 20:51:26 +00003284 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003285 dispose;
3286
cristy042ee782011-04-22 18:48:30 +00003287 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
cristy3ed852e2009-09-05 21:47:34 +00003288 if (dispose < 0)
3289 break;
3290 image->dispose=(DisposeType) dispose;
3291 break;
3292 }
3293 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3294 ConstantString(property),ConstantString(value));
3295 break;
3296 }
3297 case 'G':
3298 case 'g':
3299 {
3300 if (LocaleCompare(property,"gravity") == 0)
3301 {
cristybb503372010-05-27 20:51:26 +00003302 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003303 gravity;
3304
cristy042ee782011-04-22 18:48:30 +00003305 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
cristy3ed852e2009-09-05 21:47:34 +00003306 if (gravity < 0)
3307 break;
3308 image->gravity=(GravityType) gravity;
3309 break;
3310 }
3311 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3312 ConstantString(property),ConstantString(value));
3313 break;
3314 }
3315 case 'I':
3316 case 'i':
3317 {
3318 if (LocaleCompare(property,"intent") == 0)
3319 {
cristybb503372010-05-27 20:51:26 +00003320 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003321 rendering_intent;
3322
cristy042ee782011-04-22 18:48:30 +00003323 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003324 value);
3325 if (rendering_intent < 0)
3326 break;
3327 image->rendering_intent=(RenderingIntent) rendering_intent;
3328 break;
3329 }
3330 if (LocaleCompare(property,"interpolate") == 0)
3331 {
cristybb503372010-05-27 20:51:26 +00003332 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003333 interpolate;
3334
cristy042ee782011-04-22 18:48:30 +00003335 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003336 value);
3337 if (interpolate < 0)
3338 break;
cristy5c4e2582011-09-11 19:21:03 +00003339 image->interpolate=(PixelInterpolateMethod) interpolate;
cristy3ed852e2009-09-05 21:47:34 +00003340 break;
3341 }
3342 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3343 ConstantString(property),ConstantString(value));
3344 break;
3345 }
3346 case 'L':
3347 case 'l':
3348 {
3349 if (LocaleCompare(property,"loop") == 0)
3350 {
cristye27293e2009-12-18 02:53:20 +00003351 image->iterations=StringToUnsignedLong(value);
cristy3ed852e2009-09-05 21:47:34 +00003352 break;
3353 }
3354 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3355 ConstantString(property),ConstantString(value));
3356 break;
3357 }
3358 case 'P':
3359 case 'p':
3360 {
3361 if (LocaleCompare(property,"page") == 0)
3362 {
3363 char
3364 *geometry;
3365
3366 geometry=GetPageGeometry(value);
3367 flags=ParseAbsoluteGeometry(geometry,&image->page);
3368 geometry=DestroyString(geometry);
3369 break;
3370 }
cristy071dd7b2010-04-09 13:04:54 +00003371 if (LocaleCompare(property,"profile") == 0)
3372 {
3373 ImageInfo
3374 *image_info;
3375
3376 StringInfo
3377 *profile;
3378
3379 image_info=AcquireImageInfo();
3380 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
cristyc6c08ab2010-07-24 23:50:09 +00003381 (void) SetImageInfo(image_info,1,exception);
3382 profile=FileToStringInfo(image_info->filename,~0UL,exception);
cristy071dd7b2010-04-09 13:04:54 +00003383 if (profile != (StringInfo *) NULL)
3384 status=SetImageProfile(image,image_info->magick,profile);
3385 image_info=DestroyImageInfo(image_info);
3386 break;
3387 }
cristy3ed852e2009-09-05 21:47:34 +00003388 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3389 ConstantString(property),ConstantString(value));
3390 break;
3391 }
3392 case 'R':
3393 case 'r':
3394 {
3395 if (LocaleCompare(property,"rendering-intent") == 0)
3396 {
cristybb503372010-05-27 20:51:26 +00003397 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003398 rendering_intent;
3399
cristy042ee782011-04-22 18:48:30 +00003400 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003401 value);
3402 if (rendering_intent < 0)
3403 break;
3404 image->rendering_intent=(RenderingIntent) rendering_intent;
3405 break;
3406 }
3407 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3408 ConstantString(property),ConstantString(value));
3409 break;
3410 }
3411 case 'T':
3412 case 't':
3413 {
3414 if (LocaleCompare(property,"tile-offset") == 0)
3415 {
3416 char
3417 *geometry;
3418
3419 geometry=GetPageGeometry(value);
3420 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3421 geometry=DestroyString(geometry);
3422 break;
3423 }
3424 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3425 ConstantString(property),ConstantString(value));
3426 break;
3427 }
cristyfbb56842010-08-02 11:26:33 +00003428 case 'U':
3429 case 'u':
3430 {
3431 if (LocaleCompare(property,"units") == 0)
3432 {
3433 ssize_t
3434 units;
3435
cristy042ee782011-04-22 18:48:30 +00003436 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
cristyfbb56842010-08-02 11:26:33 +00003437 if (units < 0)
3438 break;
3439 image->units=(ResolutionType) units;
3440 break;
3441 }
3442 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3443 ConstantString(property),ConstantString(value));
3444 break;
3445 }
cristy3ed852e2009-09-05 21:47:34 +00003446 default:
3447 {
3448 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3449 ConstantString(property),ConstantString(value));
3450 break;
3451 }
3452 }
3453 return(status);
3454}