MagickCore  6.7.5
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-2012 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 "MagickCore/studio.h"
00044 #include "MagickCore/artifact.h"
00045 #include "MagickCore/cache.h"
00046 #include "MagickCore/color.h"
00047 #include "MagickCore/compare.h"
00048 #include "MagickCore/constitute.h"
00049 #include "MagickCore/draw.h"
00050 #include "MagickCore/effect.h"
00051 #include "MagickCore/exception.h"
00052 #include "MagickCore/exception-private.h"
00053 #include "MagickCore/fx.h"
00054 #include "MagickCore/fx-private.h"
00055 #include "MagickCore/gem.h"
00056 #include "MagickCore/geometry.h"
00057 #include "MagickCore/image.h"
00058 #include "MagickCore/layer.h"
00059 #include "MagickCore/list.h"
00060 #include "MagickCore/memory_.h"
00061 #include "MagickCore/monitor.h"
00062 #include "MagickCore/montage.h"
00063 #include "MagickCore/option.h"
00064 #include "MagickCore/profile.h"
00065 #include "MagickCore/quantum.h"
00066 #include "MagickCore/resource_.h"
00067 #include "MagickCore/splay-tree.h"
00068 #include "MagickCore/signature-private.h"
00069 #include "MagickCore/statistic.h"
00070 #include "MagickCore/string_.h"
00071 #include "MagickCore/token.h"
00072 #include "MagickCore/utility.h"
00073 #include "MagickCore/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 %  Note, the artifact is a constant.  Do not attempt to free it.
00252 %
00253 %  The format of the GetImageArtifact method is:
00254 %
00255 %      const char *GetImageArtifact(const Image *image,const char *key)
00256 %
00257 %  A description of each parameter follows:
00258 %
00259 %    o image: the image.
00260 %
00261 %    o key: the key.
00262 %
00263 */
00264 MagickExport const char *GetImageArtifact(const Image *image,
00265   const char *artifact)
00266 {
00267   register const char
00268     *p;
00269 
00270   assert(image != (Image *) NULL);
00271   assert(image->signature == MagickSignature);
00272   if (image->debug != MagickFalse)
00273     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00274   p=(const char *) NULL;
00275   if (artifact == (const char *) NULL)
00276     {
00277       ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
00278       p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
00279         image->artifacts);
00280       return(p);
00281     }
00282   if (image->artifacts != (void *) NULL)
00283     {
00284       p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
00285         image->artifacts,artifact);
00286       if (p != (const char *) NULL)
00287         return(p);
00288     }
00289   return(p);
00290 }
00291 
00292 /*
00293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00294 %                                                                             %
00295 %                                                                             %
00296 %                                                                             %
00297 %   G e t N e x t I m a g e A r t i f a c t                                   %
00298 %                                                                             %
00299 %                                                                             %
00300 %                                                                             %
00301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00302 %
00303 %  GetNextImageArtifact() gets the next image artifact value.
00304 %
00305 %  The format of the GetNextImageArtifact method is:
00306 %
00307 %      char *GetNextImageArtifact(const Image *image)
00308 %
00309 %  A description of each parameter follows:
00310 %
00311 %    o image: the image.
00312 %
00313 */
00314 MagickExport char *GetNextImageArtifact(const Image *image)
00315 {
00316   assert(image != (Image *) NULL);
00317   assert(image->signature == MagickSignature);
00318   if (image->debug != MagickFalse)
00319     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00320       image->filename);
00321   if (image->artifacts == (void *) NULL)
00322     return((char *) NULL);
00323   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
00324 }
00325 
00326 /*
00327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00328 %                                                                             %
00329 %                                                                             %
00330 %                                                                             %
00331 %   R e m o v e I m a g e A r t i f a c t                                     %
00332 %                                                                             %
00333 %                                                                             %
00334 %                                                                             %
00335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00336 %
00337 %  RemoveImageArtifact() removes an artifact from the image and returns its
00338 %  value.
00339 %
00340 %  The format of the RemoveImageArtifact method is:
00341 %
00342 %      char *RemoveImageArtifact(Image *image,const char *artifact)
00343 %
00344 %  A description of each parameter follows:
00345 %
00346 %    o image: the image.
00347 %
00348 %    o artifact: the image artifact.
00349 %
00350 */
00351 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
00352 {
00353   char
00354     *value;
00355 
00356   assert(image != (Image *) NULL);
00357   assert(image->signature == MagickSignature);
00358   if (image->debug != MagickFalse)
00359     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00360       image->filename);
00361   if (image->artifacts == (void *) NULL)
00362     return((char *) NULL);
00363   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
00364     artifact);
00365   return(value);
00366 }
00367 
00368 /*
00369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00370 %                                                                             %
00371 %                                                                             %
00372 %                                                                             %
00373 %   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                       %
00374 %                                                                             %
00375 %                                                                             %
00376 %                                                                             %
00377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00378 %
00379 %  ResetImageArtifactIterator() resets the image artifact iterator.  Use it
00380 %  in conjunction with GetNextImageArtifact() to iterate over all the values
00381 %  associated with an image artifact.
00382 %
00383 %  The format of the ResetImageArtifactIterator method is:
00384 %
00385 %      ResetImageArtifactIterator(Image *image)
00386 %
00387 %  A description of each parameter follows:
00388 %
00389 %    o image: the image.
00390 %
00391 */
00392 MagickExport void ResetImageArtifactIterator(const Image *image)
00393 {
00394   assert(image != (Image *) NULL);
00395   assert(image->signature == MagickSignature);
00396   if (image->debug != MagickFalse)
00397     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00398       image->filename);
00399   if (image->artifacts == (void *) NULL)
00400     return;
00401   ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
00402 }
00403 
00404 /*
00405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00406 %                                                                             %
00407 %                                                                             %
00408 %                                                                             %
00409 %   S e t I m a g e A r t i f a c t                                           %
00410 %                                                                             %
00411 %                                                                             %
00412 %                                                                             %
00413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00414 %
00415 %  SetImageArtifact() associates a value with an image artifact.
00416 %
00417 %  The format of the SetImageArtifact method is:
00418 %
00419 %      MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
00420 %        const char *value)
00421 %
00422 %  A description of each parameter follows:
00423 %
00424 %    o image: the image.
00425 %
00426 %    o artifact: the image artifact.
00427 %
00428 %    o values: the image artifact values.
00429 %
00430 */
00431 MagickExport MagickBooleanType SetImageArtifact(Image *image,
00432   const char *artifact,const char *value)
00433 {
00434   MagickBooleanType
00435     status;
00436 
00437   assert(image != (Image *) NULL);
00438   assert(image->signature == MagickSignature);
00439   if (image->debug != MagickFalse)
00440     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00441       image->filename);
00442 
00443   /* Create tree if needed */
00444   if (image->artifacts == (void *) NULL)
00445     image->artifacts=NewSplayTree(CompareSplayTreeString,
00446       RelinquishMagickMemory,RelinquishMagickMemory);
00447   /* Delete artifact if NULL or empty */
00448   if ((value == (const char *) NULL) || (*value == '\0'))
00449     return(DeleteImageArtifact(image,artifact));
00450   /* add option to tree */
00451   status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
00452     ConstantString(artifact),ConstantString(value));
00453   return(status);
00454 }