blob: 2b411ee06e945910cbca264b35e26aa057bfe8ae [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC OOO DDDD EEEEE RRRR %
7% C O O D D E R R %
8% C O O D D EEE RRRR %
9% C O O D D E R R %
10% CCCC OOO DDDD EEEEE R R %
11% %
12% %
13% MagickCore Image Coder Methods %
14% %
15% Software Design %
16% John Cristy %
17% May 2001 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/client.h"
45#include "MagickCore/coder.h"
cristy5ff4eaf2011-09-03 01:38:02 +000046#include "MagickCore/coder-private.h"
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickCore/configure.h"
48#include "MagickCore/draw.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/hashmap.h"
52#include "MagickCore/log.h"
53#include "MagickCore/memory_.h"
54#include "MagickCore/option.h"
55#include "MagickCore/semaphore.h"
56#include "MagickCore/string_.h"
57#include "MagickCore/splay-tree.h"
58#include "MagickCore/token.h"
59#include "MagickCore/utility.h"
cristyd1dd6e42011-09-04 01:46:08 +000060#include "MagickCore/utility-private.h"
cristy4c08aed2011-07-01 19:47:50 +000061#include "MagickCore/xml-tree.h"
cristy3ed852e2009-09-05 21:47:34 +000062
63/*
64 Define declarations.
65*/
66#define MagickCoderFilename "coder.xml"
67
68/*
cristy54a531d2009-10-21 17:58:01 +000069 Typedef declarations.
cristy3ed852e2009-09-05 21:47:34 +000070*/
cristye3e77a12009-10-16 00:47:21 +000071typedef struct _CoderMapInfo
72{
73 const char
74 *magick,
75 *name;
76} CoderMapInfo;
cristy54a531d2009-10-21 17:58:01 +000077
78/*
79 Static declarations.
80*/
cristye3e77a12009-10-16 00:47:21 +000081static const CoderMapInfo
82 CoderMap[] =
83 {
84 { "3FR", "DNG" },
85 { "8BIM", "META" },
86 { "8BIMTEXT", "META" },
87 { "8BIMWTEXT", "META" },
88 { "AFM", "TTF" },
89 { "A", "RAW" },
90 { "AI", "PDF" },
91 { "APP1JPEG", "META" },
92 { "APP1", "META" },
93 { "ARW", "DNG" },
cristy0fc02592010-05-24 14:12:38 +000094 { "AVI", "MPEG" },
cristye3e77a12009-10-16 00:47:21 +000095 { "BIE", "JBIG" },
96 { "BMP2", "BMP" },
97 { "BMP3", "BMP" },
98 { "B", "RAW" },
99 { "BRF", "BRAILLE" },
cristy90dbac72010-08-22 15:08:40 +0000100 { "BGRA", "BGR" },
cristye3e77a12009-10-16 00:47:21 +0000101 { "CMYKA", "CMYK" },
102 { "C", "RAW" },
103 { "CAL", "CALS" },
cristyc05417c2010-09-21 16:30:32 +0000104 { "CANVAS", "XC" },
cristye3e77a12009-10-16 00:47:21 +0000105 { "CR2", "DNG" },
106 { "CRW", "DNG" },
107 { "CUR", "ICON" },
108 { "DCR", "DNG" },
109 { "DCX", "PCX" },
110 { "DFONT", "TTF" },
111 { "EPDF", "PDF" },
112 { "EPI", "PS" },
113 { "EPS2", "PS2" },
114 { "EPS3", "PS3" },
115 { "EPSF", "PS" },
116 { "EPSI", "PS" },
117 { "EPS", "PS" },
118 { "EPT2", "EPT" },
119 { "EPT3", "EPT" },
120 { "ERF", "DNG" },
121 { "EXIF", "META" },
122 { "FILE", "URL" },
123 { "FRACTAL", "PLASMA" },
124 { "FTP", "URL" },
125 { "FTS", "FITS" },
126 { "G3", "FAX" },
127 { "GIF87", "GIF" },
128 { "G", "RAW" },
cristye3e77a12009-10-16 00:47:21 +0000129 { "GRANITE", "MAGICK" },
130 { "GROUP4", "TIFF" },
131 { "K25", "DNG" },
132 { "KDC", "DNG" },
133 { "H", "MAGICK" },
134 { "HTM", "HTML" },
135 { "HTTP", "URL" },
136 { "ICB", "TGA" },
137 { "ICC", "META" },
138 { "ICM", "META" },
139 { "ICO", "ICON" },
140 { "IMPLICIT", "***" },
141 { "IPTC", "META" },
142 { "IPTCTEXT", "META" },
143 { "IPTCWTEXT", "META" },
144 { "ISOBRL", "BRAILLE" },
145 { "JBG", "JBIG" },
146 { "JNG", "PNG" },
147 { "JPC", "JP2" },
cristy02f1fda2009-12-10 15:23:56 +0000148 { "J2C", "JP2" },
cristye3e77a12009-10-16 00:47:21 +0000149 { "JPG", "JPEG" },
150 { "JPX", "JP2" },
151 { "K", "RAW" },
152 { "LOGO", "MAGICK" },
153 { "M2V", "MPEG" },
154 { "M4V", "MPEG" },
155 { "M", "RAW" },
156 { "MNG", "PNG" },
cristy1dbd5a32010-11-28 22:23:27 +0000157 { "MOV", "MPEG" },
cristye3e77a12009-10-16 00:47:21 +0000158 { "MP4", "MPEG" },
159 { "MPG", "MPEG" },
160 { "MPRI", "MPR" },
161 { "MRW", "DNG" },
162 { "MSVG", "SVG" },
163 { "NEF", "DNG" },
164 { "NETSCAPE", "MAGICK" },
165 { "O", "RAW" },
166 { "ORF", "DNG" },
167 { "OTF", "TTF" },
168 { "P7", "PNM" },
169 { "PAL", "UYVY" },
170 { "PAM", "PNM" },
171 { "PBM", "PNM" },
172 { "PCDS", "PCD" },
173 { "PDFA", "PDF" },
174 { "PEF", "DNG" },
175 { "PEF", "DNG" },
176 { "PFA", "TTF" },
177 { "PFB", "TTF" },
178 { "PFM", "PNM" },
179 { "PGM", "PNM" },
180 { "PGX", "JP2" },
181 { "PICON", "XPM" },
182 { "PJPEG", "JPEG" },
183 { "PM", "XPM" },
184 { "PNG24", "PNG" },
185 { "PNG32", "PNG" },
186 { "PNG8", "PNG" },
187 { "PPM", "PNM" },
cristyb4233012010-02-28 20:09:14 +0000188 { "PSB", "PSD" },
cristye3e77a12009-10-16 00:47:21 +0000189 { "PTIF", "TIFF" },
190 { "RADIAL-GRADIENT", "GRADIENT" },
191 { "RAF", "DNG" },
192 { "RAS", "SUN" },
cristye3e77a12009-10-16 00:47:21 +0000193 { "RGBA", "RGB" },
194 { "RGBO", "RGB" },
195 { "R", "RAW" },
196 { "ROSE", "MAGICK" },
197 { "SHTML", "HTML" },
198 { "SR2", "DNG" },
199 { "SRF", "DNG" },
200 { "SVGZ", "SVG" },
201 { "TEXT", "TXT" },
202 { "TIFF64", "TIFF" },
203 { "TIF", "TIFF" },
204 { "TTC", "TTF" },
205 { "UBRL", "BRAILLE" },
206 { "VDA", "TGA" },
207 { "VST", "TGA" },
cristyed40d622011-01-17 15:51:00 +0000208 { "WIZARD", "MAGICK" },
cristye3e77a12009-10-16 00:47:21 +0000209 { "WMV", "MPEG" },
210 { "WMFWIN32", "EMF" },
211 { "WMZ", "WMF" },
212 { "X3f", "DNG" },
213 { "XMP", "META" },
214 { "XTRNARRAY", "XTRN" },
215 { "XTRNBLOB", "XTRN" },
cristye3e77a12009-10-16 00:47:21 +0000216 { "XTRNFILE", "XTRN" },
217 { "XTRNIMAGE", "XTRN" },
cristye3e77a12009-10-16 00:47:21 +0000218 { "XV", "VIFF" },
219 { "Y", "RAW" },
cristy54a531d2009-10-21 17:58:01 +0000220 { "YCbCrA", "YCbCr" }
cristye3e77a12009-10-16 00:47:21 +0000221 };
222
cristy3ed852e2009-09-05 21:47:34 +0000223static SemaphoreInfo
224 *coder_semaphore = (SemaphoreInfo *) NULL;
225
226static SplayTreeInfo
227 *coder_list = (SplayTreeInfo *) NULL;
228
229static volatile MagickBooleanType
230 instantiate_coder = MagickFalse;
231
232/*
233 Forward declarations.
234*/
235static MagickBooleanType
236 InitializeCoderList(ExceptionInfo *),
237 LoadCoderLists(const char *,ExceptionInfo *);
238
239/*
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241% %
242% %
243% %
cristyf34a1452009-10-24 22:29:27 +0000244+ C o d e r C o m p o n e n t G e n e s i s %
cristy3ed852e2009-09-05 21:47:34 +0000245% %
246% %
247% %
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249%
cristyf34a1452009-10-24 22:29:27 +0000250% CoderComponentGenesis() instantiates the coder component.
cristy3ed852e2009-09-05 21:47:34 +0000251%
cristyf34a1452009-10-24 22:29:27 +0000252% The format of the CoderComponentGenesis method is:
cristy3ed852e2009-09-05 21:47:34 +0000253%
cristyf34a1452009-10-24 22:29:27 +0000254% MagickBooleanType CoderComponentGenesis(void)
cristy3ed852e2009-09-05 21:47:34 +0000255%
256*/
cristy5ff4eaf2011-09-03 01:38:02 +0000257MagickPrivate MagickBooleanType CoderComponentGenesis(void)
cristyf34a1452009-10-24 22:29:27 +0000258{
cristy165b6092009-10-26 13:52:10 +0000259 AcquireSemaphoreInfo(&coder_semaphore);
cristyf34a1452009-10-24 22:29:27 +0000260 return(MagickTrue);
261}
262
263/*
264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265% %
266% %
267% %
268+ C o d e r C o m p o n e n t T e r m i n u s %
269% %
270% %
271% %
272%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273%
274% CoderComponentTerminus() destroys the coder component.
275%
276% The format of the CoderComponentTerminus method is:
277%
278% CoderComponentTerminus(void)
279%
280*/
cristy5ff4eaf2011-09-03 01:38:02 +0000281MagickPrivate void CoderComponentTerminus(void)
cristy3ed852e2009-09-05 21:47:34 +0000282{
cristy18b17442009-10-25 18:36:48 +0000283 if (coder_semaphore == (SemaphoreInfo *) NULL)
284 AcquireSemaphoreInfo(&coder_semaphore);
cristyf84a1932010-01-03 18:00:18 +0000285 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000286 if (coder_list != (SplayTreeInfo *) NULL)
287 coder_list=DestroySplayTree(coder_list);
288 instantiate_coder=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000289 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000290 DestroySemaphoreInfo(&coder_semaphore);
291}
292
293/*
294%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295% %
296% %
297% %
298+ G e t C o d e r I n f o %
299% %
300% %
301% %
302%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303%
304% GetCoderInfo searches the coder list for the specified name and if found
305% returns attributes for that coder.
306%
307% The format of the GetCoderInfo method is:
308%
309% const CoderInfo *GetCoderInfo(const char *name,ExceptionInfo *exception)
310%
311% A description of each parameter follows:
312%
313% o name: the coder name.
314%
315% o exception: return any errors or warnings in this structure.
316%
317*/
318MagickExport const CoderInfo *GetCoderInfo(const char *name,
319 ExceptionInfo *exception)
320{
321 assert(exception != (ExceptionInfo *) NULL);
322 if ((coder_list == (SplayTreeInfo *) NULL) ||
323 (instantiate_coder == MagickFalse))
324 if (InitializeCoderList(exception) == MagickFalse)
325 return((const CoderInfo *) NULL);
326 if ((coder_list == (SplayTreeInfo *) NULL) ||
327 (GetNumberOfNodesInSplayTree(coder_list) == 0))
328 return((const CoderInfo *) NULL);
329 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
330 {
331 ResetSplayTreeIterator(coder_list);
332 return((const CoderInfo *) GetNextValueInSplayTree(coder_list));
333 }
334 return((const CoderInfo *) GetValueFromSplayTree(coder_list,name));
335}
336
337/*
338%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339% %
340% %
341% %
342% G e t C o d e r I n f o L i s t %
343% %
344% %
345% %
346%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347%
348% GetCoderInfoList() returns any coder_map that match the specified pattern.
349% The format of the GetCoderInfoList function is:
350%
351% const CoderInfo **GetCoderInfoList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000352% size_t *number_coders,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000353%
354% A description of each parameter follows:
355%
356% o pattern: Specifies a pointer to a text string containing a pattern.
357%
358% o number_coders: This integer returns the number of coders in the list.
359%
360% o exception: return any errors or warnings in this structure.
361%
362*/
363
364static int CoderInfoCompare(const void *x,const void *y)
365{
366 const CoderInfo
367 **p,
368 **q;
369
370 p=(const CoderInfo **) x,
371 q=(const CoderInfo **) y;
372 if (LocaleCompare((*p)->path,(*q)->path) == 0)
373 return(LocaleCompare((*p)->name,(*q)->name));
374 return(LocaleCompare((*p)->path,(*q)->path));
375}
376
377MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000378 size_t *number_coders,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000379{
380 const CoderInfo
381 **coder_map;
382
383 register const CoderInfo
384 *p;
385
cristybb503372010-05-27 20:51:26 +0000386 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000387 i;
388
389 /*
390 Allocate coder list.
391 */
392 assert(pattern != (char *) NULL);
393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
cristybb503372010-05-27 20:51:26 +0000394 assert(number_coders != (size_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000395 *number_coders=0;
396 p=GetCoderInfo("*",exception);
397 if (p == (const CoderInfo *) NULL)
398 return((const CoderInfo **) NULL);
399 coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t)
400 GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map));
401 if (coder_map == (const CoderInfo **) NULL)
402 return((const CoderInfo **) NULL);
403 /*
404 Generate coder list.
405 */
cristyf84a1932010-01-03 18:00:18 +0000406 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000407 ResetSplayTreeIterator(coder_list);
408 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
409 for (i=0; p != (const CoderInfo *) NULL; )
410 {
411 if ((p->stealth == MagickFalse) &&
412 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
413 coder_map[i++]=p;
414 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
415 }
cristyf84a1932010-01-03 18:00:18 +0000416 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000417 qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare);
418 coder_map[i]=(CoderInfo *) NULL;
cristybb503372010-05-27 20:51:26 +0000419 *number_coders=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000420 return(coder_map);
421}
422
423/*
424%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425% %
426% %
427% %
428% G e t C o d e r L i s t %
429% %
430% %
431% %
432%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433%
434% GetCoderList() returns any coder_map that match the specified pattern.
435%
436% The format of the GetCoderList function is:
437%
cristybb503372010-05-27 20:51:26 +0000438% char **GetCoderList(const char *pattern,size_t *number_coders,
cristy3ed852e2009-09-05 21:47:34 +0000439% ExceptionInfo *exception)
440%
441% A description of each parameter follows:
442%
443% o pattern: Specifies a pointer to a text string containing a pattern.
444%
445% o number_coders: This integer returns the number of coders in the list.
446%
447% o exception: return any errors or warnings in this structure.
448%
449*/
450
451static int CoderCompare(const void *x,const void *y)
452{
453 register const char
454 **p,
455 **q;
456
457 p=(const char **) x;
458 q=(const char **) y;
459 return(LocaleCompare(*p,*q));
460}
461
462MagickExport char **GetCoderList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000463 size_t *number_coders,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000464{
465 char
466 **coder_map;
467
468 register const CoderInfo
469 *p;
470
cristybb503372010-05-27 20:51:26 +0000471 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000472 i;
473
474 /*
475 Allocate coder list.
476 */
477 assert(pattern != (char *) NULL);
478 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
cristybb503372010-05-27 20:51:26 +0000479 assert(number_coders != (size_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000480 *number_coders=0;
481 p=GetCoderInfo("*",exception);
482 if (p == (const CoderInfo *) NULL)
483 return((char **) NULL);
484 coder_map=(char **) AcquireQuantumMemory((size_t)
485 GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map));
486 if (coder_map == (char **) NULL)
487 return((char **) NULL);
488 /*
489 Generate coder list.
490 */
cristyf84a1932010-01-03 18:00:18 +0000491 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000492 ResetSplayTreeIterator(coder_list);
493 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
494 for (i=0; p != (const CoderInfo *) NULL; )
495 {
496 if ((p->stealth == MagickFalse) &&
497 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
498 coder_map[i++]=ConstantString(p->name);
499 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
500 }
cristyf84a1932010-01-03 18:00:18 +0000501 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000502 qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare);
503 coder_map[i]=(char *) NULL;
cristybb503372010-05-27 20:51:26 +0000504 *number_coders=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000505 return(coder_map);
506}
507
508/*
509%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
510% %
511% %
512% %
513+ I n i t i a l i z e C o d e r L i s t %
514% %
515% %
516% %
517%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518%
519% InitializeCoderList() initializes the coder list.
520%
521% The format of the InitializeCoderList method is:
522%
523% MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
524%
525% A description of each parameter follows.
526%
527% o exception: return any errors or warnings in this structure.
528%
529*/
530static MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
531{
532 if ((coder_list == (SplayTreeInfo *) NULL) &&
533 (instantiate_coder == MagickFalse))
534 {
cristy4e1dff62009-10-25 20:36:03 +0000535 if (coder_semaphore == (SemaphoreInfo *) NULL)
536 AcquireSemaphoreInfo(&coder_semaphore);
cristyf84a1932010-01-03 18:00:18 +0000537 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000538 if ((coder_list == (SplayTreeInfo *) NULL) &&
539 (instantiate_coder == MagickFalse))
540 {
541 (void) LoadCoderLists(MagickCoderFilename,exception);
542 instantiate_coder=MagickTrue;
543 }
cristyf84a1932010-01-03 18:00:18 +0000544 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000545 }
546 return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
547}
548
549/*
550%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551% %
552% %
553% %
554% L i s t C o d e r I n f o %
555% %
556% %
557% %
558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
559%
560% ListCoderInfo() lists the coder info to a file.
561%
562% The format of the ListCoderInfo coder is:
563%
564% MagickBooleanType ListCoderInfo(FILE *file,ExceptionInfo *exception)
565%
566% A description of each parameter follows.
567%
568% o file: An pointer to a FILE.
569%
570% o exception: return any errors or warnings in this structure.
571%
572*/
573MagickExport MagickBooleanType ListCoderInfo(FILE *file,
574 ExceptionInfo *exception)
575{
576 const char
577 *path;
578
579 const CoderInfo
580 **coder_info;
581
cristybb503372010-05-27 20:51:26 +0000582 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000583 i;
584
cristybb503372010-05-27 20:51:26 +0000585 size_t
cristy3ed852e2009-09-05 21:47:34 +0000586 number_coders;
587
cristy9d314ff2011-03-09 01:30:28 +0000588 ssize_t
589 j;
590
cristy3ed852e2009-09-05 21:47:34 +0000591 if (file == (const FILE *) NULL)
592 file=stdout;
593 coder_info=GetCoderInfoList("*",&number_coders,exception);
594 if (coder_info == (const CoderInfo **) NULL)
595 return(MagickFalse);
596 path=(const char *) NULL;
cristybb503372010-05-27 20:51:26 +0000597 for (i=0; i < (ssize_t) number_coders; i++)
cristy3ed852e2009-09-05 21:47:34 +0000598 {
599 if (coder_info[i]->stealth != MagickFalse)
600 continue;
601 if ((path == (const char *) NULL) ||
602 (LocaleCompare(path,coder_info[i]->path) != 0))
603 {
604 if (coder_info[i]->path != (char *) NULL)
cristyb51dff52011-05-19 16:55:47 +0000605 (void) FormatLocaleFile(file,"\nPath: %s\n\n",coder_info[i]->path);
606 (void) FormatLocaleFile(file,"Magick Coder\n");
cristy1e604812011-05-19 18:07:50 +0000607 (void) FormatLocaleFile(file,
608 "-------------------------------------------------"
cristy3ed852e2009-09-05 21:47:34 +0000609 "------------------------------\n");
610 }
611 path=coder_info[i]->path;
cristyb51dff52011-05-19 16:55:47 +0000612 (void) FormatLocaleFile(file,"%s",coder_info[i]->magick);
cristybb503372010-05-27 20:51:26 +0000613 for (j=(ssize_t) strlen(coder_info[i]->magick); j <= 11; j++)
cristyb51dff52011-05-19 16:55:47 +0000614 (void) FormatLocaleFile(file," ");
cristy3ed852e2009-09-05 21:47:34 +0000615 if (coder_info[i]->name != (char *) NULL)
cristyb51dff52011-05-19 16:55:47 +0000616 (void) FormatLocaleFile(file,"%s",coder_info[i]->name);
617 (void) FormatLocaleFile(file,"\n");
cristy3ed852e2009-09-05 21:47:34 +0000618 }
619 coder_info=(const CoderInfo **) RelinquishMagickMemory((void *) coder_info);
620 (void) fflush(file);
621 return(MagickTrue);
622}
623
624/*
625%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
626% %
627% %
628% %
629+ L o a d C o d e r L i s t %
630% %
631% %
632% %
633%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634%
635% LoadCoderList() loads the coder configuration file which provides a
636% mapping between coder attributes and a coder name.
637%
638% The format of the LoadCoderList coder is:
639%
640% MagickBooleanType LoadCoderList(const char *xml,const char *filename,
cristybb503372010-05-27 20:51:26 +0000641% const size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000642%
643% A description of each parameter follows:
644%
645% o xml: The coder list in XML format.
646%
647% o filename: The coder list filename.
648%
649% o depth: depth of <include /> statements.
650%
651% o exception: return any errors or warnings in this structure.
652%
653*/
654
655static void *DestroyCoderNode(void *coder_info)
656{
657 register CoderInfo
658 *p;
659
660 p=(CoderInfo *) coder_info;
cristye3e77a12009-10-16 00:47:21 +0000661 if (p->exempt == MagickFalse)
662 {
663 if (p->path != (char *) NULL)
664 p->path=DestroyString(p->path);
665 if (p->name != (char *) NULL)
666 p->name=DestroyString(p->name);
667 if (p->magick != (char *) NULL)
668 p->magick=DestroyString(p->magick);
669 }
cristy3ed852e2009-09-05 21:47:34 +0000670 return(RelinquishMagickMemory(p));
671}
672
673static MagickBooleanType LoadCoderList(const char *xml,const char *filename,
cristybb503372010-05-27 20:51:26 +0000674 const size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000675{
676 char
677 keyword[MaxTextExtent],
678 *token;
679
680 const char
681 *q;
682
683 CoderInfo
684 *coder_info;
685
686 MagickBooleanType
687 status;
688
689 /*
690 Load the coder map file.
691 */
692 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
693 "Loading coder configuration file \"%s\" ...",filename);
694 if (xml == (const char *) NULL)
695 return(MagickFalse);
696 if (coder_list == (SplayTreeInfo *) NULL)
697 {
698 coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
699 DestroyCoderNode);
700 if (coder_list == (SplayTreeInfo *) NULL)
701 {
702 ThrowFileException(exception,ResourceLimitError,
703 "MemoryAllocationFailed",filename);
704 return(MagickFalse);
705 }
706 }
707 status=MagickTrue;
708 coder_info=(CoderInfo *) NULL;
709 token=AcquireString(xml);
710 for (q=(char *) xml; *q != '\0'; )
711 {
712 /*
713 Interpret XML.
714 */
715 GetMagickToken(q,&q,token);
716 if (*token == '\0')
717 break;
718 (void) CopyMagickString(keyword,token,MaxTextExtent);
719 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
720 {
721 /*
722 Doctype element.
723 */
724 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
725 GetMagickToken(q,&q,token);
726 continue;
727 }
728 if (LocaleNCompare(keyword,"<!--",4) == 0)
729 {
730 /*
731 Comment element.
732 */
733 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
734 GetMagickToken(q,&q,token);
735 continue;
736 }
737 if (LocaleCompare(keyword,"<include") == 0)
738 {
739 /*
740 Include element.
741 */
742 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
743 {
744 (void) CopyMagickString(keyword,token,MaxTextExtent);
745 GetMagickToken(q,&q,token);
746 if (*token != '=')
747 continue;
748 GetMagickToken(q,&q,token);
749 if (LocaleCompare(keyword,"file") == 0)
750 {
751 if (depth > 200)
752 (void) ThrowMagickException(exception,GetMagickModule(),
753 ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
754 else
755 {
756 char
757 path[MaxTextExtent],
758 *xml;
759
760 GetPathComponent(filename,HeadPath,path);
761 if (*path != '\0')
762 (void) ConcatenateMagickString(path,DirectorySeparator,
763 MaxTextExtent);
764 if (*token == *DirectorySeparator)
765 (void) CopyMagickString(path,token,MaxTextExtent);
766 else
767 (void) ConcatenateMagickString(path,token,MaxTextExtent);
768 xml=FileToString(path,~0,exception);
769 if (xml != (char *) NULL)
770 {
771 status=LoadCoderList(xml,path,depth+1,exception);
772 xml=(char *) RelinquishMagickMemory(xml);
773 }
774 }
775 }
776 }
777 continue;
778 }
779 if (LocaleCompare(keyword,"<coder") == 0)
780 {
781 /*
782 Coder element.
783 */
cristy73bd4a52010-10-05 11:24:23 +0000784 coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
cristy3ed852e2009-09-05 21:47:34 +0000785 if (coder_info == (CoderInfo *) NULL)
786 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
787 (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
788 coder_info->path=ConstantString(filename);
cristye3e77a12009-10-16 00:47:21 +0000789 coder_info->exempt=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000790 coder_info->signature=MagickSignature;
791 continue;
792 }
793 if (coder_info == (CoderInfo *) NULL)
794 continue;
795 if (LocaleCompare(keyword,"/>") == 0)
796 {
797 status=AddValueToSplayTree(coder_list,ConstantString(
798 coder_info->magick),coder_info);
799 if (status == MagickFalse)
800 (void) ThrowMagickException(exception,GetMagickModule(),
801 ResourceLimitError,"MemoryAllocationFailed","`%s'",
802 coder_info->magick);
803 coder_info=(CoderInfo *) NULL;
804 }
805 GetMagickToken(q,(const char **) NULL,token);
806 if (*token != '=')
807 continue;
808 GetMagickToken(q,&q,token);
809 GetMagickToken(q,&q,token);
810 switch (*keyword)
811 {
812 case 'M':
813 case 'm':
814 {
815 if (LocaleCompare((char *) keyword,"magick") == 0)
816 {
817 coder_info->magick=ConstantString(token);
818 break;
819 }
820 break;
821 }
822 case 'N':
823 case 'n':
824 {
825 if (LocaleCompare((char *) keyword,"name") == 0)
826 {
827 coder_info->name=ConstantString(token);
828 break;
829 }
830 break;
831 }
832 case 'S':
833 case 's':
834 {
835 if (LocaleCompare((char *) keyword,"stealth") == 0)
836 {
837 coder_info->stealth=IsMagickTrue(token);
838 break;
839 }
840 break;
841 }
842 default:
843 break;
844 }
845 }
846 token=(char *) RelinquishMagickMemory(token);
847 return(status);
848}
849
850/*
851%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
852% %
853% %
854% %
855% L o a d C o d e r L i s t s %
856% %
857% %
858% %
859%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860%
861% LoadCoderLists() loads one or more coder configuration file which
862% provides a mapping between coder attributes and a coder name.
863%
864% The format of the LoadCoderLists coder is:
865%
866% MagickBooleanType LoadCoderLists(const char *filename,
867% ExceptionInfo *exception)
868%
869% A description of each parameter follows:
870%
871% o filename: the font file name.
872%
873% o exception: return any errors or warnings in this structure.
874%
875*/
876static MagickBooleanType LoadCoderLists(const char *filename,
877 ExceptionInfo *exception)
878{
cristy3ed852e2009-09-05 21:47:34 +0000879 const StringInfo
880 *option;
881
882 LinkedListInfo
883 *options;
884
885 MagickStatusType
886 status;
887
cristybb503372010-05-27 20:51:26 +0000888 register ssize_t
cristy54a531d2009-10-21 17:58:01 +0000889 i;
cristye3e77a12009-10-16 00:47:21 +0000890
891 /*
892 Load built-in coder map.
893 */
cristy3ed852e2009-09-05 21:47:34 +0000894 status=MagickFalse;
cristye3e77a12009-10-16 00:47:21 +0000895 if (coder_list == (SplayTreeInfo *) NULL)
896 {
897 coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
898 DestroyCoderNode);
899 if (coder_list == (SplayTreeInfo *) NULL)
900 {
901 ThrowFileException(exception,ResourceLimitError,
902 "MemoryAllocationFailed",filename);
903 return(MagickFalse);
904 }
905 }
cristybb503372010-05-27 20:51:26 +0000906 for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++)
cristye3e77a12009-10-16 00:47:21 +0000907 {
908 CoderInfo
909 *coder_info;
910
cristy54a531d2009-10-21 17:58:01 +0000911 register const CoderMapInfo
912 *p;
913
914 p=CoderMap+i;
cristy73bd4a52010-10-05 11:24:23 +0000915 coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
cristye3e77a12009-10-16 00:47:21 +0000916 if (coder_info == (CoderInfo *) NULL)
917 {
918 (void) ThrowMagickException(exception,GetMagickModule(),
919 ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
920 continue;
921 }
922 (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
cristy38b8ed92009-10-16 01:20:21 +0000923 coder_info->path=(char *) "[built-in]";
cristye3e77a12009-10-16 00:47:21 +0000924 coder_info->magick=(char *) p->magick;
925 coder_info->name=(char *) p->name;
926 coder_info->exempt=MagickTrue;
927 coder_info->signature=MagickSignature;
928 status=AddValueToSplayTree(coder_list,ConstantString(coder_info->magick),
929 coder_info);
930 if (status == MagickFalse)
931 (void) ThrowMagickException(exception,GetMagickModule(),
932 ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
933 }
934 /*
935 Load external coder map.
936 */
cristy3ed852e2009-09-05 21:47:34 +0000937 options=GetConfigureOptions(filename,exception);
938 option=(const StringInfo *) GetNextValueInLinkedList(options);
939 while (option != (const StringInfo *) NULL)
940 {
941 status|=LoadCoderList((const char *) GetStringInfoDatum(option),
942 GetStringInfoPath(option),0,exception);
943 option=(const StringInfo *) GetNextValueInLinkedList(options);
944 }
945 options=DestroyConfigureOptions(options);
cristy3ed852e2009-09-05 21:47:34 +0000946 return(status != 0 ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +0000947}