root/ImageMagick/trunk/magick/artifact.c

Revision 1, 17.5 KB (checked in by cristy, 3 months ago)


Line 
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-2009 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
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
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*/
100MagickExport 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
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*/
143MagickExport 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
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*/
190MagickExport 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
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*/
226MagickExport 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
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%  The format of the GetImageArtifact method is:
252%
253%      const char *GetImageArtifact(const Image *image,const char *key)
254%
255%  A description of each parameter follows:
256%
257%    o image: the image.
258%
259%    o key: the key.
260%
261*/
262MagickExport const char *GetImageArtifact(const Image *image,
263  const char *artifact)
264{
265  register const char
266    *p;
267
268  assert(image != (Image *) NULL);
269  assert(image->signature == MagickSignature);
270  if (image->debug != MagickFalse)
271    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
272  p=(const char *) NULL;
273  if (artifact == (const char *) NULL)
274    {
275      ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
276      p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
277        image->artifacts);
278      return(p);
279    }
280  if (image->artifacts != (void *) NULL)
281    {
282      p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
283        image->artifacts,artifact);
284      if (p != (const char *) NULL)
285        return(p);
286    }
287  return(p);
288}
289
290/*
291%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292%                                                                             %
293%                                                                             %
294%                                                                             %
295%   G e t N e x t I m a g e A r t i f a c t                                   %
296%                                                                             %
297%                                                                             %
298%                                                                             %
299%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300%
301%  GetNextImageArtifact() gets the next image artifact value.
302%
303%  The format of the GetNextImageArtifact method is:
304%
305%      char *GetNextImageArtifact(const Image *image)
306%
307%  A description of each parameter follows:
308%
309%    o image: the image.
310%
311*/
312MagickExport char *GetNextImageArtifact(const Image *image)
313{
314  assert(image != (Image *) NULL);
315  assert(image->signature == MagickSignature);
316  if (image->debug != MagickFalse)
317    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
318      image->filename);
319  if (image->artifacts == (void *) NULL)
320    return((char *) NULL);
321  return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
322}
323
324/*
325%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326%                                                                             %
327%                                                                             %
328%                                                                             %
329%   R e m o v e I m a g e A r t i f a c t                                     %
330%                                                                             %
331%                                                                             %
332%                                                                             %
333%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334%
335%  RemoveImageArtifact() removes an artifact from the image and returns its
336%  value.
337%
338%  The format of the RemoveImageArtifact method is:
339%
340%      char *RemoveImageArtifact(Image *image,const char *artifact)
341%
342%  A description of each parameter follows:
343%
344%    o image: the image.
345%
346%    o artifact: the image artifact.
347%
348*/
349MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
350{
351  char
352    *value;
353
354  assert(image != (Image *) NULL);
355  assert(image->signature == MagickSignature);
356  if (image->debug != MagickFalse)
357    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
358      image->filename);
359  if (image->artifacts == (void *) NULL)
360    return((char *) NULL);
361  value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
362    artifact);
363  return(value);
364}
365
366/*
367%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368%                                                                             %
369%                                                                             %
370%                                                                             %
371%   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                       %
372%                                                                             %
373%                                                                             %
374%                                                                             %
375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376%
377%  ResetImageArtifactIterator() resets the image artifact iterator.  Use it
378%  in conjunction with GetNextImageArtifact() to iterate over all the values
379%  associated with an image artifact.
380%
381%  The format of the ResetImageArtifactIterator method is:
382%
383%      ResetImageArtifactIterator(Image *image)
384%
385%  A description of each parameter follows:
386%
387%    o image: the image.
388%
389*/
390MagickExport void ResetImageArtifactIterator(const Image *image)
391{
392  assert(image != (Image *) NULL);
393  assert(image->signature == MagickSignature);
394  if (image->debug != MagickFalse)
395    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
396      image->filename);
397  if (image->artifacts == (void *) NULL)
398    return;
399  ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
400}
401
402/*
403%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404%                                                                             %
405%                                                                             %
406%                                                                             %
407%   S e t I m a g e A r t i f a c t                                           %
408%                                                                             %
409%                                                                             %
410%                                                                             %
411%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412%
413%  SetImageArtifact() associates a value with an image artifact.
414%
415%  The format of the SetImageArtifact method is:
416%
417%      MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
418%        const char *value)
419%
420%  A description of each parameter follows:
421%
422%    o image: the image.
423%
424%    o artifact: the image artifact.
425%
426%    o values: the image artifact values.
427%
428*/
429MagickExport MagickBooleanType SetImageArtifact(Image *image,
430  const char *artifact,const char *value)
431{
432  MagickBooleanType
433    status;
434
435  assert(image != (Image *) NULL);
436  assert(image->signature == MagickSignature);
437  if (image->debug != MagickFalse)
438    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
439      image->filename);
440  if (image->artifacts == (void *) NULL)
441    image->artifacts=NewSplayTree(CompareSplayTreeString,
442      RelinquishMagickMemory,RelinquishMagickMemory);
443  if ((value == (const char *) NULL) || (*value == '\0'))
444    return(DeleteImageArtifact(image,artifact));
445  status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
446    ConstantString(artifact),ConstantString(value));
447  return(status);
448}
Note: See TracBrowser for help on using the browser.