artifact.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %            AAA   RRRR   TTTTT  IIIII  FFFFF   AAA    CCCC  TTTTT            %
00007 %           A   A  R   R    T      I    F      A   A  C        T              %
00008 %           AAAAA  RRRRR    T      I    FFF    AAAAA  C        T              %
00009 %           A   A  R R      T      I    F      A   A  C        T              %
00010 %           A   A  R  R     T    IIIII  F      A   A  CCCCC    T              %
00011 %                                                                             %
00012 %                                                                             %
00013 %                         MagickCore Artifact Methods                         %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                 March 2000                                  %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 %
00038 */
00039 
00040 /*
00041   Include declarations.
00042 */
00043 #include "magick/studio.h"
00044 #include "magick/artifact.h"
00045 #include "magick/cache.h"
00046 #include "magick/color.h"
00047 #include "magick/compare.h"
00048 #include "magick/constitute.h"
00049 #include "magick/draw.h"
00050 #include "magick/effect.h"
00051 #include "magick/exception.h"
00052 #include "magick/exception-private.h"
00053 #include "magick/fx.h"
00054 #include "magick/fx-private.h"
00055 #include "magick/gem.h"
00056 #include "magick/geometry.h"
00057 #include "magick/image.h"
00058 #include "magick/layer.h"
00059 #include "magick/list.h"
00060 #include "magick/memory_.h"
00061 #include "magick/monitor.h"
00062 #include "magick/montage.h"
00063 #include "magick/option.h"
00064 #include "magick/profile.h"
00065 #include "magick/quantum.h"
00066 #include "magick/resource_.h"
00067 #include "magick/splay-tree.h"
00068 #include "magick/signature-private.h"
00069 #include "magick/statistic.h"
00070 #include "magick/string_.h"
00071 #include "magick/token.h"
00072 #include "magick/utility.h"
00073 #include "magick/xml-tree.h"
00074 
00075 /*
00076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00077 %                                                                             %
00078 %                                                                             %
00079 %                                                                             %
00080 %   C l o n e I m a g e A r t i f a c t s                                     %
00081 %                                                                             %
00082 %                                                                             %
00083 %                                                                             %
00084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00085 %
00086 %  CloneImageArtifacts() clones one or more image artifacts.
00087 %
00088 %  The format of the CloneImageArtifacts method is:
00089 %
00090 %      MagickBooleanType CloneImageArtifacts(Image *image,
00091 %        const Image *clone_image)
00092 %
00093 %  A description of each parameter follows:
00094 %
00095 %    o image: the image.
00096 %
00097 %    o clone_image: the clone image.
00098 %
00099 */
00100 MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
00101   const Image *clone_image)
00102 {
00103   assert(image != (Image *) NULL);
00104   assert(image->signature == MagickSignature);
00105   if (image->debug != MagickFalse)
00106     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00107   assert(clone_image != (const Image *) NULL);
00108   assert(clone_image->signature == MagickSignature);
00109   if (clone_image->debug != MagickFalse)
00110     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00111       clone_image->filename);
00112   if (clone_image->artifacts != (void *) NULL)
00113     image->artifacts=CloneSplayTree((SplayTreeInfo *) clone_image->artifacts,
00114       (void *(*)(void *)) ConstantString,(void *(*)(void *)) ConstantString);
00115   return(MagickTrue);
00116 }
00117 
00118 /*
00119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00120 %                                                                             %
00121 %                                                                             %
00122 %                                                                             %
00123 %   D e f i n e I m a g e A r t i f a c t                                     %
00124 %                                                                             %
00125 %                                                                             %
00126 %                                                                             %
00127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00128 %
00129 %  DefineImageArtifact() associates a key/value pair with an image artifact.
00130 %
00131 %  The format of the DefineImageArtifact method is:
00132 %
00133 %      MagickBooleanType DefineImageArtifact(Image *image,
00134 %        const char *artifact)
00135 %
00136 %  A description of each parameter follows:
00137 %
00138 %    o image: the image.
00139 %
00140 %    o artifact: the image artifact.
00141 %
00142 */
00143 MagickExport MagickBooleanType DefineImageArtifact(Image *image,
00144   const char *artifact)
00145 {
00146   char
00147     key[MaxTextExtent],
00148     value[MaxTextExtent];
00149 
00150   register char
00151     *p;
00152 
00153   assert(image != (Image *) NULL);
00154   assert(artifact != (const char *) NULL);
00155   (void) CopyMagickString(key,artifact,MaxTextExtent-1);
00156   for (p=key; *p != '\0'; p++)
00157     if (*p == '=')
00158       break;
00159   *value='\0';
00160   if (*p == '=')
00161     (void) CopyMagickString(value,p+1,MaxTextExtent);
00162   *p='\0';
00163   return(SetImageArtifact(image,key,value));
00164 }
00165 
00166 /*
00167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00168 %                                                                             %
00169 %                                                                             %
00170 %                                                                             %
00171 %   D e l e t e I m a g e A r t i f a c t                                     %
00172 %                                                                             %
00173 %                                                                             %
00174 %                                                                             %
00175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00176 %
00177 %  DeleteImageArtifact() deletes an image artifact.
00178 %
00179 %  The format of the DeleteImageArtifact method is:
00180 %
00181 %      MagickBooleanType DeleteImageArtifact(Image *image,const char *artifact)
00182 %
00183 %  A description of each parameter follows:
00184 %
00185 %    o image: the image.
00186 %
00187 %    o artifact: the image artifact.
00188 %
00189 */
00190 MagickExport MagickBooleanType DeleteImageArtifact(Image *image,
00191   const char *artifact)
00192 {
00193   assert(image != (Image *) NULL);
00194   assert(image->signature == MagickSignature);
00195   if (image->debug != MagickFalse)
00196     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00197       image->filename);
00198   if (image->artifacts == (void *) NULL)
00199     return(MagickFalse);
00200   return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->artifacts,artifact));
00201 }
00202 
00203 /*
00204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00205 %                                                                             %
00206 %                                                                             %
00207 %                                                                             %
00208 %   D e s t r o y I m a g e A r t i f a c t s                                 %
00209 %                                                                             %
00210 %                                                                             %
00211 %                                                                             %
00212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00213 %
00214 %  DestroyImageArtifacts() releases memory associated with image artifact
00215 %  values.
00216 %
00217 %  The format of the DestroyDefines method is:
00218 %
00219 %      void DestroyImageArtifacts(Image *image)
00220 %
00221 %  A description of each parameter follows:
00222 %
00223 %    o image: the image.
00224 %
00225 */
00226 MagickExport void DestroyImageArtifacts(Image *image)
00227 {
00228   assert(image != (Image *) NULL);
00229   assert(image->signature == MagickSignature);
00230   if (image->debug != MagickFalse)
00231     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00232       image->filename);
00233   if (image->artifacts != (void *) NULL)
00234     image->artifacts=(void *) DestroySplayTree((SplayTreeInfo *)
00235       image->artifacts);
00236 }
00237 
00238 /*
00239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00240 %                                                                             %
00241 %                                                                             %
00242 %                                                                             %
00243 %   G e t I m a g e A r t i f a c t                                           %
00244 %                                                                             %
00245 %                                                                             %
00246 %                                                                             %
00247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00248 %
00249 %  GetImageArtifact() gets a value associated with an image artifact.
00250 %
00251 %  The format of the GetImageArtifact method is:
00252 %
00253 %      const char *GetImageArtifact(const Image *image,const char *key)
00254 %
00255 %  A description of each parameter follows:
00256 %
00257 %    o image: the image.
00258 %
00259 %    o key: the key.
00260 %
00261 */
00262 MagickExport const char *GetImageArtifact(const Image *image,
00263   const char *artifact)
00264 {
00265   register const char
00266     *p;
00267 
00268   assert(image != (Image *) NULL);
00269   assert(image->signature == MagickSignature);
00270   if (image->debug != MagickFalse)
00271     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00272   p=(const char *) NULL;
00273   if (artifact == (const char *) NULL)
00274     {
00275       ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
00276       p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
00277         image->artifacts);
00278       return(p);
00279     }
00280   if (image->artifacts != (void *) NULL)
00281     {
00282       p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
00283         image->artifacts,artifact);
00284       if (p != (const char *) NULL)
00285         return(p);
00286     }
00287   return(p);
00288 }
00289 
00290 /*
00291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00292 %                                                                             %
00293 %                                                                             %
00294 %                                                                             %
00295 %   G e t N e x t I m a g e A r t i f a c t                                   %
00296 %                                                                             %
00297 %                                                                             %
00298 %                                                                             %
00299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00300 %
00301 %  GetNextImageArtifact() gets the next image artifact value.
00302 %
00303 %  The format of the GetNextImageArtifact method is:
00304 %
00305 %      char *GetNextImageArtifact(const Image *image)
00306 %
00307 %  A description of each parameter follows:
00308 %
00309 %    o image: the image.
00310 %
00311 */
00312 MagickExport char *GetNextImageArtifact(const Image *image)
00313 {
00314   assert(image != (Image *) NULL);
00315   assert(image->signature == MagickSignature);
00316   if (image->debug != MagickFalse)
00317     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00318       image->filename);
00319   if (image->artifacts == (void *) NULL)
00320     return((char *) NULL);
00321   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
00322 }
00323 
00324 /*
00325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00326 %                                                                             %
00327 %                                                                             %
00328 %                                                                             %
00329 %   R e m o v e I m a g e A r t i f a c t                                     %
00330 %                                                                             %
00331 %                                                                             %
00332 %                                                                             %
00333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00334 %
00335 %  RemoveImageArtifact() removes an artifact from the image and returns its
00336 %  value.
00337 %
00338 %  The format of the RemoveImageArtifact method is:
00339 %
00340 %      char *RemoveImageArtifact(Image *image,const char *artifact)
00341 %
00342 %  A description of each parameter follows:
00343 %
00344 %    o image: the image.
00345 %
00346 %    o artifact: the image artifact.
00347 %
00348 */
00349 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
00350 {
00351   char
00352     *value;
00353 
00354   assert(image != (Image *) NULL);
00355   assert(image->signature == MagickSignature);
00356   if (image->debug != MagickFalse)
00357     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00358       image->filename);
00359   if (image->artifacts == (void *) NULL)
00360     return((char *) NULL);
00361   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
00362     artifact);
00363   return(value);
00364 }
00365 
00366 /*
00367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00368 %                                                                             %
00369 %                                                                             %
00370 %                                                                             %
00371 %   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                       %
00372 %                                                                             %
00373 %                                                                             %
00374 %                                                                             %
00375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00376 %
00377 %  ResetImageArtifactIterator() resets the image artifact iterator.  Use it
00378 %  in conjunction with GetNextImageArtifact() to iterate over all the values
00379 %  associated with an image artifact.
00380 %
00381 %  The format of the ResetImageArtifactIterator method is:
00382 %
00383 %      ResetImageArtifactIterator(Image *image)
00384 %
00385 %  A description of each parameter follows:
00386 %
00387 %    o image: the image.
00388 %
00389 */
00390 MagickExport void ResetImageArtifactIterator(const Image *image)
00391 {
00392   assert(image != (Image *) NULL);
00393   assert(image->signature == MagickSignature);
00394   if (image->debug != MagickFalse)
00395     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00396       image->filename);
00397   if (image->artifacts == (void *) NULL)
00398     return;
00399   ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
00400 }
00401 
00402 /*
00403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00404 %                                                                             %
00405 %                                                                             %
00406 %                                                                             %
00407 %   S e t I m a g e A r t i f a c t                                           %
00408 %                                                                             %
00409 %                                                                             %
00410 %                                                                             %
00411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00412 %
00413 %  SetImageArtifact() associates a value with an image artifact.
00414 %
00415 %  The format of the SetImageArtifact method is:
00416 %
00417 %      MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
00418 %        const char *value)
00419 %
00420 %  A description of each parameter follows:
00421 %
00422 %    o image: the image.
00423 %
00424 %    o artifact: the image artifact.
00425 %
00426 %    o values: the image artifact values.
00427 %
00428 */
00429 MagickExport MagickBooleanType SetImageArtifact(Image *image,
00430   const char *artifact,const char *value)
00431 {
00432   MagickBooleanType
00433     status;
00434 
00435   assert(image != (Image *) NULL);
00436   assert(image->signature == MagickSignature);
00437   if (image->debug != MagickFalse)
00438     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00439       image->filename);
00440   if (image->artifacts == (void *) NULL)
00441     image->artifacts=NewSplayTree(CompareSplayTreeString,
00442       RelinquishMagickMemory,RelinquishMagickMemory);
00443   if ((value == (const char *) NULL) || (*value == '\0'))
00444     return(DeleteImageArtifact(image,artifact));
00445   status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
00446     ConstantString(artifact),ConstantString(value));
00447   return(status);
00448 }

Generated on 19 Nov 2009 for MagickCore by  doxygen 1.6.1