MagickCore  6.9.12-67
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
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 % Cristy %
17 % March 2000 %
18 % %
19 % %
20 % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 
40 /*
41  Include declarations.
42 */
43 #include "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 */
100 MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
101  const Image *clone_image)
102 {
103  assert(image != (Image *) NULL);
104  assert(image->signature == MagickCoreSignature);
105  assert(clone_image != (const Image *) NULL);
106  assert(clone_image->signature == MagickCoreSignature);
107  if (IsEventLogging() != MagickFalse)
108  {
109  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
110  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
111  clone_image->filename);
112  }
113  if (clone_image->artifacts != (void *) NULL)
114  {
115  if (image->artifacts != (void *) NULL)
116  DestroyImageArtifacts(image);
117  image->artifacts=CloneSplayTree((SplayTreeInfo *) clone_image->artifacts,
118  (void *(*)(void *)) ConstantString,(void *(*)(void *)) ConstantString);
119  }
120  return(MagickTrue);
121 }
122 
123 /*
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 % %
126 % %
127 % %
128 % D e f i n e I m a g e A r t i f a c t %
129 % %
130 % %
131 % %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %
134 % DefineImageArtifact() associates a key/value pair with an image artifact.
135 %
136 % The format of the DefineImageArtifact method is:
137 %
138 % MagickBooleanType DefineImageArtifact(Image *image,
139 % const char *artifact)
140 %
141 % A description of each parameter follows:
142 %
143 % o image: the image.
144 %
145 % o artifact: the image artifact.
146 %
147 */
148 MagickExport MagickBooleanType DefineImageArtifact(Image *image,
149  const char *artifact)
150 {
151  char
152  key[MaxTextExtent],
153  value[MaxTextExtent];
154 
155  char
156  *p;
157 
158  assert(image != (Image *) NULL);
159  assert(artifact != (const char *) NULL);
160  (void) CopyMagickString(key,artifact,MaxTextExtent-1);
161  for (p=key; *p != '\0'; p++)
162  if (*p == '=')
163  break;
164  *value='\0';
165  if (*p == '=')
166  (void) CopyMagickString(value,p+1,MaxTextExtent);
167  *p='\0';
168  return(SetImageArtifact(image,key,value));
169 }
170 
171 /*
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % %
174 % %
175 % %
176 % D e l e t e I m a g e A r t i f a c t %
177 % %
178 % %
179 % %
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 %
182 % DeleteImageArtifact() deletes an image artifact.
183 %
184 % The format of the DeleteImageArtifact method is:
185 %
186 % MagickBooleanType DeleteImageArtifact(Image *image,const char *artifact)
187 %
188 % A description of each parameter follows:
189 %
190 % o image: the image.
191 %
192 % o artifact: the image artifact.
193 %
194 */
195 MagickExport MagickBooleanType DeleteImageArtifact(Image *image,
196  const char *artifact)
197 {
198  assert(image != (Image *) NULL);
199  assert(image->signature == MagickCoreSignature);
200  if (IsEventLogging() != MagickFalse)
201  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
202  if (image->artifacts == (void *) NULL)
203  return(MagickFalse);
204  return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->artifacts,artifact));
205 }
206 
207 /*
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 % %
210 % %
211 % %
212 % D e s t r o y I m a g e A r t i f a c t s %
213 % %
214 % %
215 % %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %
218 % DestroyImageArtifacts() releases memory associated with image artifact
219 % values.
220 %
221 % The format of the DestroyDefines method is:
222 %
223 % void DestroyImageArtifacts(Image *image)
224 %
225 % A description of each parameter follows:
226 %
227 % o image: the image.
228 %
229 */
230 MagickExport void DestroyImageArtifacts(Image *image)
231 {
232  assert(image != (Image *) NULL);
233  assert(image->signature == MagickCoreSignature);
234  if (IsEventLogging() != MagickFalse)
235  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
236  if (image->artifacts != (void *) NULL)
237  image->artifacts=(void *) DestroySplayTree((SplayTreeInfo *)
238  image->artifacts);
239 }
240 
241 /*
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % %
244 % %
245 % %
246 % G e t I m a g e A r t i f a c t %
247 % %
248 % %
249 % %
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 %
252 % GetImageArtifact() gets a value associated with an image artifact.
253 %
254 % Note, the artifact is a constant. Do not attempt to free it.
255 %
256 % The format of the GetImageArtifact method is:
257 %
258 % const char *GetImageArtifact(const Image *image,const char *key)
259 %
260 % A description of each parameter follows:
261 %
262 % o image: the image.
263 %
264 % o key: the key.
265 %
266 */
267 MagickExport const char *GetImageArtifact(const Image *image,
268  const char *artifact)
269 {
270  const char
271  *p;
272 
273  assert(image != (Image *) NULL);
274  assert(image->signature == MagickCoreSignature);
275  if (IsEventLogging() != MagickFalse)
276  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
277  p=(const char *) NULL;
278  if (artifact == (const char *) NULL)
279  {
280  ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
281  p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
282  image->artifacts);
283  return(p);
284  }
285  if (image->artifacts != (void *) NULL)
286  {
287  p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) image->artifacts,
288  artifact);
289  if (p != (const char *) NULL)
290  return(p);
291  }
292  return(p);
293 }
294 
295 /*
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 % %
298 % %
299 % %
300 % G e t N e x t I m a g e A r t i f a c t %
301 % %
302 % %
303 % %
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 %
306 % GetNextImageArtifact() gets the next image artifact value.
307 %
308 % The format of the GetNextImageArtifact method is:
309 %
310 % char *GetNextImageArtifact(const Image *image)
311 %
312 % A description of each parameter follows:
313 %
314 % o image: the image.
315 %
316 */
317 MagickExport char *GetNextImageArtifact(const Image *image)
318 {
319  assert(image != (Image *) NULL);
320  assert(image->signature == MagickCoreSignature);
321  if (IsEventLogging() != MagickFalse)
322  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
323  if (image->artifacts == (void *) NULL)
324  return((char *) NULL);
325  return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
326 }
327 
328 /*
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 % %
331 % %
332 % %
333 % R e m o v e I m a g e A r t i f a c t %
334 % %
335 % %
336 % %
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 %
339 % RemoveImageArtifact() removes an artifact from the image and returns its
340 % value.
341 %
342 % The format of the RemoveImageArtifact method is:
343 %
344 % char *RemoveImageArtifact(Image *image,const char *artifact)
345 %
346 % A description of each parameter follows:
347 %
348 % o image: the image.
349 %
350 % o artifact: the image artifact.
351 %
352 */
353 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
354 {
355  char
356  *value;
357 
358  assert(image != (Image *) NULL);
359  assert(image->signature == MagickCoreSignature);
360  if (IsEventLogging() != MagickFalse)
361  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",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 
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 == MagickCoreSignature);
397  if (IsEventLogging() != MagickFalse)
398  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
399  if (image->artifacts == (void *) NULL)
400  return;
401  ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
402 }
403 
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() sets a key-value pair in the image artifact namespace.
416 % Artifacts differ from properties. Properties are public and are generally
417 % exported to an external image format if the format supports it. Artifacts
418 % are private and are utilized by the internal ImageMagick API to modify the
419 % behavior of certain algorithms.
420 %
421 % The format of the SetImageArtifact method is:
422 %
423 % MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
424 % const char *value)
425 %
426 % A description of each parameter follows:
427 %
428 % o image: the image.
429 %
430 % o artifact: the image artifact key.
431 %
432 % o value: the image artifact value.
433 %
434 */
435 MagickExport MagickBooleanType SetImageArtifact(Image *image,
436  const char *artifact,const char *value)
437 {
438  MagickBooleanType
439  status;
440 
441  assert(image != (Image *) NULL);
442  assert(image->signature == MagickCoreSignature);
443  if (IsEventLogging() != MagickFalse)
444  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
445  /*
446  Create tree if needed.
447  */
448  if (image->artifacts == (void *) NULL)
449  image->artifacts=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
450  RelinquishMagickMemory);
451  /*
452  Delete artifact if NULL -- empty string values are valid!
453  */
454  if (value == (const char *) NULL)
455  return(DeleteImageArtifact(image,artifact));
456  /*
457  Add artifact to tree.
458  */
459  status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
460  ConstantString(artifact),ConstantString(value));
461  return(status);
462 }
Definition: image.h:152