magick.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                  M   M   AAA    GGGG  IIIII   CCCC  K   K                   %
00007 %                  MM MM  A   A  G        I    C      K  K                    %
00008 %                  M M M  AAAAA  G GGG    I    C      KKK                     %
00009 %                  M   M  A   A  G   G    I    C      K  K                    %
00010 %                  M   M  A   A   GGGG  IIIII   CCCC  K   K                   %
00011 %                                                                             %
00012 %                                                                             %
00013 %               Methods to Read or List ImageMagick Image formats             %
00014 %                                                                             %
00015 %                            Software Design                                  %
00016 %                            Bob Friesenhahn                                  %
00017 %                              John Cristy                                    %
00018 %                             November 1998                                   %
00019 %                                                                             %
00020 %                                                                             %
00021 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
00022 %  dedicated to making software imaging solutions freely available.           %
00023 %                                                                             %
00024 %  You may not use this file except in compliance with the License.  You may  %
00025 %  obtain a copy of the License at                                            %
00026 %                                                                             %
00027 %    http://www.imagemagick.org/script/license.php                            %
00028 %                                                                             %
00029 %  Unless required by applicable law or agreed to in writing, software        %
00030 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00031 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00032 %  See the License for the specific language governing permissions and        %
00033 %  limitations under the License.                                             %
00034 %                                                                             %
00035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00036 %
00037 %
00038 */
00039 
00040 /*
00041   Include declarations.
00042 */
00043 #include "magick/studio.h"
00044 #include "magick/blob.h"
00045 #include "magick/cache.h"
00046 #include "magick/coder.h"
00047 #include "magick/client.h"
00048 #include "magick/coder.h"
00049 #include "magick/configure.h"
00050 #include "magick/constitute.h"
00051 #include "magick/delegate.h"
00052 #include "magick/draw.h"
00053 #include "magick/exception.h"
00054 #include "magick/exception-private.h"
00055 #include "magick/locale_.h"
00056 #include "magick/log.h"
00057 #include "magick/magic.h"
00058 #include "magick/magick.h"
00059 #include "magick/memory_.h"
00060 #include "magick/mime.h"
00061 #include "magick/module.h"
00062 #if defined(__WINDOWS__)
00063 # include "magick/nt-feature.h"
00064 #endif
00065 #include "magick/random_.h"
00066 #include "magick/registry.h"
00067 #include "magick/resource_.h"
00068 #include "magick/policy.h"
00069 #include "magick/semaphore.h"
00070 #include "magick/signature-private.h"
00071 #include "magick/splay-tree.h"
00072 #include "magick/string_.h"
00073 #include "magick/thread_.h"
00074 #include "magick/thread-private.h"
00075 #include "magick/token.h"
00076 #include "magick/utility.h"
00077 #include "magick/xwindow-private.h"
00078 
00079 /*
00080   Define declarations.
00081 */
00082 #if !defined(MAGICKCORE_RETSIGTYPE)
00083 # define MAGICKCORE_RETSIGTYPE  void
00084 #endif
00085 #if !defined(SIG_DFL)
00086 # define SIG_DFL  ((SignalHandler *) 0)
00087 #endif
00088 #if !defined(SIG_ERR)
00089 # define SIG_ERR  ((SignalHandler *) -1)
00090 #endif
00091 #if !defined(SIGMAX)
00092 #define SIGMAX  64
00093 #endif
00094 
00095 /*
00096   Typedef declarations.
00097 */
00098 typedef MAGICKCORE_RETSIGTYPE
00099   SignalHandler(int);
00100 
00101 /*
00102   Global declarations.
00103 */
00104 static SemaphoreInfo
00105   *magick_semaphore = (SemaphoreInfo *) NULL;
00106 
00107 static SignalHandler
00108   *signal_handlers[SIGMAX] = { (SignalHandler *) NULL };
00109 
00110 static SplayTreeInfo
00111   *magick_list = (SplayTreeInfo *) NULL;
00112 
00113 static volatile MagickBooleanType
00114   instantiate_magick = MagickFalse;  /* double-checked locking pattern */
00115 
00116 /*
00117   Forward declarations.
00118 */
00119 static MagickBooleanType
00120   InitializeMagickList(ExceptionInfo *);
00121 
00122 /*
00123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00124 %                                                                             %
00125 %                                                                             %
00126 %                                                                             %
00127 +   D e s t r o y M a g i c k L i s t                                         %
00128 %                                                                             %
00129 %                                                                             %
00130 %                                                                             %
00131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00132 %
00133 %  DestroyMagickList() deallocates memory associated with the MagickInfo list.
00134 %
00135 %  The format of the DestroyMagickList method is:
00136 %
00137 %      void DestroyMagickList(void)
00138 %
00139 */
00140 MagickExport void DestroyMagickList(void)
00141 {
00142   AcquireSemaphoreInfo(&magick_semaphore);
00143   if (magick_list != (SplayTreeInfo *) NULL)
00144     magick_list=DestroySplayTree(magick_list);
00145   instantiate_magick=MagickFalse;
00146   RelinquishSemaphoreInfo(magick_semaphore);
00147   DestroySemaphoreInfo(&magick_semaphore);
00148 #if !defined(MAGICKCORE_BUILD_MODULES)
00149   UnregisterStaticModules();
00150 #endif
00151 #if defined(MAGICKCORE_MODULES_SUPPORT)
00152   DestroyModuleList();
00153 #endif
00154 }
00155 
00156 /*
00157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00158 %                                                                             %
00159 %                                                                             %
00160 %                                                                             %
00161 +   G e t I m a g e D e c o d e r                                             %
00162 %                                                                             %
00163 %                                                                             %
00164 %                                                                             %
00165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00166 %
00167 %  GetImageDecoder() returns the image decoder.
00168 %
00169 %  The format of the GetImageDecoder method is:
00170 %
00171 %      DecodeImageHandler *GetImageDecoder(const MagickInfo *magick_info)
00172 %
00173 %  A description of each parameter follows:
00174 %
00175 %    o magick_info:  The magick info.
00176 %
00177 */
00178 MagickExport DecodeImageHandler *GetImageDecoder(const MagickInfo *magick_info)
00179 {
00180   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00181   assert(magick_info != (MagickInfo *) NULL);
00182   assert(magick_info->signature == MagickSignature);
00183   return(magick_info->decoder);
00184 }
00185 
00186 /*
00187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00188 %                                                                             %
00189 %                                                                             %
00190 %                                                                             %
00191 +   G e t I m a g e E n c o d e r                                             %
00192 %                                                                             %
00193 %                                                                             %
00194 %                                                                             %
00195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00196 %
00197 %  GetImageEncoder() returns the image encoder.
00198 %
00199 %  The format of the GetImageEncoder method is:
00200 %
00201 %      EncodeImageHandler *GetImageEncoder(const MagickInfo *magick_info)
00202 %
00203 %  A description of each parameter follows:
00204 %
00205 %    o magick_info:  The magick info.
00206 %
00207 */
00208 MagickExport EncodeImageHandler *GetImageEncoder(const MagickInfo *magick_info)
00209 {
00210   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00211   assert(magick_info != (MagickInfo *) NULL);
00212   assert(magick_info->signature == MagickSignature);
00213   return(magick_info->encoder);
00214 }
00215 
00216 /*
00217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00218 %                                                                             %
00219 %                                                                             %
00220 %                                                                             %
00221 +   G e t I m a g e M a g i c k                                               %
00222 %                                                                             %
00223 %                                                                             %
00224 %                                                                             %
00225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00226 %
00227 %  GetImageMagick() searches for an image format that matches the specified
00228 %  magick string.  If one is found, MagickTrue is returned otherwise
00229 %  MagickFalse.
00230 %
00231 %  The format of the GetImageMagick method is:
00232 %
00233 %      MagickBooleanType GetImageMagick(const unsigned char *magick,
00234 %        const size_t length,char *format)
00235 %
00236 %  A description of each parameter follows:
00237 %
00238 %    o magick: the image format we are searching for.
00239 %
00240 %    o length: the length of the binary string.
00241 %
00242 %    o format: the image format as determined by the magick bytes.
00243 %
00244 */
00245 MagickExport MagickBooleanType GetImageMagick(const unsigned char *magick,
00246   const size_t length,char *format)
00247 {
00248   ExceptionInfo
00249     *exception;
00250 
00251   MagickBooleanType
00252     status;
00253 
00254   register const MagickInfo
00255     *p;
00256 
00257   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00258   assert(magick != (const unsigned char *) NULL);
00259   exception=AcquireExceptionInfo();
00260   p=GetMagickInfo("*",exception);
00261   exception=DestroyExceptionInfo(exception);
00262   if (p == (const MagickInfo *) NULL)
00263     return(MagickFalse);
00264   status=MagickFalse;
00265   AcquireSemaphoreInfo(&magick_semaphore);
00266   ResetSplayTreeIterator(magick_list);
00267   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00268   while (p != (const MagickInfo *) NULL)
00269   {
00270     if ((p->magick != (IsImageFormatHandler *) NULL) &&
00271         (p->magick(magick,length) != 0))
00272       {
00273         status=MagickTrue;
00274         (void) CopyMagickString(format,p->name,MaxTextExtent);
00275         break;
00276       }
00277     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00278   }
00279   RelinquishSemaphoreInfo(magick_semaphore);
00280   return(status);
00281 }
00282 
00283 /*
00284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00285 %                                                                             %
00286 %                                                                             %
00287 %                                                                             %
00288 +   G e t M a g i c k A d j o i n                                             %
00289 %                                                                             %
00290 %                                                                             %
00291 %                                                                             %
00292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00293 %
00294 %  GetMagickAdjoin() returns MagickTrue if the magick adjoin is MagickTrue.
00295 %
00296 %  The format of the GetMagickAdjoin method is:
00297 %
00298 %      MagickBooleanType GetMagickAdjoin(const MagickInfo *magick_info)
00299 %
00300 %  A description of each parameter follows:
00301 %
00302 %    o magick_info:  The magick info.
00303 %
00304 */
00305 MagickExport MagickBooleanType GetMagickAdjoin(const MagickInfo *magick_info)
00306 {
00307   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00308   assert(magick_info != (MagickInfo *) NULL);
00309   assert(magick_info->signature == MagickSignature);
00310   return(magick_info->adjoin);
00311 }
00312 
00313 /*
00314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00315 %                                                                             %
00316 %                                                                             %
00317 %                                                                             %
00318 +   G e t M a g i c k B l o b S u p p o r t                                   %
00319 %                                                                             %
00320 %                                                                             %
00321 %                                                                             %
00322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00323 %
00324 %  GetMagickBlobSupport() returns MagickTrue if the magick supports blobs.
00325 %
00326 %  The format of the GetMagickBlobSupport method is:
00327 %
00328 %      MagickBooleanType GetMagickBlobSupport(const MagickInfo *magick_info)
00329 %
00330 %  A description of each parameter follows:
00331 %
00332 %    o magick_info:  The magick info.
00333 %
00334 */
00335 MagickExport MagickBooleanType GetMagickBlobSupport(
00336   const MagickInfo *magick_info)
00337 {
00338   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00339   assert(magick_info != (MagickInfo *) NULL);
00340   assert(magick_info->signature == MagickSignature);
00341   return(magick_info->blob_support);
00342 }
00343 
00344 /*
00345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00346 %                                                                             %
00347 %                                                                             %
00348 %                                                                             %
00349 +   G e t M a g i c k D e s c r i p t i o n                                   %
00350 %                                                                             %
00351 %                                                                             %
00352 %                                                                             %
00353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00354 %
00355 %  GetMagickDescription() returns the magick description.
00356 %
00357 %  The format of the GetMagickDescription method is:
00358 %
00359 %      const char *GetMagickDescription(const MagickInfo *magick_info)
00360 %
00361 %  A description of each parameter follows:
00362 %
00363 %    o magick_info:  The magick info.
00364 %
00365 */
00366 MagickExport const char *GetMagickDescription(const MagickInfo *magick_info)
00367 {
00368   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00369   assert(magick_info != (MagickInfo *) NULL);
00370   assert(magick_info->signature == MagickSignature);
00371   return(magick_info->description);
00372 }
00373 
00374 /*
00375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00376 %                                                                             %
00377 %                                                                             %
00378 %                                                                             %
00379 +   G e t M a g i c k E n d i a n S u p p o r t                               %
00380 %                                                                             %
00381 %                                                                             %
00382 %                                                                             %
00383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00384 %
00385 %  GetMagickEndianSupport() returns the MagickTrue if the coder respects
00386 %  endianess other than MSBEndian.
00387 %
00388 %  The format of the GetMagickEndianSupport method is:
00389 %
00390 %      MagickBooleanType GetMagickEndianSupport(const MagickInfo *magick_info)
00391 %
00392 %  A description of each parameter follows:
00393 %
00394 %    o magick_info:  The magick info.
00395 %
00396 */
00397 MagickExport MagickBooleanType GetMagickEndianSupport(
00398   const MagickInfo *magick_info)
00399 {
00400   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00401   assert(magick_info != (MagickInfo *) NULL);
00402   assert(magick_info->signature == MagickSignature);
00403   return(magick_info->endian_support);
00404 }
00405 
00406 /*
00407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00408 %                                                                             %
00409 %                                                                             %
00410 %                                                                             %
00411 +   G e t M a g i c k I n f o                                                 %
00412 %                                                                             %
00413 %                                                                             %
00414 %                                                                             %
00415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00416 %
00417 %  GetMagickInfo() returns a pointer MagickInfo structure that matches
00418 %  the specified name.  If name is NULL, the head of the image format list
00419 %  is returned.
00420 %
00421 %  The format of the GetMagickInfo method is:
00422 %
00423 %      const MagickInfo *GetMagickInfo(const char *name,Exception *exception)
00424 %
00425 %  A description of each parameter follows:
00426 %
00427 %    o name: the image format we are looking for.
00428 %
00429 %    o exception: return any errors or warnings in this structure.
00430 %
00431 */
00432 MagickExport const MagickInfo *GetMagickInfo(const char *name,
00433   ExceptionInfo *exception)
00434 {
00435   register const MagickInfo
00436     *p;
00437 
00438   assert(exception != (ExceptionInfo *) NULL);
00439   if ((magick_list == (SplayTreeInfo *) NULL) ||
00440       (instantiate_magick == MagickFalse))
00441     if (InitializeMagickList(exception) == MagickFalse)
00442       return((const MagickInfo *) NULL);
00443   if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
00444     {
00445 #if defined(MAGICKCORE_MODULES_SUPPORT)
00446       if (LocaleCompare(name,"*") == 0)
00447         (void) OpenModules(exception);
00448 #endif
00449       AcquireSemaphoreInfo(&magick_semaphore);
00450       ResetSplayTreeIterator(magick_list);
00451       p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00452       RelinquishSemaphoreInfo(magick_semaphore);
00453       return(p);
00454     }
00455   /*
00456     Find name in list.
00457   */
00458   AcquireSemaphoreInfo(&magick_semaphore);
00459   ResetSplayTreeIterator(magick_list);
00460   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00461   while (p != (const MagickInfo *) NULL)
00462   {
00463     if (LocaleCompare(p->name,name) == 0)
00464       break;
00465     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00466   }
00467 #if defined(MAGICKCORE_MODULES_SUPPORT)
00468   if (p == (const MagickInfo *) NULL)
00469     {
00470       if (*name != '\0')
00471         (void) OpenModule(name,exception);
00472       ResetSplayTreeIterator(magick_list);
00473       p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00474       while (p != (const MagickInfo *) NULL)
00475       {
00476         if (LocaleCompare(p->name,name) == 0)
00477           break;
00478         p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00479       }
00480     }
00481 #endif
00482   RelinquishSemaphoreInfo(magick_semaphore);
00483   return(p);
00484 }
00485 
00486 /*
00487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00488 %                                                                             %
00489 %                                                                             %
00490 %                                                                             %
00491 +   G e t M a g i c k I n f o L i s t                                         %
00492 %                                                                             %
00493 %                                                                             %
00494 %                                                                             %
00495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00496 %
00497 %  GetMagickInfoList() returns any image formats that match the specified
00498 %  pattern.
00499 %
00500 %  The format of the GetMagickInfoList function is:
00501 %
00502 %      const MagickInfo **GetMagickInfoList(const char *pattern,
00503 %        unsigned long *number_formats,ExceptionInfo *exception)
00504 %
00505 %  A description of each parameter follows:
00506 %
00507 %    o pattern: Specifies a pointer to a text string containing a pattern.
00508 %
00509 %    o number_formats:  This integer returns the number of formats in the list.
00510 %
00511 %    o exception: return any errors or warnings in this structure.
00512 %
00513 */
00514 
00515 #if defined(__cplusplus) || defined(c_plusplus)
00516 extern "C" {
00517 #endif
00518 
00519 static int MagickInfoCompare(const void *x,const void *y)
00520 {
00521   const MagickInfo
00522     **p,
00523     **q;
00524 
00525   p=(const MagickInfo **) x,
00526   q=(const MagickInfo **) y;
00527   return(LocaleCompare((*p)->name,(*q)->name));
00528 }
00529 
00530 #if defined(__cplusplus) || defined(c_plusplus)
00531 }
00532 #endif
00533 
00534 MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
00535   unsigned long *number_formats,ExceptionInfo *exception)
00536 {
00537   const MagickInfo
00538     **formats;
00539 
00540   register const MagickInfo
00541     *p;
00542 
00543   register long
00544     i;
00545 
00546   /*
00547     Allocate magick list.
00548   */
00549   assert(pattern != (char *) NULL);
00550   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00551   assert(number_formats != (unsigned long *) NULL);
00552   *number_formats=0;
00553   p=GetMagickInfo("*",exception);
00554   if (p == (const MagickInfo *) NULL)
00555     return((const MagickInfo **) NULL);
00556   formats=(const MagickInfo **) AcquireQuantumMemory((size_t)
00557     GetNumberOfNodesInSplayTree(magick_list)+1UL,sizeof(*formats));
00558   if (formats == (const MagickInfo **) NULL)
00559     return((const MagickInfo **) NULL);
00560   /*
00561     Generate magick list.
00562   */
00563   AcquireSemaphoreInfo(&magick_semaphore);
00564   ResetSplayTreeIterator(magick_list);
00565   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00566   for (i=0; p != (const MagickInfo *) NULL; )
00567   {
00568     if ((p->stealth == MagickFalse) &&
00569         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00570       formats[i++]=p;
00571     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00572   }
00573   RelinquishSemaphoreInfo(magick_semaphore);
00574   qsort((void *) formats,(size_t) i,sizeof(*formats),MagickInfoCompare);
00575   formats[i]=(MagickInfo *) NULL;
00576   *number_formats=(unsigned long) i;
00577   return(formats);
00578 }
00579 
00580 /*
00581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00582 %                                                                             %
00583 %                                                                             %
00584 %                                                                             %
00585 +   G e t M a g i c k L i s t                                                 %
00586 %                                                                             %
00587 %                                                                             %
00588 %                                                                             %
00589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00590 %
00591 %  GetMagickList() returns any image formats that match the specified pattern.
00592 %
00593 %  The format of the GetMagickList function is:
00594 %
00595 %      char **GetMagickList(const char *pattern,unsigned long *number_formats,
00596 %        ExceptionInfo *exception)
00597 %
00598 %  A description of each parameter follows:
00599 %
00600 %    o pattern: Specifies a pointer to a text string containing a pattern.
00601 %
00602 %    o number_formats:  This integer returns the number of formats in the list.
00603 %
00604 %    o exception: return any errors or warnings in this structure.
00605 %
00606 */
00607 
00608 #if defined(__cplusplus) || defined(c_plusplus)
00609 extern "C" {
00610 #endif
00611 
00612 static int MagickCompare(const void *x,const void *y)
00613 {
00614   register const char
00615     **p,
00616     **q;
00617 
00618   p=(const char **) x;
00619   q=(const char **) y;
00620   return(LocaleCompare(*p,*q));
00621 }
00622 
00623 #if defined(__cplusplus) || defined(c_plusplus)
00624 }
00625 #endif
00626 
00627 MagickExport char **GetMagickList(const char *pattern,
00628   unsigned long *number_formats,ExceptionInfo *exception)
00629 {
00630   char
00631     **formats;
00632 
00633   register const MagickInfo
00634     *p;
00635 
00636   register long
00637     i;
00638 
00639   /*
00640     Allocate magick list.
00641   */
00642   assert(pattern != (char *) NULL);
00643   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00644   assert(number_formats != (unsigned long *) NULL);
00645   *number_formats=0;
00646   p=GetMagickInfo("*",exception);
00647   if (p == (const MagickInfo *) NULL)
00648     return((char **) NULL);
00649   formats=(char **) AcquireQuantumMemory((size_t)
00650     GetNumberOfNodesInSplayTree(magick_list)+1UL,sizeof(*formats));
00651   if (formats == (char **) NULL)
00652     return((char **) NULL);
00653   AcquireSemaphoreInfo(&magick_semaphore);
00654   ResetSplayTreeIterator(magick_list);
00655   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00656   for (i=0; p != (const MagickInfo *) NULL; )
00657   {
00658     if ((p->stealth == MagickFalse) &&
00659         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00660       formats[i++]=ConstantString(p->name);
00661     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00662   }
00663   RelinquishSemaphoreInfo(magick_semaphore);
00664   qsort((void *) formats,(size_t) i,sizeof(*formats),MagickCompare);
00665   formats[i]=(char *) NULL;
00666   *number_formats=(unsigned long) i;
00667   return(formats);
00668 }
00669 
00670 /*
00671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00672 %                                                                             %
00673 %                                                                             %
00674 %                                                                             %
00675 +   G e t M a g i c k E n d i a n S u p p o r t                               %
00676 %                                                                             %
00677 %                                                                             %
00678 %                                                                             %
00679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00680 %
00681 %  GetMagickRawSupport() returns the MagickTrue if the coder is a raw format.
00682 %
00683 %  The format of the GetMagickRawSupport method is:
00684 %
00685 %      MagickBooleanType GetMagickRawSupport(const MagickInfo *magick_info)
00686 %
00687 %  A description of each parameter follows:
00688 %
00689 %    o magick_info:  The magick info.
00690 %
00691 */
00692 MagickExport MagickBooleanType GetMagickRawSupport(
00693   const MagickInfo *magick_info)
00694 {
00695   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00696   assert(magick_info != (MagickInfo *) NULL);
00697   assert(magick_info->signature == MagickSignature);
00698   return(magick_info->raw);
00699 }
00700 
00701 /*
00702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00703 %                                                                             %
00704 %                                                                             %
00705 %                                                                             %
00706 +   G e t M a g i c k S e e k a b l e S t r e a m                             %
00707 %                                                                             %
00708 %                                                                             %
00709 %                                                                             %
00710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00711 %
00712 %  GetMagickSeekableStream() returns MagickTrue if the magick supports a
00713 %  seekable stream.
00714 %
00715 %  The format of the GetMagickSeekableStream method is:
00716 %
00717 %      MagickBooleanType GetMagickSeekableStream(const MagickInfo *magick_info)
00718 %
00719 %  A description of each parameter follows:
00720 %
00721 %    o magick_info:  The magick info.
00722 %
00723 */
00724 MagickExport MagickBooleanType GetMagickSeekableStream(
00725   const MagickInfo *magick_info)
00726 {
00727   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00728   assert(magick_info != (MagickInfo *) NULL);
00729   assert(magick_info->signature == MagickSignature);
00730   return(magick_info->seekable_stream);
00731 }
00732 
00733 /*
00734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00735 %                                                                             %
00736 %                                                                             %
00737 %                                                                             %
00738 +   G e t M a g i c k T h r e a d S u p p o r t                               %
00739 %                                                                             %
00740 %                                                                             %
00741 %                                                                             %
00742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00743 %
00744 %  GetMagickThreadSupport() returns MagickTrue if the magick supports threads.
00745 %
00746 %  The format of the GetMagickThreadSupport method is:
00747 %
00748 %      MagickStatusType GetMagickThreadSupport(const MagickInfo *magick_info)
00749 %
00750 %  A description of each parameter follows:
00751 %
00752 %    o magick_info:  The magick info.
00753 %
00754 */
00755 MagickExport MagickStatusType GetMagickThreadSupport(
00756   const MagickInfo *magick_info)
00757 {
00758   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00759   assert(magick_info != (MagickInfo *) NULL);
00760   assert(magick_info->signature == MagickSignature);
00761   return(magick_info->thread_support);
00762 }
00763 
00764 /*
00765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00766 %                                                                             %
00767 %                                                                             %
00768 %                                                                             %
00769 +   I n i t i a l i z e M a g i c k L i s t                                   %
00770 %                                                                             %
00771 %                                                                             %
00772 %                                                                             %
00773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00774 %
00775 %  InitializeMagickList() initializes the magick list.
00776 %
00777 %  The format of the InitializeMagickList() method is:
00778 %
00779 %      InitializeMagickList(Exceptioninfo *exception)
00780 %
00781 %  A description of each parameter follows.
00782 %
00783 %    o exception: return any errors or warnings in this structure.
00784 %
00785 */
00786 
00787 static void *DestroyMagickNode(void *magick_info)
00788 {
00789   register MagickInfo
00790     *p;
00791 
00792   p=(MagickInfo *) magick_info;
00793   if (p->name != (char *) NULL)
00794     p->name=DestroyString(p->name);
00795   if (p->description != (char *) NULL)
00796     p->description=DestroyString(p->description);
00797   if (p->version != (char *) NULL)
00798     p->version=DestroyString(p->version);
00799   if (p->note != (char *) NULL)
00800     p->note=DestroyString(p->note);
00801   if (p->module != (char *) NULL)
00802     p->module=DestroyString(p->module);
00803   return(RelinquishMagickMemory(p));
00804 }
00805 
00806 static MagickBooleanType InitializeMagickList(ExceptionInfo *exception)
00807 {
00808   if ((magick_list == (SplayTreeInfo *) NULL) &&
00809       (instantiate_magick == MagickFalse))
00810     {
00811       AcquireSemaphoreInfo(&magick_semaphore);
00812       if ((magick_list == (SplayTreeInfo *) NULL) &&
00813           (instantiate_magick == MagickFalse))
00814         {
00815           MagickBooleanType
00816             status;
00817 
00818           MagickInfo
00819             *magick_info;
00820 
00821           magick_list=NewSplayTree(CompareSplayTreeString,
00822             (void *(*)(void *)) NULL,DestroyMagickNode);
00823           if (magick_list == (SplayTreeInfo *) NULL)
00824             ThrowFatalException(ResourceLimitFatalError,
00825               "MemoryAllocationFailed");
00826           magick_info=SetMagickInfo("tmp");
00827           magick_info->stealth=MagickTrue;
00828           status=AddValueToSplayTree(magick_list,magick_info->name,magick_info);
00829           if (status == MagickFalse)
00830             ThrowFatalException(ResourceLimitFatalError,
00831               "MemoryAllocationFailed");
00832           magick_info=SetMagickInfo("clipmask");
00833           magick_info->stealth=MagickTrue;
00834           status=AddValueToSplayTree(magick_list,magick_info->name,magick_info);
00835           if (status == MagickFalse)
00836             {
00837               char
00838                 *message;
00839 
00840               message=GetExceptionMessage(errno);
00841               ThrowFatalException(ResourceLimitFatalError,
00842                 "MemoryAllocationFailed");
00843               message=DestroyString(message);
00844             }
00845 #if defined(MAGICKCORE_MODULES_SUPPORT)
00846           (void) GetModuleInfo((char *) NULL,exception);
00847 #endif
00848 #if !defined(MAGICKCORE_BUILD_MODULES)
00849           RegisterStaticModules();
00850 #endif
00851           instantiate_magick=MagickTrue;
00852         }
00853       RelinquishSemaphoreInfo(magick_semaphore);
00854     }
00855   return(magick_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
00856 }
00857 
00858 /*
00859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00860 %                                                                             %
00861 %                                                                             %
00862 %                                                                             %
00863 +   I s M a g i c k C o n f l i c t                                           %
00864 %                                                                             %
00865 %                                                                             %
00866 %                                                                             %
00867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00868 %
00869 %  IsMagickConflict() returns MagickTrue if the image format is not a valid
00870 %  image format or conflicts with a logical drive (.e.g. X:).
00871 %
00872 %  The format of the IsMagickConflict method is:
00873 %
00874 %      MagickBooleanType IsMagickConflict(const char *magick)
00875 %
00876 %  A description of each parameter follows:
00877 %
00878 %    o magick: Specifies the image format.
00879 %
00880 */
00881 MagickExport MagickBooleanType IsMagickConflict(const char *magick)
00882 {
00883   const DelegateInfo
00884     *delegate_info;
00885 
00886   const MagickInfo
00887     *magick_info;
00888 
00889   ExceptionInfo
00890     *exception;
00891 
00892   assert(magick != (char *) NULL);
00893   exception=AcquireExceptionInfo();
00894   magick_info=GetMagickInfo(magick,exception);
00895   delegate_info=GetDelegateInfo(magick,(char *) NULL,exception);
00896   if (delegate_info == (const DelegateInfo *) NULL)
00897     delegate_info=GetDelegateInfo((char *) NULL,magick,exception);
00898   exception=DestroyExceptionInfo(exception);
00899   if ((magick_info == (const MagickInfo *) NULL) &&
00900       (delegate_info == (const DelegateInfo *) NULL))
00901     return(MagickTrue);
00902 #if defined(macintosh)
00903   return(MACIsMagickConflict(magick));
00904 #elif defined(vms)
00905   return(VMSIsMagickConflict(magick));
00906 #elif defined(__WINDOWS__)
00907   return(NTIsMagickConflict(magick));
00908 #else
00909   return(MagickFalse);
00910 #endif
00911 }
00912 
00913 /*
00914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00915 %                                                                             %
00916 %                                                                             %
00917 %                                                                             %
00918 +  L i s t M a g i c k I n f o                                                %
00919 %                                                                             %
00920 %                                                                             %
00921 %                                                                             %
00922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00923 %
00924 %  ListMagickInfo() lists the image formats to a file.
00925 %
00926 %  The format of the ListMagickInfo method is:
00927 %
00928 %      MagickBooleanType ListMagickInfo(FILE *file,ExceptionInfo *exception)
00929 %
00930 %  A description of each parameter follows.
00931 %
00932 %    o file: A file handle.
00933 %
00934 %    o exception: return any errors or warnings in this structure.
00935 %
00936 */
00937 MagickExport MagickBooleanType ListMagickInfo(FILE *file,
00938   ExceptionInfo *exception)
00939 {
00940   const MagickInfo
00941     **magick_info;
00942 
00943   long
00944     j;
00945 
00946   register long
00947     i;
00948 
00949   unsigned long
00950     number_formats;
00951 
00952   if (file == (FILE *) NULL)
00953     file=stdout;
00954   magick_info=GetMagickInfoList("*",&number_formats,exception);
00955   if (magick_info == (const MagickInfo **) NULL)
00956     return(MagickFalse);
00957   ClearMagickException(exception);
00958 #if !defined(MAGICKCORE_MODULES_SUPPORT)
00959   (void) fprintf(file,"   Format  Mode  Description\n");
00960 #else
00961   (void) fprintf(file,"   Format  Module    Mode  Description\n");
00962 #endif
00963   (void) fprintf(file,"--------------------------------------------------------"
00964     "-----------------------\n");
00965   for (i=0; i < (long) number_formats; i++)
00966   {
00967     if (magick_info[i]->stealth != MagickFalse)
00968       continue;
00969     (void) fprintf(file,"%9s%c ",magick_info[i]->name != (char *) NULL ?
00970       magick_info[i]->name : "",
00971       magick_info[i]->blob_support != MagickFalse ? '*' : ' ');
00972 #if defined(MAGICKCORE_MODULES_SUPPORT)
00973     {
00974       char
00975         module[MaxTextExtent];
00976 
00977       *module='\0';
00978       if (magick_info[i]->module != (char *) NULL)
00979         (void) CopyMagickString(module,magick_info[i]->module,MaxTextExtent);
00980       (void) ConcatenateMagickString(module,"          ",MaxTextExtent);
00981       module[9]='\0';
00982       (void) fprintf(file,"%9s ",module);
00983     }
00984 #endif
00985     (void) fprintf(file,"%c%c%c ",magick_info[i]->decoder ? 'r' : '-',
00986       magick_info[i]->encoder ? 'w' : '-',magick_info[i]->encoder != NULL &&
00987       magick_info[i]->adjoin != MagickFalse ? '+' : '-');
00988     if (magick_info[i]->description != (char *) NULL)
00989       (void) fprintf(file,"  %s",magick_info[i]->description);
00990     if (magick_info[i]->version != (char *) NULL)
00991       (void) fprintf(file," (%s)",magick_info[i]->version);
00992     (void) fprintf(file,"\n");
00993     if (magick_info[i]->note != (char *) NULL)
00994       {
00995         char
00996           **text;
00997 
00998         text=StringToList(magick_info[i]->note);
00999         if (text != (char **) NULL)
01000           {
01001             for (j=0; text[j] != (char *) NULL; j++)
01002             {
01003               (void) fprintf(file,"           %s\n",text[j]);
01004               text[j]=DestroyString(text[j]);
01005             }
01006             text=(char **) RelinquishMagickMemory(text);
01007           }
01008       }
01009   }
01010   (void) fprintf(file,"\n* native blob support\n");
01011   (void) fprintf(file,"r read support\n");
01012   (void) fprintf(file,"w write support\n");
01013   (void) fprintf(file,"+ support for multiple images\n");
01014   (void) fflush(file);
01015   magick_info=(const MagickInfo **) RelinquishMagickMemory((void *)
01016     magick_info);
01017   return(MagickTrue);
01018 }
01019 
01020 /*
01021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01022 %                                                                             %
01023 %                                                                             %
01024 %                                                                             %
01025 %  I s M a g i c k I n s t a n t i a t e d                                    %
01026 %                                                                             %
01027 %                                                                             %
01028 %                                                                             %
01029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01030 %
01031 %  IsMagickInstantiated() returns MagickTrue if the ImageMagick environment
01032 %  is currently instantiated:  MagickCoreGenesis() has been called but
01033 %  MagickDestroy() has not.
01034 %
01035 %  The format of the IsMagickInstantiated method is:
01036 %
01037 %      MagickBooleanType IsMagickInstantiated(void)
01038 %
01039 */
01040 MagickExport MagickBooleanType IsMagickInstantiated(void)
01041 {
01042   return(instantiate_magick);
01043 }
01044 
01045 /*
01046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01047 %                                                                             %
01048 %                                                                             %
01049 %                                                                             %
01050 %   M a g i c k C o r e G e n e s i s                                         %
01051 %                                                                             %
01052 %                                                                             %
01053 %                                                                             %
01054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01055 %
01056 %  MagickCoreGenesis() initializes the MagickCore environment.
01057 %
01058 %  The format of the InitializeMagick function is:
01059 %
01060 %      MagickCoreGenesis(const char *path,
01061 %        const MagickBooleanType establish_signal_handlers)
01062 %
01063 %  A description of each parameter follows:
01064 %
01065 %    o path: the execution path of the current ImageMagick client.
01066 %
01067 %    o establish_signal_handlers: set to MagickTrue to use MagickCore's own
01068 %      signal handlers for common signals.
01069 %
01070 */
01071 
01072 static SignalHandler *SetMagickSignalHandler(int signal_number,
01073   SignalHandler *handler)
01074 {
01075 #if defined(MAGICKCORE_HAVE_SIGACTION) && defined(MAGICKCORE_HAVE_SIGEMPTYSET)
01076   int
01077     status;
01078 
01079   sigset_t
01080     mask;
01081 
01082   struct sigaction
01083     action,
01084     previous_action;
01085 
01086   sigemptyset(&mask);
01087   sigaddset(&mask,signal_number);
01088   sigprocmask(SIG_BLOCK,&mask,NULL);
01089   action.sa_mask=mask;
01090   action.sa_handler=handler;
01091   action.sa_flags=0;
01092 #if defined(SA_INTERRUPT)
01093   action.sa_flags|=SA_INTERRUPT;
01094 #endif
01095   status=sigaction(signal_number,&action,&previous_action);
01096   if (status < 0)
01097     return(SIG_ERR);
01098   sigprocmask(SIG_UNBLOCK,&mask,NULL);
01099   return(previous_action.sa_handler);
01100 #else
01101   return(signal(signal_number,handler));
01102 #endif
01103 }
01104 
01105 static void MagickSignalHandler(int signal_number)
01106 {
01107 #if !defined(MAGICKCORE_HAVE_SIGACTION)
01108   (void) signal(signal_number,SIG_IGN);
01109 #endif
01110   AsynchronousDestroyMagickResources();
01111   instantiate_magick=MagickFalse;
01112   (void) SetMagickSignalHandler(signal_number,signal_handlers[signal_number]);
01113 #if defined(MAGICKCORE_HAVE_RAISE)
01114   if (signal_handlers[signal_number] != MagickSignalHandler)
01115     raise(signal_number);
01116 #endif
01117 #if !defined(MAGICKCORE_HAVE__EXIT)
01118   exit(signal_number);
01119 #else
01120 #if defined(SIGHUP)
01121   if (signal_number == SIGHUP)
01122     exit(signal_number);
01123 #endif
01124 #if defined(SIGINT) && !defined(__WINDOWS__)
01125   if (signal_number == SIGINT)
01126     exit(signal_number);
01127 #endif
01128 #if defined(SIGTERM)
01129   if (signal_number == SIGTERM)
01130     exit(signal_number);
01131 #endif
01132   _exit(signal_number);
01133 #endif
01134 }
01135 
01136 static SignalHandler *RegisterMagickSignalHandler(int signal_number)
01137 {
01138   SignalHandler
01139     *handler;
01140 
01141   handler=SetMagickSignalHandler(signal_number,MagickSignalHandler);
01142   if (handler == SIG_ERR)
01143     return(handler);
01144   if (handler != SIG_DFL)
01145     handler=SetMagickSignalHandler(signal_number,handler);
01146   else
01147     (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
01148       "Register handler for signal: %d",signal_number);
01149   return(handler);
01150 }
01151 
01152 MagickExport void MagickCoreGenesis(const char *path,
01153   const MagickBooleanType establish_signal_handlers)
01154 {
01155   char
01156     *events,
01157     execution_path[MaxTextExtent],
01158     filename[MaxTextExtent];
01159 
01160   ExceptionInfo
01161     *exception;
01162 
01163   time_t
01164     seconds;
01165 
01166   /*
01167     Initialize the Magick environment.
01168   */
01169   InitializeSemaphore();
01170   seconds=time((time_t *) NULL);
01171   events=GetEnvironmentValue("MAGICK_DEBUG");
01172   if (events != (char *) NULL)
01173     {
01174       (void) SetLogEventMask(events);
01175       events=DestroyString(events);
01176     }
01177 #if defined(__WINDOWS__)
01178 #if defined(_DEBUG) && !defined(__BORLANDC__) && !defined(__MINGW32__)
01179   if (IsEventLogging() != MagickFalse)
01180     {
01181       int
01182         debug;
01183 
01184       debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
01185       debug|=_CRTDBG_CHECK_ALWAYS_DF |_CRTDBG_DELAY_FREE_MEM_DF |
01186         _CRTDBG_LEAK_CHECK_DF;
01187       if (0)
01188         {
01189           debug=_CrtSetDbgFlag(debug);
01190           _ASSERTE(_CrtCheckMemory());
01191         }
01192     }
01193 #endif
01194 #endif
01195   /*
01196     Set client name and execution path.
01197   */
01198   (void) GetExecutionPath(execution_path,MaxTextExtent);
01199   if ((path != (const char *) NULL) && (*path != '\0'))
01200     (void) CopyMagickString(execution_path,path,MaxTextExtent);
01201   GetPathComponent(execution_path,TailPath,filename);
01202   (void) SetClientName(filename);
01203   GetPathComponent(execution_path,HeadPath,execution_path);
01204   (void) SetClientPath(execution_path);
01205   if (establish_signal_handlers != MagickFalse)
01206     {
01207       /*
01208         Set signal handlers.
01209       */
01210 #if defined(SIGABRT)
01211       if (signal_handlers[SIGABRT] == (SignalHandler *) NULL)
01212         signal_handlers[SIGABRT]=RegisterMagickSignalHandler(SIGABRT);
01213 #endif
01214 #if defined(SIGFPE)
01215       if (signal_handlers[SIGFPE] == (SignalHandler *) NULL)
01216         signal_handlers[SIGFPE]=RegisterMagickSignalHandler(SIGFPE);
01217 #endif
01218 #if defined(SIGHUP)
01219       if (signal_handlers[SIGHUP] == (SignalHandler *) NULL)
01220         signal_handlers[SIGHUP]=RegisterMagickSignalHandler(SIGHUP);
01221 #endif
01222 #if defined(SIGINT) && !defined(__WINDOWS__)
01223       if (signal_handlers[SIGINT] == (SignalHandler *) NULL)
01224         signal_handlers[SIGINT]=RegisterMagickSignalHandler(SIGINT);
01225 #endif
01226 #if defined(SIGQUIT)
01227       if (signal_handlers[SIGQUIT] == (SignalHandler *) NULL)
01228         signal_handlers[SIGQUIT]=RegisterMagickSignalHandler(SIGQUIT);
01229 #endif
01230 #if defined(SIGTERM)
01231       if (signal_handlers[SIGTERM] == (SignalHandler *) NULL)
01232         signal_handlers[SIGTERM]=RegisterMagickSignalHandler(SIGTERM);
01233 #endif
01234 #if defined(SIGXCPU)
01235       if (signal_handlers[SIGXCPU] == (SignalHandler *) NULL)
01236         signal_handlers[SIGXCPU]=RegisterMagickSignalHandler(SIGXCPU);
01237 #endif
01238 #if defined(SIGXFSZ)
01239       if (signal_handlers[SIGXFSZ] == (SignalHandler *) NULL)
01240         signal_handlers[SIGXFSZ]=RegisterMagickSignalHandler(SIGXFSZ);
01241 #endif
01242     }
01243   /*
01244     Initialize magick resources.
01245   */
01246   InitializeMagickResources();
01247   exception=AcquireExceptionInfo();
01248   (void) GetMagickInfo((char *) NULL,exception);
01249   exception=DestroyExceptionInfo(exception);
01250 }
01251 
01252 /*
01253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01254 %                                                                             %
01255 %                                                                             %
01256 %                                                                             %
01257 %   M a g i c k C o r e T e r m i n u s                                       %
01258 %                                                                             %
01259 %                                                                             %
01260 %                                                                             %
01261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01262 %
01263 %  MagickCoreTerminus() destroys the MagickCore environment.
01264 %
01265 %  The format of the DestroyMagick function is:
01266 %
01267 %      MagickCoreTerminus(void)
01268 %
01269 */
01270 MagickExport void MagickCoreTerminus(void)
01271 {
01272 #if defined(MAGICKCORE_X11_DELEGATE)
01273   DestroyXResources();
01274 #endif
01275   DestroyConstitute();
01276   DestroyMimeList();
01277   DestroyConfigureList();
01278   DestroyTypeList();
01279   DestroyColorList();
01280 #if defined(__WINDOWS__)
01281   NTGhostscriptUnLoadDLL();
01282 #endif
01283   DestroyMagicList();
01284   DestroyDelegateList();
01285   DestroyMagickList();
01286   DestroyCoderList();
01287   DestroyMagickResources();
01288   DestroyImageRegistry();
01289   DestroyPixelCacheResources();
01290   DestroyPolicyList();
01291   DestroyRandomReservoir();
01292   DestroyLocaleList();
01293   DestroyLogList();
01294   instantiate_magick=MagickFalse;
01295 }
01296 
01297 /*
01298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01299 %                                                                             %
01300 %                                                                             %
01301 %                                                                             %
01302 +   R e g i s t e r M a g i c k I n f o                                       %
01303 %                                                                             %
01304 %                                                                             %
01305 %                                                                             %
01306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01307 %
01308 %  RegisterMagickInfo() adds attributes for a particular image format to the
01309 %  list of supported formats.  The attributes include the image format name,
01310 %  a method to read and/or write the format, whether the format supports the
01311 %  saving of more than one frame to the same file or blob, whether the format
01312 %  supports native in-memory I/O, and a brief description of the format.
01313 %
01314 %  The format of the RegisterMagickInfo method is:
01315 %
01316 %      MagickInfo *RegisterMagickInfo(MagickInfo *magick_info)
01317 %
01318 %  A description of each parameter follows:
01319 %
01320 %    o magick_info: the magick info.
01321 %
01322 */
01323 MagickExport MagickInfo *RegisterMagickInfo(MagickInfo *magick_info)
01324 {
01325   MagickBooleanType
01326     status;
01327 
01328   /*
01329     Delete any existing name.
01330   */
01331   assert(magick_info != (MagickInfo *) NULL);
01332   assert(magick_info->signature == MagickSignature);
01333   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",magick_info->name);
01334   if (magick_list == (SplayTreeInfo *) NULL)
01335     return((MagickInfo *) NULL);
01336   status=AddValueToSplayTree(magick_list,magick_info->name,magick_info);
01337   if (status == MagickFalse)
01338     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
01339   return(magick_info);
01340 }
01341 
01342 /*
01343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01344 %                                                                             %
01345 %                                                                             %
01346 %                                                                             %
01347 +   S e t M a g i c k I n f o                                                 %
01348 %                                                                             %
01349 %                                                                             %
01350 %                                                                             %
01351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01352 %
01353 %  SetMagickInfo() allocates a MagickInfo structure and initializes the members
01354 %  to default values.
01355 %
01356 %  The format of the SetMagickInfo method is:
01357 %
01358 %      MagickInfo *SetMagickInfo(const char *name)
01359 %
01360 %  A description of each parameter follows:
01361 %
01362 %    o magick_info: Method SetMagickInfo returns the allocated and initialized
01363 %      MagickInfo structure.
01364 %
01365 %    o name: a character string that represents the image format associated
01366 %      with the MagickInfo structure.
01367 %
01368 */
01369 MagickExport MagickInfo *SetMagickInfo(const char *name)
01370 {
01371   MagickInfo
01372     *magick_info;
01373 
01374   assert(name != (const char *) NULL);
01375   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
01376   magick_info=(MagickInfo *) AcquireMagickMemory(sizeof(*magick_info));
01377   if (magick_info == (MagickInfo *) NULL)
01378     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
01379   (void) ResetMagickMemory(magick_info,0,sizeof(*magick_info));
01380   magick_info->name=ConstantString(name);
01381   magick_info->adjoin=MagickTrue;
01382   magick_info->blob_support=MagickTrue;
01383   magick_info->thread_support=(MagickStatusType) (DecoderThreadSupport |
01384     EncoderThreadSupport);
01385   magick_info->signature=MagickSignature;
01386   return(magick_info);
01387 }
01388 
01389 /*
01390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01391 %                                                                             %
01392 %                                                                             %
01393 %                                                                             %
01394 +   U n r e g i s t e r M a g i c k I n f o                                   %
01395 %                                                                             %
01396 %                                                                             %
01397 %                                                                             %
01398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01399 %
01400 %  UnregisterMagickInfo() removes a name from the magick info list.  It returns
01401 %  MagickFalse if the name does not exist in the list otherwise MagickTrue.
01402 %
01403 %  The format of the UnregisterMagickInfo method is:
01404 %
01405 %      MagickBooleanType UnregisterMagickInfo(const char *name)
01406 %
01407 %  A description of each parameter follows:
01408 %
01409 %    o name: a character string that represents the image format we are
01410 %      looking for.
01411 %
01412 */
01413 MagickExport MagickBooleanType UnregisterMagickInfo(const char *name)
01414 {
01415   register const MagickInfo
01416     *p;
01417 
01418   MagickBooleanType
01419     status;
01420 
01421   assert(name != (const char *) NULL);
01422   if (magick_list == (SplayTreeInfo *) NULL)
01423     return(MagickFalse);
01424   if (GetNumberOfNodesInSplayTree(magick_list) == 0)
01425     return(MagickFalse);
01426   AcquireSemaphoreInfo(&magick_semaphore);
01427   ResetSplayTreeIterator(magick_list);
01428   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
01429   while (p != (const MagickInfo *) NULL)
01430   {
01431     if (LocaleCompare(p->name,name) == 0)
01432       break;
01433     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
01434   }
01435   status=DeleteNodeByValueFromSplayTree(magick_list,p);
01436   RelinquishSemaphoreInfo(magick_semaphore);
01437   return(status);
01438 }

Generated on Thu Jul 2 12:03:20 2009 for MagickCore by  doxygen 1.5.8