]> granicus.if.org Git - imagemagick/blob - MagickCore/artifact.c
(no commit message)
[imagemagick] / MagickCore / artifact.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %            AAA   RRRR   TTTTT  IIIII  FFFFF   AAA    CCCC  TTTTT            %
7 %           A   A  R   R    T      I    F      A   A  C        T              %
8 %           AAAAA  RRRRR    T      I    FFF    AAAAA  C        T              %
9 %           A   A  R R      T      I    F      A   A  C        T              %
10 %           A   A  R  R     T    IIIII  F      A   A  CCCCC    T              %
11 %                                                                             %
12 %                                                                             %
13 %                         MagickCore Artifact Methods                         %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                 March 2000                                  %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    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 \f
40 /*
41   Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/artifact.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/image.h"
58 #include "MagickCore/layer.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/montage.h"
63 #include "MagickCore/option.h"
64 #include "MagickCore/profile.h"
65 #include "MagickCore/quantum.h"
66 #include "MagickCore/resource_.h"
67 #include "MagickCore/splay-tree.h"
68 #include "MagickCore/signature-private.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/string_.h"
71 #include "MagickCore/token.h"
72 #include "MagickCore/utility.h"
73 #include "MagickCore/xml-tree.h"
74 \f
75 /*
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %                                                                             %
78 %                                                                             %
79 %                                                                             %
80 %   C l o n e I m a g e A r t i f a c t s                                     %
81 %                                                                             %
82 %                                                                             %
83 %                                                                             %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 %
86 %  CloneImageArtifacts() clones one or more image artifacts.
87 %
88 %  The format of the CloneImageArtifacts method is:
89 %
90 %      MagickBooleanType CloneImageArtifacts(Image *image,
91 %        const Image *clone_image)
92 %
93 %  A description of each parameter follows:
94 %
95 %    o image: the image.
96 %
97 %    o clone_image: the clone image.
98 %
99 */
100 MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
101   const Image *clone_image)
102 {
103   assert(image != (Image *) NULL);
104   assert(image->signature == MagickSignature);
105   if (image->debug != MagickFalse)
106     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
107   assert(clone_image != (const Image *) NULL);
108   assert(clone_image->signature == MagickSignature);
109   if (clone_image->debug != MagickFalse)
110     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
111       clone_image->filename);
112   if (clone_image->artifacts != (void *) NULL)
113     image->artifacts=CloneSplayTree((SplayTreeInfo *) clone_image->artifacts,
114       (void *(*)(void *)) ConstantString,(void *(*)(void *)) ConstantString);
115   return(MagickTrue);
116 }
117 \f
118 /*
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 %                                                                             %
121 %                                                                             %
122 %                                                                             %
123 %   D e f i n e I m a g e A r t i f a c t                                     %
124 %                                                                             %
125 %                                                                             %
126 %                                                                             %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 %
129 %  DefineImageArtifact() associates a key/value pair with an image artifact.
130 %
131 %  The format of the DefineImageArtifact method is:
132 %
133 %      MagickBooleanType DefineImageArtifact(Image *image,
134 %        const char *artifact)
135 %
136 %  A description of each parameter follows:
137 %
138 %    o image: the image.
139 %
140 %    o artifact: the image artifact.
141 %
142 */
143 MagickExport MagickBooleanType DefineImageArtifact(Image *image,
144   const char *artifact)
145 {
146   char
147     key[MaxTextExtent],
148     value[MaxTextExtent];
149
150   register char
151     *p;
152
153   assert(image != (Image *) NULL);
154   assert(artifact != (const char *) NULL);
155   (void) CopyMagickString(key,artifact,MaxTextExtent-1);
156   for (p=key; *p != '\0'; p++)
157     if (*p == '=')
158       break;
159   *value='\0';
160   if (*p == '=')
161     (void) CopyMagickString(value,p+1,MaxTextExtent);
162   *p='\0';
163   return(SetImageArtifact(image,key,value));
164 }
165 \f
166 /*
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 %                                                                             %
169 %                                                                             %
170 %                                                                             %
171 %   D e l e t e I m a g e A r t i f a c t                                     %
172 %                                                                             %
173 %                                                                             %
174 %                                                                             %
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 %
177 %  DeleteImageArtifact() deletes an image artifact.
178 %
179 %  The format of the DeleteImageArtifact method is:
180 %
181 %      MagickBooleanType DeleteImageArtifact(Image *image,const char *artifact)
182 %
183 %  A description of each parameter follows:
184 %
185 %    o image: the image.
186 %
187 %    o artifact: the image artifact.
188 %
189 */
190 MagickExport MagickBooleanType DeleteImageArtifact(Image *image,
191   const char *artifact)
192 {
193   assert(image != (Image *) NULL);
194   assert(image->signature == MagickSignature);
195   if (image->debug != MagickFalse)
196     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
197       image->filename);
198   if (image->artifacts == (void *) NULL)
199     return(MagickFalse);
200   return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->artifacts,artifact));
201 }
202 \f
203 /*
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 %                                                                             %
206 %                                                                             %
207 %                                                                             %
208 %   D e s t r o y I m a g e A r t i f a c t s                                 %
209 %                                                                             %
210 %                                                                             %
211 %                                                                             %
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 %
214 %  DestroyImageArtifacts() releases memory associated with image artifact
215 %  values.
216 %
217 %  The format of the DestroyDefines method is:
218 %
219 %      void DestroyImageArtifacts(Image *image)
220 %
221 %  A description of each parameter follows:
222 %
223 %    o image: the image.
224 %
225 */
226 MagickExport void DestroyImageArtifacts(Image *image)
227 {
228   assert(image != (Image *) NULL);
229   assert(image->signature == MagickSignature);
230   if (image->debug != MagickFalse)
231     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
232       image->filename);
233   if (image->artifacts != (void *) NULL)
234     image->artifacts=(void *) DestroySplayTree((SplayTreeInfo *)
235       image->artifacts);
236 }
237 \f
238 /*
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 %                                                                             %
241 %                                                                             %
242 %                                                                             %
243 %   G e t I m a g e A r t i f a c t                                           %
244 %                                                                             %
245 %                                                                             %
246 %                                                                             %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 %
249 %  GetImageArtifact() gets a value associated with an image artifact.
250 %  If the requested artifact is NULL return the first artifact.
251 %
252 %  Note, returned string is a constant in the tree and should NOT be freed.
253 %
254 %  The format of the GetImageArtifact method is:
255 %
256 %      const char *GetImageArtifact(const Image *image,const char *key)
257 %
258 %  A description of each parameter follows:
259 %
260 %    o image: the image.
261 %
262 %    o key: the key.
263 %
264 */
265 MagickExport const char *GetImageArtifact(const Image *image,
266   const char *artifact)
267 {
268   register const char
269     *p;
270
271   assert(image != (Image *) NULL);
272   assert(image->signature == MagickSignature);
273   if (image->debug != MagickFalse)
274     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
275   p=(const char *) NULL;
276   if (artifact == (const char *) NULL)
277     {
278       ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
279       p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
280         image->artifacts);
281       return(p);
282     }
283   if (image->artifacts != (void *) NULL)
284     {
285       p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
286         image->artifacts,artifact);
287       if (p != (const char *) NULL)
288         return(p);
289     }
290   return(p);
291 }
292 \f
293 /*
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 %                                                                             %
296 %                                                                             %
297 %                                                                             %
298 %   G e t N e x t I m a g e A r t i f a c t                                   %
299 %                                                                             %
300 %                                                                             %
301 %                                                                             %
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 %
304 %  GetNextImageArtifact() gets the next image artifact value.
305 %
306 %  The format of the GetNextImageArtifact method is:
307 %
308 %      char *GetNextImageArtifact(const Image *image)
309 %
310 %  A description of each parameter follows:
311 %
312 %    o image: the image.
313 %
314 */
315 MagickExport char *GetNextImageArtifact(const Image *image)
316 {
317   assert(image != (Image *) NULL);
318   assert(image->signature == MagickSignature);
319   if (image->debug != MagickFalse)
320     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
321       image->filename);
322   if (image->artifacts == (void *) NULL)
323     return((char *) NULL);
324   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
325 }
326 \f
327 /*
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 %                                                                             %
330 %                                                                             %
331 %                                                                             %
332 %   R e m o v e I m a g e A r t i f a c t                                     %
333 %                                                                             %
334 %                                                                             %
335 %                                                                             %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 %
338 %  RemoveImageArtifact() removes an artifact from the image and returns its
339 %  value.
340 %
341 %  The format of the RemoveImageArtifact method is:
342 %
343 %      char *RemoveImageArtifact(Image *image,const char *artifact)
344 %
345 %  A description of each parameter follows:
346 %
347 %    o image: the image.
348 %
349 %    o artifact: the image artifact.
350 %
351 */
352 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
353 {
354   char
355     *value;
356
357   assert(image != (Image *) NULL);
358   assert(image->signature == MagickSignature);
359   if (image->debug != MagickFalse)
360     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
361       image->filename);
362   if (image->artifacts == (void *) NULL)
363     return((char *) NULL);
364   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
365     artifact);
366   return(value);
367 }
368 \f
369 /*
370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371 %                                                                             %
372 %                                                                             %
373 %                                                                             %
374 %   R e s e t I m a g e A r t i f a c t I t e r a t o r                       %
375 %                                                                             %
376 %                                                                             %
377 %                                                                             %
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 %
380 %  ResetImageArtifactIterator() resets the image artifact iterator.  Use it
381 %  in conjunction with GetNextImageArtifact() to iterate over all the values
382 %  associated with an image artifact.
383 %
384 %  The format of the ResetImageArtifactIterator method is:
385 %
386 %      ResetImageArtifactIterator(Image *image)
387 %
388 %  A description of each parameter follows:
389 %
390 %    o image: the image.
391 %
392 */
393 MagickExport void ResetImageArtifactIterator(const Image *image)
394 {
395   assert(image != (Image *) NULL);
396   assert(image->signature == MagickSignature);
397   if (image->debug != MagickFalse)
398     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
399       image->filename);
400   if (image->artifacts == (void *) NULL)
401     return;
402   ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
403 }
404 \f
405 /*
406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 %                                                                             %
408 %                                                                             %
409 %                                                                             %
410 %   S e t I m a g e A r t i f a c t                                           %
411 %                                                                             %
412 %                                                                             %
413 %                                                                             %
414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 %
416 %  SetImageArtifact() associates a value with an image artifact.
417 %
418 %  The format of the SetImageArtifact method is:
419 %
420 %      MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
421 %        const char *value)
422 %
423 %  A description of each parameter follows:
424 %
425 %    o image: the image.
426 %
427 %    o artifact: the image artifact.
428 %
429 %    o values: the image artifact values.
430 %
431 */
432 MagickExport MagickBooleanType SetImageArtifact(Image *image,
433   const char *artifact,const char *value)
434 {
435   MagickBooleanType
436     status;
437
438   assert(image != (Image *) NULL);
439   assert(image->signature == MagickSignature);
440   if (image->debug != MagickFalse)
441     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
442       image->filename);
443
444   /* Create tree if needed */
445   if (image->artifacts == (void *) NULL)
446     image->artifacts=NewSplayTree(CompareSplayTreeString,
447       RelinquishMagickMemory,RelinquishMagickMemory);
448
449   /* Delete artifact if NULL --  empty string values are valid! */
450   if (value == (const char *) NULL)
451     return(DeleteImageArtifact(image,artifact));
452
453   /* add artifact to splay-tree */
454   status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
455     ConstantString(artifact),ConstantString(value));
456   return(status);
457 }