coder.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                   CCCC   OOO   DDDD    EEEEE  RRRR                          %
00007 %                  C      O   O  D   D   E      R   R                         %
00008 %                  C      O   O  D   D   EEE    RRRR                          %
00009 %                  C      O   O  D   D   E      R R                           %
00010 %                   CCCC   OOO   DDDD    EEEEE  R  R                          %
00011 %                                                                             %
00012 %                                                                             %
00013 %                     MagickCore Image Coder Methods                          %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                 May 2001                                    %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 */
00038 
00039 /*
00040   Include declarations.
00041 */
00042 #include "magick/studio.h"
00043 #include "magick/blob.h"
00044 #include "magick/client.h"
00045 #include "magick/coder.h"
00046 #include "magick/configure.h"
00047 #include "magick/draw.h"
00048 #include "magick/exception.h"
00049 #include "magick/exception-private.h"
00050 #include "magick/hashmap.h"
00051 #include "magick/log.h"
00052 #include "magick/memory_.h"
00053 #include "magick/option.h"
00054 #include "magick/semaphore.h"
00055 #include "magick/string_.h"
00056 #include "magick/splay-tree.h"
00057 #include "magick/token.h"
00058 #include "magick/utility.h"
00059 #include "magick/xml-tree.h"
00060 
00061 /*
00062   Define declarations.
00063 */
00064 #define MagickCoderFilename  "coder.xml"
00065 
00066 /*
00067   Typedef declarations.
00068 */
00069 typedef struct _CoderMapInfo
00070 {
00071   const char
00072     *magick,
00073     *name;
00074 } CoderMapInfo;
00075 
00076 /*
00077   Static declarations.
00078 */
00079 static const CoderMapInfo
00080   CoderMap[] =
00081   {
00082     { "3FR", "DNG" },
00083     { "8BIM", "META" },
00084     { "8BIMTEXT", "META" },
00085     { "8BIMWTEXT", "META" },
00086     { "AFM", "TTF" },
00087     { "A", "RAW" },
00088     { "AI", "PDF" },
00089     { "APP1JPEG", "META" },
00090     { "APP1", "META" },
00091     { "ARW", "DNG" },
00092     { "BIE", "JBIG" },
00093     { "BMP2", "BMP" },
00094     { "BMP3", "BMP" },
00095     { "B", "RAW" },
00096     { "BRF", "BRAILLE" },
00097     { "BGR", "RGB" },
00098     { "BRG", "RGB" },
00099     { "CMYKA", "CMYK" },
00100     { "C", "RAW" },
00101     { "CAL", "CALS" },
00102     { "CR2", "DNG" },
00103     { "CRW", "DNG" },
00104     { "CUR", "ICON" },
00105     { "DCR", "DNG" },
00106     { "DCX", "PCX" },
00107     { "DFONT", "TTF" },
00108     { "EPDF", "PDF" },
00109     { "EPI", "PS" },
00110     { "EPS2", "PS2" },
00111     { "EPS3", "PS3" },
00112     { "EPSF", "PS" },
00113     { "EPSI", "PS" },
00114     { "EPS", "PS" },
00115     { "EPT2", "EPT" },
00116     { "EPT3", "EPT" },
00117     { "ERF", "DNG" },
00118     { "EXIF", "META" },
00119     { "FILE", "URL" },
00120     { "FRACTAL", "PLASMA" },
00121     { "FTP", "URL" },
00122     { "FTS", "FITS" },
00123     { "G3", "FAX" },
00124     { "GIF87", "GIF" },
00125     { "G", "RAW" },
00126     { "GBR", "RGB" },
00127     { "GRB", "RGB" },
00128     { "GRANITE", "MAGICK" },
00129     { "GROUP4", "TIFF" },
00130     { "K25", "DNG" },
00131     { "KDC", "DNG" },
00132     { "H", "MAGICK" },
00133     { "HTM", "HTML" },
00134     { "HTTP", "URL" },
00135     { "ICB", "TGA" },
00136     { "ICC", "META" },
00137     { "ICM", "META" },
00138     { "ICO", "ICON" },
00139     { "IMPLICIT", "***" },
00140     { "IPTC", "META" },
00141     { "IPTCTEXT", "META" },
00142     { "IPTCWTEXT", "META" },
00143     { "ISOBRL", "BRAILLE" },
00144     { "JBG", "JBIG" },
00145     { "JNG", "PNG" },
00146     { "JPC", "JP2" },
00147     { "JPG", "JPEG" },
00148     { "JPX", "JP2" },
00149     { "K", "RAW" },
00150     { "LOGO", "MAGICK" },
00151     { "M2V", "MPEG" },
00152     { "M4V", "MPEG" },
00153     { "M", "RAW" },
00154     { "MNG", "PNG" },
00155     { "MOV", "PNG" },
00156     { "MP4", "MPEG" },
00157     { "MPG", "MPEG" },
00158     { "MPRI", "MPR" },
00159     { "MRW", "DNG" },
00160     { "MSVG", "SVG" },
00161     { "NEF", "DNG" },
00162     { "NETSCAPE", "MAGICK" },
00163     { "O", "RAW" },
00164     { "ORF", "DNG" },
00165     { "OTF", "TTF" },
00166     { "P7", "PNM" },
00167     { "PAL", "UYVY" },
00168     { "PAM", "PNM" },
00169     { "PBM", "PNM" },
00170     { "PCDS", "PCD" },
00171     { "PDFA", "PDF" },
00172     { "PEF", "DNG" },
00173     { "PEF", "DNG" },
00174     { "PFA", "TTF" },
00175     { "PFB", "TTF" },
00176     { "PFM", "PNM" },
00177     { "PGM", "PNM" },
00178     { "PGX", "JP2" },
00179     { "PICON", "XPM" },
00180     { "PJPEG", "JPEG" },
00181     { "PM", "XPM" },
00182     { "PNG24", "PNG" },
00183     { "PNG32", "PNG" },
00184     { "PNG8", "PNG" },
00185     { "PPM", "PNM" },
00186     { "PTIF", "TIFF" },
00187     { "RADIAL-GRADIENT", "GRADIENT" },
00188     { "RAF", "DNG" },
00189     { "RAS", "SUN" },
00190     { "RBG", "RGB" },
00191     { "RGBA", "RGB" },
00192     { "RGBO", "RGB" },
00193     { "R", "RAW" },
00194     { "ROSE", "MAGICK" },
00195     { "SHTML", "HTML" },
00196     { "SR2", "DNG" },
00197     { "SRF", "DNG" },
00198     { "SVGZ", "SVG" },
00199     { "TEXT", "TXT" },
00200     { "TIFF64", "TIFF" },
00201     { "TIF", "TIFF" },
00202     { "TTC", "TTF" },
00203     { "UBRL", "BRAILLE" },
00204     { "VDA", "TGA" },
00205     { "VST", "TGA" },
00206     { "WMV", "MPEG" },
00207     { "WMFWIN32", "EMF" },
00208     { "WMZ", "WMF" },
00209     { "X3f", "DNG" },
00210     { "XMP", "META" },
00211     { "XTRNARRAY", "XTRN" },
00212     { "XTRNBLOB", "XTRN" },
00213     { "XTRNBSTR", "XTRN" },
00214     { "XTRNFILE", "XTRN" },
00215     { "XTRNIMAGE", "XTRN" },
00216     { "XTRNSTREAM", "XTRN" },
00217     { "XV", "VIFF" },
00218     { "Y", "RAW" },
00219     { "YCbCrA", "YCbCr" }
00220  };
00221 
00222 static SemaphoreInfo
00223   *coder_semaphore = (SemaphoreInfo *) NULL;
00224 
00225 static SplayTreeInfo
00226   *coder_list = (SplayTreeInfo *) NULL;
00227 
00228 static volatile MagickBooleanType
00229   instantiate_coder = MagickFalse;
00230 
00231 /*
00232   Forward declarations.
00233 */
00234 static MagickBooleanType
00235   InitializeCoderList(ExceptionInfo *),
00236   LoadCoderLists(const char *,ExceptionInfo *);
00237 
00238 /*
00239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00240 %                                                                             %
00241 %                                                                             %
00242 %                                                                             %
00243 +   C o d e r C o m p o n e n t G e n e s i s                                 %
00244 %                                                                             %
00245 %                                                                             %
00246 %                                                                             %
00247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00248 %
00249 %  CoderComponentGenesis() instantiates the coder component.
00250 %
00251 %  The format of the CoderComponentGenesis method is:
00252 %
00253 %      MagickBooleanType CoderComponentGenesis(void)
00254 %
00255 */
00256 MagickExport MagickBooleanType CoderComponentGenesis(void)
00257 {
00258   AcquireSemaphoreInfo(&coder_semaphore);
00259   return(MagickTrue);
00260 }
00261 
00262 /*
00263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00264 %                                                                             %
00265 %                                                                             %
00266 %                                                                             %
00267 +   C o d e r C o m p o n e n t T e r m i n u s                               %
00268 %                                                                             %
00269 %                                                                             %
00270 %                                                                             %
00271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00272 %
00273 %  CoderComponentTerminus() destroys the coder component.
00274 %
00275 %  The format of the CoderComponentTerminus method is:
00276 %
00277 %      CoderComponentTerminus(void)
00278 %
00279 */
00280 MagickExport void CoderComponentTerminus(void)
00281 {
00282   if (coder_semaphore == (SemaphoreInfo *) NULL)
00283     AcquireSemaphoreInfo(&coder_semaphore);
00284   (void) LockSemaphoreInfo(coder_semaphore);
00285   if (coder_list != (SplayTreeInfo *) NULL)
00286     coder_list=DestroySplayTree(coder_list);
00287   instantiate_coder=MagickFalse;
00288   (void) UnlockSemaphoreInfo(coder_semaphore);
00289   DestroySemaphoreInfo(&coder_semaphore);
00290 }
00291 
00292 /*
00293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00294 %                                                                             %
00295 %                                                                             %
00296 %                                                                             %
00297 +   G e t C o d e r I n f o                                                   %
00298 %                                                                             %
00299 %                                                                             %
00300 %                                                                             %
00301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00302 %
00303 %  GetCoderInfo searches the coder list for the specified name and if found
00304 %  returns attributes for that coder.
00305 %
00306 %  The format of the GetCoderInfo method is:
00307 %
00308 %      const CoderInfo *GetCoderInfo(const char *name,ExceptionInfo *exception)
00309 %
00310 %  A description of each parameter follows:
00311 %
00312 %    o name: the coder name.
00313 %
00314 %    o exception: return any errors or warnings in this structure.
00315 %
00316 */
00317 MagickExport const CoderInfo *GetCoderInfo(const char *name,
00318   ExceptionInfo *exception)
00319 {
00320   assert(exception != (ExceptionInfo *) NULL);
00321   if ((coder_list == (SplayTreeInfo *) NULL) ||
00322       (instantiate_coder == MagickFalse))
00323     if (InitializeCoderList(exception) == MagickFalse)
00324       return((const CoderInfo *) NULL);
00325   if ((coder_list == (SplayTreeInfo *) NULL) ||
00326       (GetNumberOfNodesInSplayTree(coder_list) == 0))
00327     return((const CoderInfo *) NULL);
00328   if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
00329     {
00330       ResetSplayTreeIterator(coder_list);
00331       return((const CoderInfo *) GetNextValueInSplayTree(coder_list));
00332     }
00333   return((const CoderInfo *) GetValueFromSplayTree(coder_list,name));
00334 }
00335 
00336 /*
00337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00338 %                                                                             %
00339 %                                                                             %
00340 %                                                                             %
00341 %   G e t C o d e r I n f o L i s t                                           %
00342 %                                                                             %
00343 %                                                                             %
00344 %                                                                             %
00345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00346 %
00347 %  GetCoderInfoList() returns any coder_map that match the specified pattern.
00348 %  The format of the GetCoderInfoList function is:
00349 %
00350 %      const CoderInfo **GetCoderInfoList(const char *pattern,
00351 %        unsigned long *number_coders,ExceptionInfo *exception)
00352 %
00353 %  A description of each parameter follows:
00354 %
00355 %    o pattern: Specifies a pointer to a text string containing a pattern.
00356 %
00357 %    o number_coders:  This integer returns the number of coders in the list.
00358 %
00359 %    o exception: return any errors or warnings in this structure.
00360 %
00361 */
00362 
00363 static int CoderInfoCompare(const void *x,const void *y)
00364 {
00365   const CoderInfo
00366     **p,
00367     **q;
00368 
00369   p=(const CoderInfo **) x,
00370   q=(const CoderInfo **) y;
00371   if (LocaleCompare((*p)->path,(*q)->path) == 0)
00372     return(LocaleCompare((*p)->name,(*q)->name));
00373   return(LocaleCompare((*p)->path,(*q)->path));
00374 }
00375 
00376 MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
00377   unsigned long *number_coders,ExceptionInfo *exception)
00378 {
00379   const CoderInfo
00380     **coder_map;
00381 
00382   register const CoderInfo
00383     *p;
00384 
00385   register long
00386     i;
00387 
00388   /*
00389     Allocate coder list.
00390   */
00391   assert(pattern != (char *) NULL);
00392   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00393   assert(number_coders != (unsigned long *) NULL);
00394   *number_coders=0;
00395   p=GetCoderInfo("*",exception);
00396   if (p == (const CoderInfo *) NULL)
00397     return((const CoderInfo **) NULL);
00398   coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t)
00399     GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map));
00400   if (coder_map == (const CoderInfo **) NULL)
00401     return((const CoderInfo **) NULL);
00402   /*
00403     Generate coder list.
00404   */
00405   (void) LockSemaphoreInfo(coder_semaphore);
00406   ResetSplayTreeIterator(coder_list);
00407   p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
00408   for (i=0; p != (const CoderInfo *) NULL; )
00409   {
00410     if ((p->stealth == MagickFalse) &&
00411         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00412       coder_map[i++]=p;
00413     p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
00414   }
00415   (void) UnlockSemaphoreInfo(coder_semaphore);
00416   qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare);
00417   coder_map[i]=(CoderInfo *) NULL;
00418   *number_coders=(unsigned long) i;
00419   return(coder_map);
00420 }
00421 
00422 /*
00423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00424 %                                                                             %
00425 %                                                                             %
00426 %                                                                             %
00427 %   G e t C o d e r L i s t                                                   %
00428 %                                                                             %
00429 %                                                                             %
00430 %                                                                             %
00431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00432 %
00433 %  GetCoderList() returns any coder_map that match the specified pattern.
00434 %
00435 %  The format of the GetCoderList function is:
00436 %
00437 %      char **GetCoderList(const char *pattern,unsigned long *number_coders,
00438 %        ExceptionInfo *exception)
00439 %
00440 %  A description of each parameter follows:
00441 %
00442 %    o pattern: Specifies a pointer to a text string containing a pattern.
00443 %
00444 %    o number_coders:  This integer returns the number of coders in the list.
00445 %
00446 %    o exception: return any errors or warnings in this structure.
00447 %
00448 */
00449 
00450 static int CoderCompare(const void *x,const void *y)
00451 {
00452   register const char
00453     **p,
00454     **q;
00455 
00456   p=(const char **) x;
00457   q=(const char **) y;
00458   return(LocaleCompare(*p,*q));
00459 }
00460 
00461 MagickExport char **GetCoderList(const char *pattern,
00462   unsigned long *number_coders,ExceptionInfo *exception)
00463 {
00464   char
00465     **coder_map;
00466 
00467   register const CoderInfo
00468     *p;
00469 
00470   register long
00471     i;
00472 
00473   /*
00474     Allocate coder list.
00475   */
00476   assert(pattern != (char *) NULL);
00477   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00478   assert(number_coders != (unsigned long *) NULL);
00479   *number_coders=0;
00480   p=GetCoderInfo("*",exception);
00481   if (p == (const CoderInfo *) NULL)
00482     return((char **) NULL);
00483   coder_map=(char **) AcquireQuantumMemory((size_t)
00484     GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map));
00485   if (coder_map == (char **) NULL)
00486     return((char **) NULL);
00487   /*
00488     Generate coder list.
00489   */
00490   (void) LockSemaphoreInfo(coder_semaphore);
00491   ResetSplayTreeIterator(coder_list);
00492   p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
00493   for (i=0; p != (const CoderInfo *) NULL; )
00494   {
00495     if ((p->stealth == MagickFalse) &&
00496         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00497       coder_map[i++]=ConstantString(p->name);
00498     p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
00499   }
00500   (void) UnlockSemaphoreInfo(coder_semaphore);
00501   qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare);
00502   coder_map[i]=(char *) NULL;
00503   *number_coders=(unsigned long) i;
00504   return(coder_map);
00505 }
00506 
00507 /*
00508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00509 %                                                                             %
00510 %                                                                             %
00511 %                                                                             %
00512 +   I n i t i a l i z e C o d e r L i s t                                     %
00513 %                                                                             %
00514 %                                                                             %
00515 %                                                                             %
00516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00517 %
00518 %  InitializeCoderList() initializes the coder list.
00519 %
00520 %  The format of the InitializeCoderList method is:
00521 %
00522 %      MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
00523 %
00524 %  A description of each parameter follows.
00525 %
00526 %    o exception: return any errors or warnings in this structure.
00527 %
00528 */
00529 static MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
00530 {
00531   if ((coder_list == (SplayTreeInfo *) NULL) &&
00532       (instantiate_coder == MagickFalse))
00533     {
00534       if (coder_semaphore == (SemaphoreInfo *) NULL)
00535         AcquireSemaphoreInfo(&coder_semaphore);
00536       (void) LockSemaphoreInfo(coder_semaphore);
00537       if ((coder_list == (SplayTreeInfo *) NULL) &&
00538           (instantiate_coder == MagickFalse))
00539         {
00540           (void) LoadCoderLists(MagickCoderFilename,exception);
00541           instantiate_coder=MagickTrue;
00542         }
00543       (void) UnlockSemaphoreInfo(coder_semaphore);
00544     }
00545   return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
00546 }
00547 
00548 /*
00549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00550 %                                                                             %
00551 %                                                                             %
00552 %                                                                             %
00553 %  L i s t C o d e r I n f o                                                  %
00554 %                                                                             %
00555 %                                                                             %
00556 %                                                                             %
00557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00558 %
00559 %  ListCoderInfo() lists the coder info to a file.
00560 %
00561 %  The format of the ListCoderInfo coder is:
00562 %
00563 %      MagickBooleanType ListCoderInfo(FILE *file,ExceptionInfo *exception)
00564 %
00565 %  A description of each parameter follows.
00566 %
00567 %    o file:  An pointer to a FILE.
00568 %
00569 %    o exception: return any errors or warnings in this structure.
00570 %
00571 */
00572 MagickExport MagickBooleanType ListCoderInfo(FILE *file,
00573   ExceptionInfo *exception)
00574 {
00575   const char
00576     *path;
00577 
00578   const CoderInfo
00579     **coder_info;
00580 
00581   long
00582     j;
00583 
00584   register long
00585     i;
00586 
00587   unsigned long
00588     number_coders;
00589 
00590   if (file == (const FILE *) NULL)
00591     file=stdout;
00592   coder_info=GetCoderInfoList("*",&number_coders,exception);
00593   if (coder_info == (const CoderInfo **) NULL)
00594     return(MagickFalse);
00595   path=(const char *) NULL;
00596   for (i=0; i < (long) number_coders; i++)
00597   {
00598     if (coder_info[i]->stealth != MagickFalse)
00599       continue;
00600     if ((path == (const char *) NULL) ||
00601         (LocaleCompare(path,coder_info[i]->path) != 0))
00602       {
00603         if (coder_info[i]->path != (char *) NULL)
00604           (void) fprintf(file,"\nPath: %s\n\n",coder_info[i]->path);
00605         (void) fprintf(file,"Magick      Coder\n");
00606         (void) fprintf(file,"-------------------------------------------------"
00607           "------------------------------\n");
00608       }
00609     path=coder_info[i]->path;
00610     (void) fprintf(file,"%s",coder_info[i]->magick);
00611     for (j=(long) strlen(coder_info[i]->magick); j <= 11; j++)
00612       (void) fprintf(file," ");
00613     if (coder_info[i]->name != (char *) NULL)
00614       (void) fprintf(file,"%s",coder_info[i]->name);
00615     (void) fprintf(file,"\n");
00616   }
00617   coder_info=(const CoderInfo **) RelinquishMagickMemory((void *) coder_info);
00618   (void) fflush(file);
00619   return(MagickTrue);
00620 }
00621 
00622 /*
00623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00624 %                                                                             %
00625 %                                                                             %
00626 %                                                                             %
00627 +   L o a d C o d e r L i s t                                                 %
00628 %                                                                             %
00629 %                                                                             %
00630 %                                                                             %
00631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00632 %
00633 %  LoadCoderList() loads the coder configuration file which provides a
00634 %  mapping between coder attributes and a coder name.
00635 %
00636 %  The format of the LoadCoderList coder is:
00637 %
00638 %      MagickBooleanType LoadCoderList(const char *xml,const char *filename,
00639 %        const unsigned long depth,ExceptionInfo *exception)
00640 %
00641 %  A description of each parameter follows:
00642 %
00643 %    o xml:  The coder list in XML format.
00644 %
00645 %    o filename:  The coder list filename.
00646 %
00647 %    o depth: depth of <include /> statements.
00648 %
00649 %    o exception: return any errors or warnings in this structure.
00650 %
00651 */
00652 
00653 static void *DestroyCoderNode(void *coder_info)
00654 {
00655   register CoderInfo
00656     *p;
00657 
00658   p=(CoderInfo *) coder_info;
00659   if (p->exempt == MagickFalse)
00660     {
00661       if (p->path != (char *) NULL)
00662         p->path=DestroyString(p->path);
00663       if (p->name != (char *) NULL)
00664         p->name=DestroyString(p->name);
00665       if (p->magick != (char *) NULL)
00666         p->magick=DestroyString(p->magick);
00667     }
00668   return(RelinquishMagickMemory(p));
00669 }
00670 
00671 static MagickBooleanType LoadCoderList(const char *xml,const char *filename,
00672   const unsigned long depth,ExceptionInfo *exception)
00673 {
00674   char
00675     keyword[MaxTextExtent],
00676     *token;
00677 
00678   const char
00679     *q;
00680 
00681   CoderInfo
00682     *coder_info;
00683 
00684   MagickBooleanType
00685     status;
00686 
00687   /*
00688     Load the coder map file.
00689   */
00690   (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
00691     "Loading coder configuration file \"%s\" ...",filename);
00692   if (xml == (const char *) NULL)
00693     return(MagickFalse);
00694   if (coder_list == (SplayTreeInfo *) NULL)
00695     {
00696       coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
00697         DestroyCoderNode);
00698       if (coder_list == (SplayTreeInfo *) NULL)
00699         {
00700           ThrowFileException(exception,ResourceLimitError,
00701             "MemoryAllocationFailed",filename);
00702           return(MagickFalse);
00703         }
00704     }
00705   status=MagickTrue;
00706   coder_info=(CoderInfo *) NULL;
00707   token=AcquireString(xml);
00708   for (q=(char *) xml; *q != '\0'; )
00709   {
00710     /*
00711       Interpret XML.
00712     */
00713     GetMagickToken(q,&q,token);
00714     if (*token == '\0')
00715       break;
00716     (void) CopyMagickString(keyword,token,MaxTextExtent);
00717     if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
00718       {
00719         /*
00720           Doctype element.
00721         */
00722         while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
00723           GetMagickToken(q,&q,token);
00724         continue;
00725       }
00726     if (LocaleNCompare(keyword,"<!--",4) == 0)
00727       {
00728         /*
00729           Comment element.
00730         */
00731         while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
00732           GetMagickToken(q,&q,token);
00733         continue;
00734       }
00735     if (LocaleCompare(keyword,"<include") == 0)
00736       {
00737         /*
00738           Include element.
00739         */
00740         while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
00741         {
00742           (void) CopyMagickString(keyword,token,MaxTextExtent);
00743           GetMagickToken(q,&q,token);
00744           if (*token != '=')
00745             continue;
00746           GetMagickToken(q,&q,token);
00747           if (LocaleCompare(keyword,"file") == 0)
00748             {
00749               if (depth > 200)
00750                 (void) ThrowMagickException(exception,GetMagickModule(),
00751                   ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
00752               else
00753                 {
00754                   char
00755                     path[MaxTextExtent],
00756                     *xml;
00757 
00758                   GetPathComponent(filename,HeadPath,path);
00759                   if (*path != '\0')
00760                     (void) ConcatenateMagickString(path,DirectorySeparator,
00761                       MaxTextExtent);
00762                   if (*token == *DirectorySeparator)
00763                     (void) CopyMagickString(path,token,MaxTextExtent);
00764                   else
00765                     (void) ConcatenateMagickString(path,token,MaxTextExtent);
00766                   xml=FileToString(path,~0,exception);
00767                   if (xml != (char *) NULL)
00768                     {
00769                       status=LoadCoderList(xml,path,depth+1,exception);
00770                       xml=(char *) RelinquishMagickMemory(xml);
00771                     }
00772                 }
00773             }
00774         }
00775         continue;
00776       }
00777     if (LocaleCompare(keyword,"<coder") == 0)
00778       {
00779         /*
00780           Coder element.
00781         */
00782         coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
00783         if (coder_info == (CoderInfo *) NULL)
00784           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00785         (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
00786         coder_info->path=ConstantString(filename);
00787         coder_info->exempt=MagickFalse;
00788         coder_info->signature=MagickSignature;
00789         continue;
00790       }
00791     if (coder_info == (CoderInfo *) NULL)
00792       continue;
00793     if (LocaleCompare(keyword,"/>") == 0)
00794       {
00795         status=AddValueToSplayTree(coder_list,ConstantString(
00796           coder_info->magick),coder_info);
00797         if (status == MagickFalse)
00798           (void) ThrowMagickException(exception,GetMagickModule(),
00799             ResourceLimitError,"MemoryAllocationFailed","`%s'",
00800             coder_info->magick);
00801         coder_info=(CoderInfo *) NULL;
00802       }
00803     GetMagickToken(q,(const char **) NULL,token);
00804     if (*token != '=')
00805       continue;
00806     GetMagickToken(q,&q,token);
00807     GetMagickToken(q,&q,token);
00808     switch (*keyword)
00809     {
00810       case 'M':
00811       case 'm':
00812       {
00813         if (LocaleCompare((char *) keyword,"magick") == 0)
00814           {
00815             coder_info->magick=ConstantString(token);
00816             break;
00817           }
00818         break;
00819       }
00820       case 'N':
00821       case 'n':
00822       {
00823         if (LocaleCompare((char *) keyword,"name") == 0)
00824           {
00825             coder_info->name=ConstantString(token);
00826             break;
00827           }
00828         break;
00829       }
00830       case 'S':
00831       case 's':
00832       {
00833         if (LocaleCompare((char *) keyword,"stealth") == 0)
00834           {
00835             coder_info->stealth=IsMagickTrue(token);
00836             break;
00837           }
00838         break;
00839       }
00840       default:
00841         break;
00842     }
00843   }
00844   token=(char *) RelinquishMagickMemory(token);
00845   return(status);
00846 }
00847 
00848 /*
00849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00850 %                                                                             %
00851 %                                                                             %
00852 %                                                                             %
00853 %  L o a d C o d e r L i s t s                                                %
00854 %                                                                             %
00855 %                                                                             %
00856 %                                                                             %
00857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00858 %
00859 %  LoadCoderLists() loads one or more coder configuration file which
00860 %  provides a mapping between coder attributes and a coder name.
00861 %
00862 %  The format of the LoadCoderLists coder is:
00863 %
00864 %      MagickBooleanType LoadCoderLists(const char *filename,
00865 %        ExceptionInfo *exception)
00866 %
00867 %  A description of each parameter follows:
00868 %
00869 %    o filename: the font file name.
00870 %
00871 %    o exception: return any errors or warnings in this structure.
00872 %
00873 */
00874 static MagickBooleanType LoadCoderLists(const char *filename,
00875   ExceptionInfo *exception)
00876 {
00877   const StringInfo
00878     *option;
00879 
00880   LinkedListInfo
00881     *options;
00882 
00883   MagickStatusType
00884     status;
00885 
00886   register long
00887     i;
00888 
00889   /*
00890     Load built-in coder map.
00891   */
00892   status=MagickFalse;
00893   if (coder_list == (SplayTreeInfo *) NULL)
00894     {
00895       coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
00896         DestroyCoderNode);
00897       if (coder_list == (SplayTreeInfo *) NULL)
00898         {
00899           ThrowFileException(exception,ResourceLimitError,
00900             "MemoryAllocationFailed",filename);
00901           return(MagickFalse);
00902         }
00903     }
00904   for (i=0; i < (long) (sizeof(CoderMap)/sizeof(*CoderMap)); i++)
00905   {
00906     CoderInfo
00907       *coder_info;
00908 
00909     register const CoderMapInfo
00910       *p;
00911 
00912     p=CoderMap+i;
00913     coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
00914     if (coder_info == (CoderInfo *) NULL)
00915       {
00916         (void) ThrowMagickException(exception,GetMagickModule(),
00917           ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
00918         continue;
00919       }
00920     (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
00921     coder_info->path=(char *) "[built-in]";
00922     coder_info->magick=(char *) p->magick;
00923     coder_info->name=(char *) p->name;
00924     coder_info->exempt=MagickTrue;
00925     coder_info->signature=MagickSignature;
00926     status=AddValueToSplayTree(coder_list,ConstantString(coder_info->magick),
00927       coder_info);
00928     if (status == MagickFalse)
00929       (void) ThrowMagickException(exception,GetMagickModule(),
00930         ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
00931   }
00932   /*
00933     Load external coder map.
00934   */
00935   options=GetConfigureOptions(filename,exception);
00936   option=(const StringInfo *) GetNextValueInLinkedList(options);
00937   while (option != (const StringInfo *) NULL)
00938   {
00939     status|=LoadCoderList((const char *) GetStringInfoDatum(option),
00940       GetStringInfoPath(option),0,exception);
00941     option=(const StringInfo *) GetNextValueInLinkedList(options);
00942   }
00943   options=DestroyConfigureOptions(options);
00944   return(status != 0 ? MagickTrue : MagickFalse);
00945 }

Generated on 19 Nov 2009 for MagickCore by  doxygen 1.6.1