]> granicus.if.org Git - imagemagick/blobdiff - magick/coder.c
(no commit message)
[imagemagick] / magick / coder.c
index 25c3b40106813474a621a47d9bc7712c9923c7d6..50b0f124514d562d04cd84d947ade13db18bb24f 100644 (file)
@@ -17,7 +17,7 @@
 %                                 May 2001                                    %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -64,7 +64,7 @@
 #define MagickCoderFilename  "coder.xml"
 \f
 /*
-  Static declarations.
+  Typedef declarations.
 */
 typedef struct _CoderMapInfo
 {
@@ -72,7 +72,10 @@ typedef struct _CoderMapInfo
     *magick,
     *name;
 } CoderMapInfo;
-
+\f
+/*
+  Static declarations.
+*/
 static const CoderMapInfo
   CoderMap[] =
   {
@@ -86,12 +89,14 @@ static const CoderMapInfo
     { "APP1JPEG", "META" },
     { "APP1", "META" },
     { "ARW", "DNG" },
+    { "AVI", "MPEG" },
     { "BIE", "JBIG" },
     { "BMP2", "BMP" },
     { "BMP3", "BMP" },
     { "B", "RAW" },
     { "BRF", "BRAILLE" },
     { "BGR", "RGB" },
+    { "BGRA", "RGB" },
     { "BRG", "RGB" },
     { "CMYKA", "CMYK" },
     { "C", "RAW" },
@@ -141,6 +146,7 @@ static const CoderMapInfo
     { "JBG", "JBIG" },
     { "JNG", "PNG" },
     { "JPC", "JP2" },
+    { "J2C", "JP2" },
     { "JPG", "JPEG" },
     { "JPX", "JP2" },
     { "K", "RAW" },
@@ -180,6 +186,7 @@ static const CoderMapInfo
     { "PNG32", "PNG" },
     { "PNG8", "PNG" },
     { "PPM", "PNM" },
+    { "PSB", "PSD" },
     { "PTIF", "TIFF" },
     { "RADIAL-GRADIENT", "GRADIENT" },
     { "RAF", "DNG" },
@@ -213,8 +220,7 @@ static const CoderMapInfo
     { "XTRNSTREAM", "XTRN" },
     { "XV", "VIFF" },
     { "Y", "RAW" },
-    { "YCbCrA", "YCbCr" },
-    { (const char *) NULL, (const char *) NULL }
+    { "YCbCrA", "YCbCr" }
  };
 
 static SemaphoreInfo
@@ -238,26 +244,52 @@ static MagickBooleanType
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   D e s t r o y C o d e r C o m p o n e n t                                 %
++   C o d e r C o m p o n e n t G e n e s i s                                 %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  DestroyCoderComponent() destroys the coder component.
+%  CoderComponentGenesis() instantiates the coder component.
 %
-%  The format of the DestroyCoderComponent method is:
+%  The format of the CoderComponentGenesis method is:
 %
-%      DestroyCoderComponent(void)
+%      MagickBooleanType CoderComponentGenesis(void)
 %
 */
-MagickExport void DestroyCoderComponent(void)
+MagickExport MagickBooleanType CoderComponentGenesis(void)
 {
   AcquireSemaphoreInfo(&coder_semaphore);
+  return(MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
++   C o d e r C o m p o n e n t T e r m i n u s                               %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  CoderComponentTerminus() destroys the coder component.
+%
+%  The format of the CoderComponentTerminus method is:
+%
+%      CoderComponentTerminus(void)
+%
+*/
+MagickExport void CoderComponentTerminus(void)
+{
+  if (coder_semaphore == (SemaphoreInfo *) NULL)
+    AcquireSemaphoreInfo(&coder_semaphore);
+  LockSemaphoreInfo(coder_semaphore);
   if (coder_list != (SplayTreeInfo *) NULL)
     coder_list=DestroySplayTree(coder_list);
   instantiate_coder=MagickFalse;
-  RelinquishSemaphoreInfo(coder_semaphore);
+  UnlockSemaphoreInfo(coder_semaphore);
   DestroySemaphoreInfo(&coder_semaphore);
 }
 \f
@@ -320,7 +352,7 @@ MagickExport const CoderInfo *GetCoderInfo(const char *name,
 %  The format of the GetCoderInfoList function is:
 %
 %      const CoderInfo **GetCoderInfoList(const char *pattern,
-%        unsigned long *number_coders,ExceptionInfo *exception)
+%        size_t *number_coders,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -346,7 +378,7 @@ static int CoderInfoCompare(const void *x,const void *y)
 }
 
 MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
-  unsigned long *number_coders,ExceptionInfo *exception)
+  size_t *number_coders,ExceptionInfo *exception)
 {
   const CoderInfo
     **coder_map;
@@ -354,7 +386,7 @@ MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
   register const CoderInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -362,7 +394,7 @@ MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_coders != (unsigned long *) NULL);
