attribute.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %        AAA   TTTTT  TTTTT  RRRR   IIIII  BBBB   U   U  TTTTT  EEEEE         %
00007 %       A   A    T      T    R   R    I    B   B  U   U    T    E             %
00008 %       AAAAA    T      T    RRRR     I    BBBB   U   U    T    EEE           %
00009 %       A   A    T      T    R R      I    B   B  U   U    T    E             %
00010 %       A   A    T      T    R  R   IIIII  BBBB    UUU     T    EEEEE         %
00011 %                                                                             %
00012 %                                                                             %
00013 %                       Methods to Get/Set Attributes                         %
00014 %                                                                             %
00015 %                             Software Design                                 %
00016 %                               John Cristy                                   %
00017 %                              February 2000                                  %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2006 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 %  The image attributes methods gets, sets, or destroys attributes associated
00037 %  with a particular image (e.g. comments, copyright, author, etc).
00038 %
00039 %  These methods are deprecated.  Use the Get/SetImageProperties() methods
00040 %  instead.
00041 %
00042 */
00043 
00044 /*
00045   Include declarations.
00046 */
00047 #include "magick/studio.h"
00048 #include "magick/attribute.h"
00049 #include "magick/blob.h"
00050 #include "magick/draw.h"
00051 #include "magick/exception-private.h"
00052 #include "magick/fx-private.h"
00053 #include "magick/geometry.h"
00054 #include "magick/list.h"
00055 #include "magick/memory_.h"
00056 #include "magick/option.h"
00057 #include "magick/profile.h"
00058 #include "magick/property.h"
00059 #include "magick/signature.h"
00060 #include "magick/splay-tree.h"
00061 #include "magick/statistic.h"
00062 #include "magick/string_.h"
00063 #include "magick/token.h"
00064 #include "magick/utility.h"
00065 
00066 /*
00067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00068 %                                                                             %
00069 %                                                                             %
00070 %                                                                             %
00071 %   C l o n e I m a g e A t t r i b u t e s                                   %
00072 %                                                                             %
00073 %                                                                             %
00074 %                                                                             %
00075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00076 %
00077 %  CloneImageAttributes() clones one or more image attributes.
00078 %
00079 %  The format of the CloneImageAttributes method is:
00080 %
00081 %      MagickBooleanType CloneImageAttributes(Image *image,
00082 %        const Image *clone_image)
00083 %
00084 %  A description of each parameter follows:
00085 %
00086 %    o image: The image.
00087 %
00088 %    o clone_image: The clone image.
00089 %
00090 */
00091 MagickExport MagickBooleanType CloneImageAttributes(Image *image,
00092   const Image *clone_image)
00093 {
00094   return(CloneImageProperties(image,clone_image));
00095 }
00096 
00097 /*
00098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00099 %                                                                             %
00100 %                                                                             %
00101 %                                                                             %
00102 %   D e l e t e I m a g e O p t i o n                                         %
00103 %                                                                             %
00104 %                                                                             %
00105 %                                                                             %
00106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00107 %
00108 %  DeleteImageAttribute() deletes an attribute from the image.
00109 %
00110 %  The format of the DeleteImageAttribute method is:
00111 %
00112 %      MagickBooleanType DeleteImageAttribute(Image *image,const char *key)
00113 %
00114 %  A description of each parameter follows:
00115 %
00116 %    o image: The image info.
00117 %
00118 %    o key: The image key.
00119 %
00120 */
00121 MagickExport MagickBooleanType DeleteImageAttribute(Image *image,
00122   const char *key)
00123 {
00124   return(DeleteImageProperty(image,key));
00125 }
00126 
00127 /*
00128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00129 %                                                                             %
00130 %                                                                             %
00131 %                                                                             %
00132 %   D e s t r o y I m a g e A t t r i b u t e s                               %
00133 %                                                                             %
00134 %                                                                             %
00135 %                                                                             %
00136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00137 %
00138 %  DestroyImageAttributes() deallocates memory associated with the image
00139 %  attribute list.
00140 %
00141 %  The format of the DestroyImageAttributes method is:
00142 %
00143 %      DestroyImageAttributes(Image *image)
00144 %
00145 %  A description of each parameter follows:
00146 %
00147 %    o image: The image.
00148 %
00149 */
00150 MagickExport void DestroyImageAttributes(Image *image)
00151 {
00152   assert(image != (Image *) NULL);
00153   assert(image->signature == MagickSignature);
00154   if (image->debug != MagickFalse)
00155     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00156   if (image->attributes != (void *) NULL)
00157     image->attributes=(void *) DestroySplayTree((SplayTreeInfo *)
00158       image->attributes);
00159 }
00160 
00161 /*
00162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00163 %                                                                             %
00164 %                                                                             %
00165 %                                                                             %
00166 %  F o r m a t I m a g e A t t r i b u t e                                    %
00167 %                                                                             %
00168 %                                                                             %
00169 %                                                                             %
00170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00171 %
00172 %  FormatImageAttribute() permits formatted key/value pairs to be saved as an
00173 %  image attribute.
00174 %
00175 %  The format of the FormatImageAttribute method is:
00176 %
00177 %      MagickBooleanType FormatImageAttribute(Image *image,const char *key,
00178 %        const char *format,...)
00179 %
00180 %  A description of each parameter follows.
00181 %
00182 %   o  image:  The image.
00183 %
00184 %   o  key:  The attribute key.
00185 %
00186 %   o  format:  A string describing the format to use to write the remaining
00187 %      arguments.
00188 %
00189 */
00190 
00191 MagickExport MagickBooleanType FormatImageAttributeList(Image *image,
00192   const char *key,const char *format,va_list operands)
00193 {
00194   char
00195     value[MaxTextExtent];
00196 
00197   int
00198     n;
00199 
00200 #if defined(HAVE_VSNPRINTF)
00201   n=vsnprintf(value,MaxTextExtent,format,operands);
00202 #else
00203   n=vsprintf(value,format,operands);
00204 #endif
00205   if (n < 0)
00206     value[MaxTextExtent-1]='\0';
00207   return(SetImageAttribute(image,key,value));
00208 }
00209 
00210 MagickExport MagickBooleanType FormatImageAttribute(Image *image,
00211   const char *key,const char *format,...)
00212 {
00213   MagickBooleanType
00214     status;
00215 
00216   va_list
00217     operands;
00218 
00219   va_start(operands,format);
00220   status=FormatImageAttributeList(image,key,format,operands);
00221   va_end(operands);
00222   return(status);
00223 }
00224 
00225 /*
00226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00227 %                                                                             %
00228 %                                                                             %
00229 %                                                                             %
00230 %   G e t I m a g e A t t r i b u t e                                         %
00231 %                                                                             %
00232 %                                                                             %
00233 %                                                                             %
00234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00235 %
00236 %  GetImageAttribute() searches the list of image attributes and returns
00237 %  a pointer to the attribute if it exists otherwise NULL.
00238 %
00239 %  The format of the GetImageAttribute method is:
00240 %
00241 %      const ImageAttribute *GetImageAttribute(const Image *image,
00242 %        const char *key)
00243 %
00244 %  A description of each parameter follows:
00245 %
00246 %    o image: The image.
00247 %
00248 %    o key:  These character strings are the name of an image attribute to
00249 %      return.
00250 %
00251 */
00252 
00253 static void *DestroyAttribute(void *attribute)
00254 {
00255   register ImageAttribute
00256     *p;
00257 
00258   p=(ImageAttribute *) attribute;
00259   if (p->value != (char *) NULL)
00260     p->value=(char *) RelinquishMagickMemory(p->value);
00261   return(RelinquishMagickMemory(p));
00262 }
00263 
00264 MagickExport const ImageAttribute *GetImageAttribute(const Image *image,
00265   const char *key)
00266 {
00267   const char
00268     *value;
00269 
00270   ImageAttribute
00271     *attribute;
00272 
00273   value=GetImageProperty(image,key);
00274   if (value == (const char *) NULL)
00275     return((const ImageAttribute *) NULL);
00276   if (image->attributes == (void *) NULL)
00277     ((Image *) image)->attributes=NewSplayTree(CompareSplayTreeString,
00278       RelinquishMagickMemory,DestroyAttribute);
00279   else
00280     {
00281       const ImageAttribute
00282         *attribute;
00283 
00284       attribute=(const ImageAttribute *) GetValueFromSplayTree((SplayTreeInfo *)
00285         image->attributes,key);
00286       if (attribute != (const ImageAttribute *) NULL)
00287         return(attribute);
00288     }
00289   attribute=(ImageAttribute *) AcquireMagickMemory(sizeof(*attribute));
00290   if (attribute == (ImageAttribute *) NULL)
00291     ThrowMagickFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00292       key);
00293   (void) ResetMagickMemory(attribute,0,sizeof(*attribute));
00294   attribute->key=ConstantString(key);
00295   attribute->value=ConstantString(value);
00296   (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->attributes,
00297     attribute->key,attribute);
00298   return((const ImageAttribute *) attribute);
00299 }
00300 
00301 /*
00302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00303 %                                                                             %
00304 %                                                                             %
00305 %                                                                             %
00306 %   G e t I m a g e C l i p p i n g P a t h A t t r i b u t e                 %
00307 %                                                                             %
00308 %                                                                             %
00309 %                                                                             %
00310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00311 %
00312 %  GetImageClippingPathAttribute() searches the list of image attributes and
00313 %  returns a pointer to a clipping path if it exists otherwise NULL.
00314 %
00315 %  The format of the GetImageClippingPathAttribute method is:
00316 %
00317 %      const ImageAttribute *GetImageClippingPathAttribute(Image *image)
00318 %
00319 %  A description of each parameter follows:
00320 %
00321 %    o attribute:  Method GetImageClippingPathAttribute returns the clipping
00322 %      path if it exists otherwise NULL.
00323 %
00324 %    o image: The image.
00325 %
00326 */
00327 MagickExport const ImageAttribute *GetImageClippingPathAttribute(Image *image)
00328 {
00329   return(GetImageAttribute(image,"8BIM:1999,2998"));
00330 }
00331 
00332 /*
00333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00334 %                                                                             %
00335 %                                                                             %
00336 %                                                                             %
00337 %   G e t N e x t I m a g e A t t r i b u t e                                 %
00338 %                                                                             %
00339 %                                                                             %
00340 %                                                                             %
00341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00342 %
00343 %  GetNextImageAttribute() gets the next image attribute.
00344 %
00345 %  The format of the GetNextImageAttribute method is:
00346 %
00347 %      const ImageAttribute *GetNextImageAttribute(const Image *image)
00348 %
00349 %  A description of each parameter follows:
00350 %
00351 %    o image: The image.
00352 %
00353 */
00354 MagickExport const ImageAttribute *GetNextImageAttribute(const Image *image)
00355 {
00356   const char
00357     *property;
00358 
00359   property=GetNextImageProperty(image);
00360   if (property == (const char *) NULL)
00361     return((const ImageAttribute *) NULL);
00362   return(GetImageAttribute(image,property));
00363 }
00364 
00365 /*
00366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00367 %                                                                             %
00368 %                                                                             %
00369 %                                                                             %
00370 %   I n t e r p r e t I m a g e A t t r i b u t e s                           %
00371 %                                                                             %
00372 %                                                                             %
00373 %                                                                             %
00374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00375 %
00376 %  InterpretImageAttributes() replaces any embedded formatting characters with
00377 %  the appropriate image attribute and returns the translated text.
00378 %
00379 %  The format of the InterpretImageAttributes method is:
00380 %
00381 %      char *InterpretImageAttributes(const ImageInfo *image_info,Image *image,
00382 %        const char *embed_text)
00383 %
00384 %  A description of each parameter follows:
00385 %
00386 %    o image_info: The image info.
00387 %
00388 %    o image: The image.
00389 %
00390 %    o embed_text: The address of a character string containing the embedded
00391 %      formatting characters.
00392 %
00393 */
00394 MagickExport char *InterpretImageAttributes(const ImageInfo *image_info,
00395   Image *image,const char *embed_text)
00396 {
00397   return(InterpretImageProperties(image_info,image,embed_text));
00398 }
00399 
00400 /*
00401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00402 %                                                                             %
00403 %                                                                             %
00404 %                                                                             %
00405 %   R e s e t I m a g e A t t r i b u t e I t e r a t o r                     %
00406 %                                                                             %
00407 %                                                                             %
00408 %                                                                             %
00409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00410 %
00411 %  ResetImageAttributeIterator() resets the image attributes iterator.  Use it
00412 %  in conjunction with GetNextImageAttribute() to iterate over all the values
00413 %  associated with an image.
00414 %
00415 %  The format of the ResetImageAttributeIterator method is:
00416 %
00417 %      ResetImageAttributeIterator(const ImageInfo *image)
00418 %
00419 %  A description of each parameter follows:
00420 %
00421 %    o image: The image.
00422 %
00423 */
00424 MagickExport void ResetImageAttributeIterator(const Image *image)
00425 {
00426   ResetImagePropertyIterator(image);
00427 }
00428 
00429 /*
00430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00431 %                                                                             %
00432 %                                                                             %
00433 %                                                                             %
00434 %   S e t I m a g e A t t r i b u t e                                         %
00435 %                                                                             %
00436 %                                                                             %
00437 %                                                                             %
00438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00439 %
00440 %  SetImageAttribute() searches the list of image attributes and replaces the
00441 %  attribute value.  If it is not found in the list, the attribute name
00442 %  and value is added to the list.   
00443 %
00444 %  The format of the SetImageAttribute method is:
00445 %
00446 %       MagickBooleanType SetImageAttribute(Image *image,const char *key,
00447 %         const char *value)
00448 %
00449 %  A description of each parameter follows:
00450 %
00451 %    o image: The image.
00452 %
00453 %    o key: The key.
00454 %
00455 %    o value: The value.
00456 %
00457 */
00458 MagickExport MagickBooleanType SetImageAttribute(Image *image,const char *key,
00459   const char *value)
00460 {
00461   return(SetImageProperty(image,key,value));
00462 }

Generated on Thu Sep 4 11:42:42 2008 for ImageMagick by  doxygen 1.5.6