]> granicus.if.org Git - imagemagick/blob - magick/artifact.c
(no commit message)
[imagemagick] / magick / 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-2011 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 "magick/studio.h"
44 #include "magick/artifact.h"
45 #include "magick/cache.h"
46 #include "magick/color.h"
47 #include "magick/compare.h"
48 #include "magick/constitute.h"
49 #include "magick/draw.h"
50 #include "magick/effect.h"
51 #include "magick/exception.h"
52 #include "magick/exception-private.h"
53 #include "magick/fx.h"
54 #include "magick/fx-private.h"
55 #include "magick/gem.h"
56 #include "magick/geometry.h"
57 #include "magick/image.h"
58 #include "magick/layer.h"
59 #include "magick/list.h"
60 #include "magick/memory_.h"
61 #include "magick/monitor.h"
62 #include "magick/montage.h"
63 #include "magick/option.h"
64 #include "magick/profile.h"
65 #include "magick/quantum.h"
66 #include "magick/resource_.h"
67 #include "magick/splay-tree.h"
68 #include "magick/signature-private.h"
69 #include "magick/statistic.h"
70 #include "magick/string_.h"
71 #include "magick/token.h"
72 #include "magick/utility.h"
73 #include "magick/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 %
251 %  Note, the artifact is a constant.  Do not attempt to free it.
252 %
253 %  The format of the GetImageArtifact method is:
254 %
255 %      const char *GetImageArtifact(const Image *image,const char *key)
256 %
257 %  A description of each parameter follows:
258 %
259 %    o image: the image.
260 %
261 %    o key: the key.
262 %
263 */
264 MagickExport const char *GetImageArtifact(const Image *image,
265   const char *artifact)
266 {
267   register const char
268     *p;
269
270   assert(image != (Image *) NULL);
271   assert(image->signature == MagickSignature);
272   if (image->debug != MagickFalse)
273     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
274   p=(const char *) NULL;
275   if (artifact == (const char *) NULL)
276     {
277       ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
278       p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
279         image->artifacts);
280       return(p);
281     }
282   if (image->artifacts != (void *) NULL)
283     {
284       p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
285         image->artifacts,artifact);
286       if (p != (const char *) NULL)
287         return(p);
288     }
289   return(p);
290 }
291 \f
292 /*
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 %                                                                             %
295 %                                                                             %
296 %                                                                             %
297 %   G e t N e x t I m a g e A r t i f a c t                                   %
298 %                                                                             %
299 %                                                                             %
300 %                                                                             %
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 %
303 %  GetNextImageArtifact() gets the next image artifact value.
304 %
305 %  The format of the GetNextImageArtifact method is:
306 %
307 %      char *GetNextImageArtifact(const Image *image)
308 %
309 %  A description of each parameter follows:
310 %
311 %    o image: the image.
312 %
313 */
314 MagickExport char *GetNextImageArtifact(const Image *image)
315 {
316   assert(image != (Image *) NULL);
317   assert(image->signature == MagickSignature);
318   if (image->debug != MagickFalse)
319     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
320       image->filename);
321   if (image->artifacts == (void *) NULL)
322     return((char *) NULL);
323   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
324 }
325 \f
326 /*
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 %                                                                             %
329 %                                                                             %
330 %                                                                             %
331 %   R e m o v e I m a g e A r t i f a c t                                     %
332 %                                                                             %
333 %                                                                             %
334 %                                                                             %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 %
337 %  RemoveImageArtifact() removes an artifact from the image and returns its
338 %  value.
339 %
340 %  The format of the RemoveImageArtifact method is:
341 %
342 %      char *RemoveImageArtifact(Image *image,const char *artifact)
343 %
344 %  A description of each parameter follows:
345 %
346 %    o image: the image.
347 %
348 %    o artifact: the image artifact.
349 %
350 */
351 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
352 {
353   char
354     *value;
355
356   assert(image != (Image *) NULL);
357   assert(image->signature == MagickSignature);
358   if (image->debug != MagickFalse)
359     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
360       image->filename);
361   if (image->artifacts == (void *) NULL)
362     return((char *) NULL);
363   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
364     artifact);
365   return(value);
366 }
367 \f
368 /*
369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370 %                                                                             %
371 %                                                                             %
372 %                                                                             %
373 %   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                       %
374 %                                                                             %
375 %                                                                             %
376 %                                                                             %
377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378 %
379 %  ResetImageArtifactIterator() resets the image artifact iterator.  Use it
380 %  in conjunction with GetNextImageArtifact() to iterate over all the values
381 %  associated with an image artifact.
382 %
383 %  The format of the ResetImageArtifactIterator method is:
384 %
385 %      ResetImageArtifactIterator(Image *image)
386 %
387 %  A description of each parameter follows:
388 %
389 %    o image: the image.
390 %
391 */
392 MagickExport void ResetImageArtifactIterator(const Image *image)
393 {
394   assert(image != (Image *) NULL);
395   assert(image->signature == MagickSignature);
396   if (image->debug != MagickFalse)
397     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
398       image->filename);
399   if (image->artifacts == (void *) NULL)
400     return;
401   ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
402 }
403 \f
404 /*
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 %                                                                             %
407 %                                                                             %
408 %                                                                             %
409 %   S e t I m a g e A r t i f a c t                                           %
410 %                                                                             %
411 %                                                                             %
412 %                                                                             %
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 %
415 %  SetImageArtifact() associates a value with an image artifact.
416 %
417 %  The format of the SetImageArtifact method is:
418 %
419 %      MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
420 %        const char *value)
421 %
422 %  A description of each parameter follows:
423 %
424 %    o image: the image.
425 %
426 %    o artifact: the image artifact.
427 %
428 %    o values: the image artifact values.
429 %
430 */
431 MagickExport MagickBooleanType SetImageArtifact(Image *image,
432   const char *artifact,const char *value)
433 {
434   MagickBooleanType
435     status;
436
437   assert(image != (Image *) NULL);
438   assert(image->signature == MagickSignature);
439   if (image->debug != MagickFalse)
440     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
441       image->filename);
442   if (image->artifacts == (void *) NULL)
443     image->artifacts=NewSplayTree(CompareSplayTreeString,
444       RelinquishMagickMemory,RelinquishMagickMemory);
445   if ((value == (const char *) NULL) || (*value == '\0'))
446     return(DeleteImageArtifact(image,artifact));
447   status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
448     ConstantString(artifact),ConstantString(value));
449   return(status);
450 }