+  assert(number_coders != (size_t *) NULL);
   *number_coders=0;
   p=GetCoderInfo("*",exception);
   if (p == (const CoderInfo *) NULL)
@@ -374,7 +406,7 @@ MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
   /*
     Generate coder list.
   */
-  AcquireSemaphoreInfo(&coder_semaphore);
+  LockSemaphoreInfo(coder_semaphore);
   ResetSplayTreeIterator(coder_list);
   p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
   for (i=0; p != (const CoderInfo *) NULL; )
@@ -384,10 +416,10 @@ MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
       coder_map[i++]=p;
     p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
   }
-  RelinquishSemaphoreInfo(coder_semaphore);
+  UnlockSemaphoreInfo(coder_semaphore);
   qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare);
   coder_map[i]=(CoderInfo *) NULL;
-  *number_coders=(unsigned long) i;
+  *number_coders=(size_t) i;
   return(coder_map);
 }
 \f
@@ -406,7 +438,7 @@ MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
 %
 %  The format of the GetCoderList function is:
 %
-%      char **GetCoderList(const char *pattern,unsigned long *number_coders,
+%      char **GetCoderList(const char *pattern,size_t *number_coders,
 %        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
@@ -431,7 +463,7 @@ static int CoderCompare(const void *x,const void *y)
 }
 
 MagickExport char **GetCoderList(const char *pattern,
-  unsigned long *number_coders,ExceptionInfo *exception)
+  size_t *number_coders,ExceptionInfo *exception)
 {
   char
     **coder_map;
@@ -439,7 +471,7 @@ MagickExport char **GetCoderList(const char *pattern,
   register const CoderInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -447,7 +479,7 @@ MagickExport char **GetCoderList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_coders != (unsigned long *) NULL);
+  assert(number_coders != (size_t *) NULL);
   *number_coders=0;
   p=GetCoderInfo("*",exception);
   if (p == (const CoderInfo *) NULL)
@@ -459,7 +491,7 @@ MagickExport char **GetCoderList(const char *pattern,
   /*
     Generate coder list.
   */
-  AcquireSemaphoreInfo(&coder_semaphore);
+  LockSemaphoreInfo(coder_semaphore);
   ResetSplayTreeIterator(coder_list);
   p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
   for (i=0; p != (const CoderInfo *) NULL; )
@@ -469,10 +501,10 @@ MagickExport char **GetCoderList(const char *pattern,
       coder_map[i++]=ConstantString(p->name);
     p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
   }
-  RelinquishSemaphoreInfo(coder_semaphore);
+  UnlockSemaphoreInfo(coder_semaphore);
   qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare);
   coder_map[i]=(char *) NULL;
-  *number_coders=(unsigned long) i;
+  *number_coders=(size_t) i;
   return(coder_map);
 }
 \f
@@ -503,14 +535,16 @@ static MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
   if ((coder_list == (SplayTreeInfo *) NULL) &&
       (instantiate_coder == MagickFalse))
     {
-      AcquireSemaphoreInfo(&coder_semaphore);
+      if (coder_semaphore == (SemaphoreInfo *) NULL)
+        AcquireSemaphoreInfo(&coder_semaphore);
+      LockSemaphoreInfo(coder_semaphore);
       if ((coder_list == (SplayTreeInfo *) NULL) &&
           (instantiate_coder == MagickFalse))
         {
           (void) LoadCoderLists(MagickCoderFilename,exception);
           instantiate_coder=MagickTrue;
         }
-      RelinquishSemaphoreInfo(coder_semaphore);
+      UnlockSemaphoreInfo(coder_semaphore);
     }
   return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
 }
