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-2008 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/semaphore.h"
00069 #include "magick/signature-private.h"
00070 #include "magick/splay-tree.h"
00071 #include "magick/string_.h"
00072 #include "magick/token.h"
00073 #include "magick/utility.h"
00074 #include "magick/xwindow-private.h"
00075 
00076 /*
00077   Define declarations.
00078 */
00079 #if !defined(MAGICKCORE_RETSIGTYPE)
00080 # define MAGICKCORE_RETSIGTYPE  void
00081 #endif
00082 #if !defined(SIG_DFL)
00083 # define SIG_DFL  ((SignalHandler *) 0)
00084 #endif
00085 #if !defined(SIG_ERR)
00086 # define SIG_ERR  ((SignalHandler *) -1)
00087 #endif
00088 #if !defined(SIGMAX)
00089 #define SIGMAX  64
00090 #endif
00091 
00092 /*
00093   Typedef declarations.
00094 */
00095 typedef MAGICKCORE_RETSIGTYPE
00096   SignalHandler(int);
00097 
00098 /*
00099   Global declarations.
00100 */
00101 static SemaphoreInfo
00102   *magick_semaphore = (SemaphoreInfo *) NULL;
00103 
00104 static SignalHandler
00105   *signal_handlers[SIGMAX] = { (SignalHandler *) NULL };
00106 
00107 static SplayTreeInfo
00108   *magick_list = (SplayTreeInfo *) NULL;
00109 
00110 static volatile MagickBooleanType
00111   instantiate_magick = MagickFalse;  /* double-checked locking pattern */
00112 
00113 /*
00114   Forward declarations.
00115 */
00116 static MagickBooleanType
00117   InitializeMagickList(ExceptionInfo *);
00118 
00119 /*
00120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00121 %                                                                             %
00122 %                                                                             %
00123 %                                                                             %
00124 +   D e s t r o y M a g i c k L i s t                                         %
00125 %                                                                             %
00126 %                                                                             %
00127 %                                                                             %
00128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00129 %
00130 %  DestroyMagickList() deallocates memory associated with the MagickInfo list.
00131 %
00132 %  The format of the DestroyMagickList method is:
00133 %
00134 %      void DestroyMagickList(void)
00135 %
00136 */
00137 MagickExport void DestroyMagickList(void)
00138 {
00139   AcquireSemaphoreInfo(&magick_semaphore);
00140   if (magick_list != (SplayTreeInfo *) NULL)
00141     magick_list=DestroySplayTree(magick_list);
00142   instantiate_magick=MagickFalse;
00143   RelinquishSemaphoreInfo(magick_semaphore);
00144   DestroySemaphoreInfo(&magick_semaphore);
00145 #if !defined(MAGICKCORE_BUILD_MODULES)
00146   UnregisterStaticModules();
00147 #endif
00148 #if defined(MAGICKCORE_MODULES_SUPPORT)
00149   DestroyModuleList();
00150 #endif
00151 }
00152 
00153 /*
00154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00155 %                                                                             %
00156 %                                                                             %
00157 %                                                                             %
00158 +   G e t I m a g e D e c o d e r                                             %
00159 %                                                                             %
00160 %                                                                             %
00161 %                                                                             %
00162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00163 %
00164 %  GetImageDecoder() returns the image decoder.
00165 %
00166 %  The format of the GetImageDecoder method is:
00167 %
00168 %      DecodeImageHandler *GetImageDecoder(const MagickInfo *magick_info)
00169 %
00170 %  A description of each parameter follows:
00171 %
00172 %    o magick_info:  The magick info.
00173 %
00174 */
00175 MagickExport DecodeImageHandler *GetImageDecoder(const MagickInfo *magick_info)
00176 {
00177   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00178   assert(magick_info != (MagickInfo *) NULL);
00179   assert(magick_info->signature == MagickSignature);
00180   return(magick_info->decoder);
00181 }
00182 
00183 /*
00184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00185 %                                                                             %
00186 %                                                                             %
00187 %                                                                             %
00188 +   G e t I m a g e E n c o d e r                                             %
00189 %                                                                             %
00190 %                                                                             %
00191 %                                                                             %
00192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00193 %
00194 %  GetImageEncoder() returns the image encoder.
00195 %
00196 %  The format of the GetImageEncoder method is:
00197 %
00198 %      EncodeImageHandler *GetImageEncoder(const MagickInfo *magick_info)
00199 %
00200 %  A description of each parameter follows:
00201 %
00202 %    o magick_info:  The magick info.
00203 %
00204 */
00205 MagickExport EncodeImageHandler *GetImageEncoder(const MagickInfo *magick_info)
00206 {
00207   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00208   assert(magick_info != (MagickInfo *) NULL);
00209   assert(magick_info->signature == MagickSignature);
00210   return(magick_info->encoder);
00211 }
00212 
00213 /*
00214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00215 %                                                                             %
00216 %                                                                             %
00217 %                                                                             %
00218 +   G e t I m a g e M a g i c k                                               %
00219 %                                                                             %
00220 %                                                                             %
00221 %                                                                             %
00222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00223 %
00224 %  GetImageMagick() searches for an image format that matches the specified
00225 %  magick string.  If one is found the name is returned otherwise NULL.
00226 %
00227 %  The format of the GetImageMagick method is:
00228 %
00229 %      const char *GetImageMagick(const unsigned char *magick,
00230 %        const size_t length)
00231 %
00232 %  A description of each parameter follows:
00233 %
00234 %    o magick: the image format we are searching for.
00235 %
00236 %    o length: the length of the binary string.
00237 %
00238 */
00239 MagickExport const char *GetImageMagick(const unsigned char *magick,
00240   const size_t length)
00241 {
00242   ExceptionInfo
00243     *exception;
00244 
00245   register const MagickInfo
00246     *p;
00247 
00248   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00249   assert(magick != (const unsigned char *) NULL);
00250   exception=AcquireExceptionInfo();
00251   p=GetMagickInfo("*",exception);
00252   exception=DestroyExceptionInfo(exception);
00253   if (p == (const MagickInfo *) NULL)
00254     return((const char *) NULL);
00255   AcquireSemaphoreInfo(&magick_semaphore);
00256   ResetSplayTreeIterator(magick_list);
00257   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00258   while (p != (const MagickInfo *) NULL)
00259   {
00260     if ((p->magick != (IsImageFormatHandler *) NULL) &&
00261         (p->magick(magick,length) != 0))
00262       break;
00263     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00264   }
00265   RelinquishSemaphoreInfo(magick_semaphore);
00266   if (p != (MagickInfo *) NULL)
00267     return(p->name);
00268   return((const char *) NULL);
00269 }
00270 
00271 /*
00272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00273 %                                                                             %
00274 %                                                                             %
00275 %                                                                             %
00276 +   G e t M a g i c k A d j o i n                                             %
00277 %                                                                             %
00278 %                                                                             %
00279 %                                                                             %
00280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00281 %
00282 %  GetMagickAdjoin() returns MagickTrue if the magick adjoin is MagickTrue.
00283 %
00284 %  The format of the GetMagickAdjoin method is:
00285 %
00286 %      MagickBooleanType GetMagickAdjoin(const MagickInfo *magick_info)
00287 %
00288 %  A description of each parameter follows:
00289 %
00290 %    o magick_info:  The magick info.
00291 %
00292 */
00293 MagickExport MagickBooleanType GetMagickAdjoin(const MagickInfo *magick_info)
00294 {
00295   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00296   assert(magick_info != (MagickInfo *) NULL);
00297   assert(magick_info->signature == MagickSignature);
00298   return(magick_info->adjoin);
00299 }
00300 
00301 /*
00302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00303 %                                                                             %
00304 %                                                                             %
00305 %                                                                             %
00306 +   G e t M a g i c k B l o b S u p p o r t                                   %
00307 %                                                                             %
00308 %                                                                             %
00309 %                                                                             %
00310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00311 %
00312 %  GetMagickBlobSupport() returns MagickTrue if the magick supports blobs.
00313 %
00314 %  The format of the GetMagickBlobSupport method is:
00315 %
00316 %      MagickBooleanType GetMagickBlobSupport(const MagickInfo *magick_info)
00317 %
00318 %  A description of each parameter follows:
00319 %
00320 %    o magick_info:  The magick info.
00321 %
00322 */
00323 MagickExport MagickBooleanType GetMagickBlobSupport(
00324   const MagickInfo *magick_info)
00325 {
00326   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00327   assert(magick_info != (MagickInfo *) NULL);
00328   assert(magick_info->signature == MagickSignature);
00329   return(magick_info->blob_support);
00330 }
00331 
00332 /*
00333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00334 %                                                                             %
00335 %                                                                             %
00336 %                                                                             %
00337 +   G e t M a g i c k D e s c r i p t i o n                                   %
00338 %                                                                             %
00339 %                                                                             %
00340 %                                                                             %
00341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00342 %
00343 %  GetMagickDescription() returns the magick description.
00344 %
00345 %  The format of the GetMagickDescription method is:
00346 %
00347 %      const char *GetMagickDescription(const MagickInfo *magick_info)
00348 %
00349 %  A description of each parameter follows:
00350 %
00351 %    o magick_info:  The magick info.
00352 %
00353 */
00354 MagickExport const char *GetMagickDescription(const MagickInfo *magick_info)
00355 {
00356   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00357   assert(magick_info != (MagickInfo *) NULL);
00358   assert(magick_info->signature == MagickSignature);
00359   return(magick_info->description);
00360 }
00361 
00362 /*
00363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00364 %                                                                             %
00365 %                                                                             %
00366 %                                                                             %
00367 +   G e t M a g i c k E n d i a n S u p p o r t                               %
00368 %                                                                             %
00369 %                                                                             %
00370 %                                                                             %
00371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00372 %
00373 %  GetMagickEndianSupport() returns the MagickTrue if the coder respects
00374 %  endianess other than MSBEndian.
00375 %
00376 %  The format of the GetMagickEndianSupport method is:
00377 %
00378 %      MagickBooleanType GetMagickEndianSupport(const MagickInfo *magick_info)
00379 %
00380 %  A description of each parameter follows:
00381 %
00382 %    o magick_info:  The magick info.
00383 %
00384 */
00385 MagickExport MagickBooleanType GetMagickEndianSupport(
00386   const MagickInfo *magick_info)
00387 {
00388   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00389   assert(magick_info != (MagickInfo *) NULL);
00390   assert(magick_info->signature == MagickSignature);
00391   return(magick_info->endian_support);
00392 }
00393 
00394 /*
00395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00396 %                                                                             %
00397 %                                                                             %
00398 %                                                                             %
00399 +   G e t M a g i c k I n f o                                                 %
00400 %                                                                             %
00401 %                                                                             %
00402 %                                                                             %
00403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00404 %
00405 %  GetMagickInfo() returns a pointer MagickInfo structure that matches
00406 %  the specified name.  If name is NULL, the head of the image format list
00407 %  is returned.
00408 %
00409 %  The format of the GetMagickInfo method is:
00410 %
00411 %      const MagickInfo *GetMagickInfo(const char *name,Exception *exception)
00412 %
00413 %  A description of each parameter follows:
00414 %
00415 %    o name: the image format we are looking for.
00416 %
00417 %    o exception: return any errors or warnings in this structure.
00418 %
00419 */
00420 MagickExport const MagickInfo *GetMagickInfo(const char *name,
00421   ExceptionInfo *exception)
00422 {
00423   register const MagickInfo
00424     *p;
00425 
00426   assert(exception != (ExceptionInfo *) NULL);
00427   if ((magick_list == (SplayTreeInfo *) NULL) ||
00428       (instantiate_magick == MagickFalse))
00429     if (InitializeMagickList(exception) == MagickFalse)
00430       return((const MagickInfo *) NULL);
00431   if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
00432     {
00433 #if defined(MAGICKCORE_MODULES_SUPPORT)
00434       if (LocaleCompare(name,"*") == 0)
00435         (void) OpenModules(exception);
00436 #endif
00437       AcquireSemaphoreInfo(&magick_semaphore);
00438       ResetSplayTreeIterator(magick_list);
00439       p=GetNextValueInSplayTree(magick_list);
00440       RelinquishSemaphoreInfo(magick_semaphore);
00441       return(p);
00442     }
00443   /*
00444     Find name in list.
00445   */
00446   AcquireSemaphoreInfo(&magick_semaphore);
00447   ResetSplayTreeIterator(magick_list);
00448   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00449   while (p != (const MagickInfo *) NULL)
00450   {
00451     if (LocaleCompare(p->name,name) == 0)
00452       break;
00453     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00454   }
00455 #if defined(MAGICKCORE_MODULES_SUPPORT)
00456   if (p == (const MagickInfo *) NULL)
00457     {
00458       if (*name != '\0')
00459         (void) OpenModule(name,exception);
00460       ResetSplayTreeIterator(magick_list);
00461       p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00462       while (p != (const MagickInfo *) NULL)
00463       {
00464         if (LocaleCompare(p->name,name) == 0)
00465           break;
00466         p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00467       }
00468     }
00469 #endif
00470   RelinquishSemaphoreInfo(magick_semaphore);
00471   return(p);
00472 }
00473 
00474 /*
00475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00476 %                                                                             %
00477 %                                                                             %
00478 %                                                                             %
00479 +   G e t M a g i c k I n f o L i s t                                         %
00480 %                                                                             %
00481 %                                                                             %
00482 %                                                                             %
00483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00484 %
00485 %  GetMagickInfoList() returns any image formats that match the specified
00486 %  pattern.
00487 %
00488 %  The format of the GetMagickInfoList function is:
00489 %
00490 %      const MagickInfo **GetMagickInfoList(const char *pattern,
00491 %        unsigned long *number_formats,ExceptionInfo *exception)
00492 %
00493 %  A description of each parameter follows:
00494 %
00495 %    o pattern: Specifies a pointer to a text string containing a pattern.
00496 %
00497 %    o number_formats:  This integer returns the number of formats in the list.
00498 %
00499 %    o exception: return any errors or warnings in this structure.
00500 %
00501 */
00502 
00503 #if defined(__cplusplus) || defined(c_plusplus)
00504 extern "C" {
00505 #endif
00506 
00507 static int MagickInfoCompare(const void *x,const void *y)
00508 {
00509   const MagickInfo
00510     **p,
00511     **q;
00512 
00513   p=(const MagickInfo **) x,
00514   q=(const MagickInfo **) y;
00515   return(LocaleCompare((*p)->name,(*q)->name));
00516 }
00517 
00518 #if defined(__cplusplus) || defined(c_plusplus)
00519 }
00520 #endif
00521 
00522 MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
00523   unsigned long *number_formats,ExceptionInfo *exception)
00524 {
00525   const MagickInfo
00526     **formats;
00527 
00528   register const MagickInfo
00529     *p;
00530 
00531   register long
00532     i;
00533 
00534   /*
00535     Allocate magick list.
00536   */
00537   assert(pattern != (char *) NULL);
00538   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00539   assert(number_formats != (unsigned long *) NULL);
00540   *number_formats=0;
00541   p=GetMagickInfo("*",exception);
00542   if (p == (const MagickInfo *) NULL)
00543     return((const MagickInfo **) NULL);
00544   formats=(const MagickInfo **) AcquireQuantumMemory((size_t)
00545     GetNumberOfNodesInSplayTree(magick_list)+1UL,sizeof(*formats));
00546   if (formats == (const MagickInfo **) NULL)
00547     return((const MagickInfo **) NULL);
00548   /*
00549     Generate magick list.
00550   */
00551   AcquireSemaphoreInfo(&magick_semaphore);
00552   ResetSplayTreeIterator(magick_list);
00553   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00554   for (i=0; p != (const MagickInfo *) NULL; )
00555   {
00556     if ((p->stealth == MagickFalse) &&
00557         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00558       formats[i++]=p;
00559     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00560   }
00561   RelinquishSemaphoreInfo(magick_semaphore);
00562   qsort((void *) formats,(size_t) i,sizeof(*formats),MagickInfoCompare);
00563   formats[i]=(MagickInfo *) NULL;
00564   *number_formats=(unsigned long) i;
00565   return(formats);
00566 }
00567 
00568 /*
00569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00570 %                                                                             %
00571 %                                                                             %
00572 %                                                                             %
00573 +   G e t M a g i c k L i s t                                                 %
00574 %                                                                             %
00575 %                                                                             %
00576 %                                                                             %
00577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00578 %
00579 %  GetMagickList() returns any image formats that match the specified pattern.
00580 %
00581 %  The format of the GetMagickList function is:
00582 %
00583 %      char **GetMagickList(const char *pattern,unsigned long *number_formats,
00584 %        ExceptionInfo *exception)
00585 %
00586 %  A description of each parameter follows:
00587 %
00588 %    o pattern: Specifies a pointer to a text string containing a pattern.
00589 %
00590 %    o number_formats:  This integer returns the number of formats in the list.
00591 %
00592 %    o exception: return any errors or warnings in this structure.
00593 %
00594 */
00595 
00596 #if defined(__cplusplus) || defined(c_plusplus)
00597 extern "C" {
00598 #endif
00599 
00600 static int MagickCompare(const void *x,const void *y)
00601 {
00602   register const char
00603     **p,
00604     **q;
00605 
00606   p=(const char **) x;
00607   q=(const char **) y;
00608   return(LocaleCompare(*p,*q));
00609 }
00610 
00611 #if defined(__cplusplus) || defined(c_plusplus)
00612 }
00613 #endif
00614 
00615 MagickExport char **GetMagickList(const char *pattern,
00616   unsigned long *number_formats,ExceptionInfo *exception)
00617 {
00618   char
00619     **formats;
00620 
00621   register const MagickInfo
00622     *p;
00623 
00624   register long
00625     i;
00626 
00627   /*
00628     Allocate magick list.
00629   */
00630   assert(pattern != (char *) NULL);
00631   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00632   assert(number_formats != (unsigned long *) NULL);
00633   *number_formats=0;
00634   p=GetMagickInfo("*",exception);
00635   if (p == (const MagickInfo *) NULL)
00636     return((char **) NULL);
00637   formats=(char **) AcquireQuantumMemory((size_t)
00638     GetNumberOfNodesInSplayTree(magick_list)+1UL,sizeof(*formats));
00639   if (formats == (char **) NULL)
00640     return((char **) NULL);
00641   AcquireSemaphoreInfo(&magick_semaphore);
00642   ResetSplayTreeIterator(magick_list);
00643   p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00644   for (i=0; p != (const MagickInfo *) NULL; )
00645   {
00646     if ((p->stealth == MagickFalse) &&
00647         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00648       formats[i++]=ConstantString(p->name);
00649     p=(const MagickInfo *) GetNextValueInSplayTree(magick_list);
00650   }
00651   RelinquishSemaphoreInfo(magick_semaphore);
00652   qsort((void *) formats,(size_t) i,sizeof(*formats),MagickCompare);
00653   formats[i]=(char *) NULL;
00654   *number_formats=(unsigned long) i;
00655   return(formats);
00656 }
00657 
00658 /*
00659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00660 %                                                                             %
00661 %                                                                             %
00662 %                                                                             %
00663 +   G e t M a g i c k E n d i a n S u p p o r t                               %
00664 %                                                                             %
00665 %                                                                             %
00666 %                                                                             %
00667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00668 %
00669 %  GetMagickRawSupport() returns the MagickTrue if the coder is a raw format.
00670 %
00671 %  The format of the GetMagickRawSupport method is:
00672 %
00673 %      MagickBooleanType GetMagickRawSupport(const MagickInfo *magick_info)
00674 %
00675 %  A description of each parameter follows:
00676 %
00677 %    o magick_info:  The magick info.
00678 %
00679 */
00680 MagickExport MagickBooleanType GetMagickRawSupport(
00681   const MagickInfo *magick_info)
00682 {
00683   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00684   assert(magick_info != (MagickInfo *) NULL);
00685   assert(magick_info->signature == MagickSignature);
00686   return(magick_info->raw);
00687 }
00688 
00689 /*
00690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00691 %                                                                             %
00692 %                                                                             %
00693 %                                                                             %
00694 +   G e t M a g i c k S e e k a b l e S t r e a m                             %
00695 %                                                                             %
00696 %                                                                             %
00697 %                                                                             %
00698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00699 %
00700 %  GetMagickSeekableStream() returns MagickTrue if the magick supports a
00701 %  seekable stream.
00702 %
00703 %  The format of the GetMagickSeekableStream method is:
00704 %
00705 %      MagickBooleanType GetMagickSeekableStream(const MagickInfo *magick_info)
00706 %
00707 %  A description of each parameter follows:
00708 %
00709 %    o magick_info:  The magick info.
00710 %
00711 */
00712 MagickExport MagickBooleanType GetMagickSeekableStream(
00713   const MagickInfo *magick_info)
00714 {
00715   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00716   assert(magick_info != (MagickInfo *) NULL);
00717   assert(magick_info->signature == MagickSignature);
00718   return(magick_info->seekable_stream);
00719 }
00720 
00721 /*
00722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00723 %                                                                             %
00724 %                                                                             %
00725 %                                                                             %
00726 +   G e t M a g i c k T h r e a d S u p p o r t                               %
00727 %                                                                             %
00728 %                                                                             %
00729 %                                                                             %
00730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00731 %
00732 %  GetMagickThreadSupport() returns MagickTrue if the magick supports threads.
00733 %
00734 %  The format of the GetMagickThreadSupport method is:
00735 %
00736 %      MagickStatusType GetMagickThreadSupport(const MagickInfo *magick_info)
00737 %
00738 %  A description of each parameter follows:
00739 %
00740 %    o magick_info:  The magick info.
00741 %
00742 */
00743 MagickExport MagickStatusType GetMagickThreadSupport(
00744   const MagickInfo *magick_info)
00745 {
00746   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00747   assert(magick_info != (MagickInfo *) NULL);
00748   assert(magick_info->signature == MagickSignature);
00749   return(magick_info->thread_support);
00750 }
00751 
00752 /*
00753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00754 %                                                                             %
00755 %                                                                             %
00756 %                                                                             %
00757 +   I n i t i a l i z e M a g i c k L i s t                                   %
00758 %                                                                             %
00759 %                                                                             %
00760 %                                                                             %
00761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00762 %
00763 %  InitializeMagickList() initializes the magick list.
00764 %
00765 %  The format of the InitializeMagickList() method is:
00766 %
00767 %      InitializeMagickList(Exceptioninfo *exception)
00768 %
00769 %  A description of each parameter follows.
00770 %
00771 %    o exception: return any errors or warnings in this structure.
00772 %
00773 */
00774 
00775 static void *DestroyMagickNode(void *magick_info)
00776 {
00777   register MagickInfo
00778     *p;
00779 
00780   p=(MagickInfo *) magick_info;
00781   if (p->name != (char *) NULL)
00782     p->name=DestroyString(p->name);
00783   if (p->description != (char *) NULL)
00784     p->description=DestroyString(p->description);
00785   if (p->version != (char *) NULL)
00786     p->version=DestroyString(p->version);
00787   if (p->note != (char *) NULL)
00788     p->note=DestroyString(p->note);
00789   if (p->module != (char *) NULL)
00790     p->module=DestroyString(p->module);
00791   return(RelinquishMagickMemory(p));
00792 }
00793 
00794 static MagickBooleanType InitializeMagickList(ExceptionInfo *exception)
00795 {
00796   if ((magick_list == (SplayTreeInfo *) NULL) &&
00797       (instantiate_magick == MagickFalse))
00798     {
00799       AcquireSemaphoreInfo(&magick_semaphore);
00800       if ((magick_list == (SplayTreeInfo *) NULL) &&
00801           (instantiate_magick == MagickFalse))
00802         {
00803           MagickBooleanType
00804             status;
00805 
00806           MagickInfo
00807             *magick_info;
00808 
00809           magick_list=NewSplayTree(CompareSplayTreeString,
00810             (void *(*)(void *)) NULL,DestroyMagickNode);
00811           if (magick_list == (SplayTreeInfo *) NULL)
00812             ThrowFatalException(ResourceLimitFatalError,
00813               "MemoryAllocationFailed");
00814           magick_info=SetMagickInfo("tmp");
00815           magick_info->stealth=MagickTrue;
00816           status=AddValueToSplayTree(magick_list,magick_info->name,magick_info);
00817           if (status == MagickFalse)
00818             ThrowFatalException(ResourceLimitFatalError,
00819               "MemoryAllocationFailed");
00820           magick_info=SetMagickInfo("clipmask");
00821           magick_info->stealth=MagickTrue;
00822           status=AddValueToSplayTree(magick_list,magick_info->name,magick_info);
00823           if (status == MagickFalse)
00824             {
00825               char
00826                 *message;
00827 
00828               message=GetExceptionMessage(errno);
00829               ThrowFatalException(ResourceLimitFatalError,
00830                 "MemoryAllocationFailed");
00831               message=DestroyString(message);
00832             }
00833 #if defined(MAGICKCORE_MODULES_SUPPORT)
00834           (void) GetModuleInfo((char *) NULL,exception);
00835 #endif
00836 #if !defined(MAGICKCORE_BUILD_MODULES)
00837           RegisterStaticModules();
00838 #endif
00839           instantiate_magick=MagickTrue;
00840         }
00841       RelinquishSemaphoreInfo(magick_semaphore);
00842     }
00843   return(magick_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
00844 }
00845 
00846 /*
00847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00848 %                                                                             %
00849 %                                                                             %
00850 %                                                                             %
00851 +   I s M a g i c k C o n f l i c t                                           %
00852 %                                                                             %
00853 %                                                                             %
00854 %                                                                             %
00855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00856 %
00857 %  IsMagickConflict() returns MagickTrue if the image format is not a valid
00858 %  image format or conflicts with a logical drive (.e.g. X:).
00859 %
00860 %  The format of the IsMagickConflict method is:
00861 %
00862 %      MagickBooleanType IsMagickConflict(const char *magick)
00863 %
00864 %  A description of each parameter follows:
00865 %
00866 %    o magick: Specifies the image format.
00867 %
00868 */
00869 MagickExport MagickBooleanType IsMagickConflict(const char *magick)
00870 {
00871   const DelegateInfo
00872     *delegate_info;
00873 
00874   const MagickInfo
00875     *magick_info;
00876 
00877   ExceptionInfo
00878     *exception;
00879 
00880   assert(magick != (char *) NULL);
00881   exception=AcquireExceptionInfo();
00882   magick_info=GetMagickInfo(magick,exception);
00883   delegate_info=GetDelegateInfo(magick,(char *) NULL,exception);
00884   if (delegate_info == (const DelegateInfo *) NULL)
00885     delegate_info=GetDelegateInfo((char *) NULL,magick,exception);
00886   exception=DestroyExceptionInfo(exception);
00887   if ((magick_info == (const MagickInfo *) NULL) &&
00888       (delegate_info == (const DelegateInfo *) NULL))
00889     return(MagickTrue);
00890 #if defined(macintosh)
00891   return(MACIsMagickConflict(magick));
00892 #endif
00893 #if defined(vms)
00894   return(VMSIsMagickConflict(magick));
00895 #endif
00896 #if defined(__WINDOWS__)
00897   return(NTIsMagickConflict(magick));
00898 #endif
00899   return(MagickFalse);
00900 }
00901 
00902 /*
00903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00904 %                                                                             %
00905 %                                                                             %
00906 %                                                                             %
00907 +  L i s t M a g i c k I n f o                                                %
00908 %                                                                             %
00909 %                                                                             %
00910 %                                                                             %
00911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00912 %
00913 %  ListMagickInfo() lists the image formats to a file.
00914 %
00915 %  The format of the ListMagickInfo method is:
00916 %
00917 %      MagickBooleanType ListMagickInfo(FILE *file,ExceptionInfo *exception)
00918 %
00919 %  A description of each parameter follows.
00920 %
00921 %    o file: A file handle.
00922 %
00923 %    o exception: return any errors or warnings in this structure.
00924 %
00925 */
00926 MagickExport MagickBooleanType ListMagickInfo(FILE *file,
00927   ExceptionInfo *exception)
00928 {
00929   const MagickInfo
00930     **magick_info;
00931 
00932   long
00933     j;
00934 
00935   register long
00936     i;
00937 
00938   unsigned long
00939     number_formats;
00940 
00941   if (file == (FILE *) NULL)
00942     file=stdout;
00943   magick_info=GetMagickInfoList("*",&number_formats,exception);
00944   if (magick_info == (const MagickInfo **) NULL)
00945     return(MagickFalse);
00946   ClearMagickException(exception);
00947 #if !defined(MAGICKCORE_MODULES_SUPPORT)
00948   (void) fprintf(file,"   Format  Mode  Description\n");
00949 #else
00950   (void) fprintf(file,"   Format  Module    Mode  Description\n");
00951 #endif
00952   (void) fprintf(file,"--------------------------------------------------------"
00953     "-----------------------\n");
00954   for (i=0; i < (long) number_formats; i++)
00955   {
00956     if (magick_info[i]->stealth != MagickFalse)
00957       continue;
00958     (void) fprintf(file,"%9s%c ",magick_info[i]->name != (char *) NULL ?
00959       magick_info[i]->name : "",
00960       magick_info[i]->blob_support != MagickFalse ? '*' : ' ');
00961 #if defined(MAGICKCORE_MODULES_SUPPORT)
00962     {
00963       char
00964         module[MaxTextExtent];
00965 
00966       *module='\0';
00967       if (magick_info[i]->module != (char *) NULL)
00968         (void) CopyMagickString(module,magick_info[i]->module,MaxTextExtent);
00969       (void) ConcatenateMagickString(module,"          ",MaxTextExtent);
00970       module[9]='\0';
00971       (void) fprintf(file,"%9s ",module);
00972     }
00973 #endif
00974     (void) fprintf(file,"%c%c%c ",magick_info[i]->decoder ? 'r' : '-',
00975       magick_info[i]->encoder ? 'w' : '-',magick_info[i]->encoder != NULL &&
00976       magick_info[i]->adjoin != MagickFalse ? '+' : '-');
00977     if (magick_info[i]->description != (char *) NULL)
00978       (void) fprintf(file,"  %s",magick_info[i]->description);
00979     if (magick_info[i]->version != (char *) NULL)
00980       (void) fprintf(file," (%s)",magick_info[i]->version);
00981     (void) fprintf(file,"\n");
00982     if (magick_info[i]->note != (char *) NULL)
00983       {
00984         char
00985           **text;
00986 
00987         text=StringToList(magick_info[i]->note);
00988         if (text != (char **) NULL)
00989           {
00990             for (j=0; text[j] != (char *) NULL; j++)
00991             {
00992               (void) fprintf(file,"           %s\n",text[j]);
00993               text[j]=DestroyString(text[j]);
00994             }
00995             text=(char **) RelinquishMagickMemory(text);
00996           }
00997       }
00998   }
00999   (void) fprintf(file,"\n* native blob support\n\n");
01000   (void) fflush(file);
01001   magick_info=(const MagickInfo **)
01002     RelinquishMagickMemory((void *) magick_info);
01003   return(MagickTrue);
01004 }
01005 
01006 /*
01007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01008 %                                                                             %
01009 %                                                                             %
01010 %                                                                             %
01011 %  I s M a g i c k I n s t a n t i a t e d                                    %
01012 %                                                                             %
01013 %                                                                             %
01014 %                                                                             %
01015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01016 %
01017 %  IsMagickInstantiated() returns MagickTrue if the ImageMagick environment
01018 %  is currently instantiated:  MagickCoreGenesis() has been called but
01019 %  MagickDestroy() has not.
01020 %
01021 %  The format of the IsMagickInstantiated method is:
01022 %
01023 %      MagickBooleanType IsMagickInstantiated(void)
01024 %
01025 */
01026 MagickExport MagickBooleanType