@@ -520,31 +554,6 @@ static MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   I n s t a n t i a t e C o d e r C o m p o n e n t                         %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  InstantiateCoderComponent() instantiates the coder component.
-%
-%  The format of the InstantiateCoderComponent method is:
-%
-%      MagickBooleanType InstantiateCoderComponent(void)
-%
-*/
-MagickExport MagickBooleanType InstantiateCoderComponent(void)
-{
-  AcquireSemaphoreInfo(&coder_semaphore);
-  RelinquishSemaphoreInfo(coder_semaphore);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %  L i s t C o d e r I n f o                                                  %
 %                                                                             %
 %                                                                             %
@@ -573,13 +582,13 @@ MagickExport MagickBooleanType ListCoderInfo(FILE *file,
   const CoderInfo
     **coder_info;
 
-  long
+  ssize_t
     j;
 
-  register long
+  register ssize_t
     i;
 
-  unsigned long
+  size_t
     number_coders;
 
   if (file == (const FILE *) NULL)
@@ -588,7 +597,7 @@ MagickExport MagickBooleanType ListCoderInfo(FILE *file,
   if (coder_info == (const CoderInfo **) NULL)
     return(MagickFalse);
   path=(const char *) NULL;
-  for (i=0; i < (long) number_coders; i++)
+  for (i=0; i < (ssize_t) number_coders; i++)
   {
     if (coder_info[i]->stealth != MagickFalse)
       continue;
@@ -603,7 +612,7 @@ MagickExport MagickBooleanType ListCoderInfo(FILE *file,
       }
     path=coder_info[i]->path;
     (void) fprintf(file,"%s",coder_info[i]->magick);
-    for (j=(long) strlen(coder_info[i]->magick); j <= 11; j++)
+    for (j=(ssize_t) strlen(coder_info[i]->magick); j <= 11; j++)
       (void) fprintf(file," ");
     if (coder_info[i]->name != (char *) NULL)
       (void) fprintf(file,"%s",coder_info[i]->name);
@@ -631,7 +640,7 @@ MagickExport MagickBooleanType ListCoderInfo(FILE *file,
 %  The format of the LoadCoderList coder is:
 %
 %      MagickBooleanType LoadCoderList(const char *xml,const char *filename,
-%        const unsigned long depth,ExceptionInfo *exception)
+%        const size_t depth,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -664,7 +673,7 @@ static void *DestroyCoderNode(void *coder_info)
 }
 
 static MagickBooleanType LoadCoderList(const char *xml,const char *filename,
-  const unsigned long depth,ExceptionInfo *exception)
+  const size_t depth,ExceptionInfo *exception)
 {
   char
     keyword[MaxTextExtent],
@@ -774,7 +783,7 @@ static MagickBooleanType LoadCoderList(const char *xml,const char *filename,
         /*
           Coder element.
         */
-        coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
+        coder_info=(CoderInfo *) AcquireAlignedMemory(1,sizeof(*coder_info));
         if (coder_info == (CoderInfo *) NULL)
           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
         (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
@@ -878,8 +887,8 @@ static MagickBooleanType LoadCoderLists(const char *filename,
   MagickStatusType
     status;
 
-  register const CoderMapInfo
-    *p;
+  register ssize_t
+    i;
 
   /*
     Load built-in coder map.
@@ -896,12 +905,16 @@ static MagickBooleanType LoadCoderLists(const char *filename,
           return(MagickFalse);
         }
     }
-  for (p=CoderMap; p->magick != (const char *) NULL; p++)
+  for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++)
   {
     CoderInfo
       *coder_info;
 
-    coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
+    register const CoderMapInfo
+      *p;
+
+    p=CoderMap+i;
+    coder_info=(CoderInfo *) AcquireAlignedMemory(1,sizeof(*coder_info));
     if (coder_info == (CoderInfo *) NULL)
       {
         (void) ThrowMagickException(exception,GetMagickModule(),