blob: 9a7d213df467bee74e193dd37c5c0debbe238975 [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% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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*/
42#include "magick/studio.h"
43#include "magick/blob.h"
44#include "magick/client.h"
45#include "magick/coder.h"
46#include "magick/configure.h"
47#include "magick/draw.h"
48#include "magick/exception.h"
49#include "magick/exception-private.h"
50#include "magick/hashmap.h"
51#include "magick/log.h"
52#include "magick/memory_.h"
53#include "magick/option.h"
54#include "magick/semaphore.h"
55#include "magick/string_.h"
56#include "magick/splay-tree.h"
57#include "magick/token.h"
58#include "magick/utility.h"
59#include "magick/xml-tree.h"
60
61/*
62 Define declarations.
63*/
64#define MagickCoderFilename "coder.xml"
65
66/*
cristy54a531d2009-10-21 17:58:01 +000067 Typedef declarations.
cristy3ed852e2009-09-05 21:47:34 +000068*/
cristye3e77a12009-10-16 00:47:21 +000069typedef struct _CoderMapInfo
70{
71 const char
72 *magick,
73 *name;
74} CoderMapInfo;
cristy54a531d2009-10-21 17:58:01 +000075
76/*
77 Static declarations.
78*/
cristye3e77a12009-10-16 00:47:21 +000079static const CoderMapInfo
80 CoderMap[] =
81 {
82 { "3FR", "DNG" },
83 { "8BIM", "META" },
84 { "8BIMTEXT", "META" },
85 { "8BIMWTEXT", "META" },
86 { "AFM", "TTF" },
87 { "A", "RAW" },
88 { "AI", "PDF" },
89 { "APP1JPEG", "META" },
90 { "APP1", "META" },
91 { "ARW", "DNG" },
cristy0fc02592010-05-24 14:12:38 +000092 { "AVI", "MPEG" },
cristye3e77a12009-10-16 00:47:21 +000093 { "BIE", "JBIG" },
94 { "BMP2", "BMP" },
95 { "BMP3", "BMP" },
96 { "B", "RAW" },
97 { "BRF", "BRAILLE" },
cristy90dbac72010-08-22 15:08:40 +000098 { "BGRA", "BGR" },
cristye3e77a12009-10-16 00:47:21 +000099 { "CMYKA", "CMYK" },
100 { "C", "RAW" },
101 { "CAL", "CALS" },
102 { "CR2", "DNG" },
103 { "CRW", "DNG" },
104 { "CUR", "ICON" },
105 { "DCR", "DNG" },
106 { "DCX", "PCX" },
107 { "DFONT", "TTF" },
108 { "EPDF", "PDF" },
109 { "EPI", "PS" },
110 { "EPS2", "PS2" },
111 { "EPS3", "PS3" },
112 { "EPSF", "PS" },
113 { "EPSI", "PS" },
114 { "EPS", "PS" },
115 { "EPT2", "EPT" },
116 { "EPT3", "EPT" },
117 { "ERF", "DNG" },
118 { "EXIF", "META" },
119 { "FILE", "URL" },
120 { "FRACTAL", "PLASMA" },
121 { "FTP", "URL" },
122 { "FTS", "FITS" },
123 { "G3", "FAX" },
124 { "GIF87", "GIF" },
125 { "G", "RAW" },
cristye3e77a12009-10-16 00:47:21 +0000126 { "GRANITE", "MAGICK" },
127 { "GROUP4", "TIFF" },
128 { "K25", "DNG" },
129 { "KDC", "DNG" },
130 { "H", "MAGICK" },
131 { "HTM", "HTML" },
132 { "HTTP", "URL" },
133 { "ICB", "TGA" },
134 { "ICC", "META" },
135 { "ICM", "META" },
136 { "ICO", "ICON" },
137 { "IMPLICIT", "***" },
138 { "IPTC", "META" },
139 { "IPTCTEXT", "META" },
140 { "IPTCWTEXT", "META" },
141 { "ISOBRL", "BRAILLE" },
142 { "JBG", "JBIG" },
143 { "JNG", "PNG" },
144 { "JPC", "JP2" },
cristy02f1fda2009-12-10 15:23:56 +0000145 { "J2C", "JP2" },
cristye3e77a12009-10-16 00:47:21 +0000146 { "JPG", "JPEG" },
147 { "JPX", "JP2" },
148 { "K", "RAW" },
149 { "LOGO", "MAGICK" },
150 { "M2V", "MPEG" },
151 { "M4V", "MPEG" },
152 { "M", "RAW" },
153 { "MNG", "PNG" },
154 { "MOV", "PNG" },
155 { "MP4", "MPEG" },
156 { "MPG", "MPEG" },
157 { "MPRI", "MPR" },
158 { "MRW", "DNG" },
159 { "MSVG", "SVG" },
160 { "NEF", "DNG" },
161 { "NETSCAPE", "MAGICK" },
162 { "O", "RAW" },
163 { "ORF", "DNG" },
164 { "OTF", "TTF" },
165 { "P7", "PNM" },
166 { "PAL", "UYVY" },
167 { "PAM", "PNM" },
168 { "PBM", "PNM" },
169 { "PCDS", "PCD" },
170 { "PDFA", "PDF" },
171 { "PEF", "DNG" },
172 { "PEF", "DNG" },
173 { "PFA", "TTF" },
174 { "PFB", "TTF" },
175 { "PFM", "PNM" },
176 { "PGM", "PNM" },
177 { "PGX", "JP2" },
178 { "PICON", "XPM" },
179 { "PJPEG", "JPEG" },
180 { "PM", "XPM" },
181 { "PNG24", "PNG" },
182 { "PNG32", "PNG" },
183 { "PNG8", "PNG" },
184 { "PPM", "PNM" },
cristyb4233012010-02-28 20:09:14 +0000185 { "PSB", "PSD" },
cristye3e77a12009-10-16 00:47:21 +0000186 { "PTIF", "TIFF" },
187 { "RADIAL-GRADIENT", "GRADIENT" },
188 { "RAF", "DNG" },
189 { "RAS", "SUN" },
cristye3e77a12009-10-16 00:47:21 +0000190 { "RGBA", "RGB" },
191 { "RGBO", "RGB" },
192 { "R", "RAW" },
193 { "ROSE", "MAGICK" },
194 { "SHTML", "HTML" },
195 { "SR2", "DNG" },
196 { "SRF", "DNG" },
197 { "SVGZ", "SVG" },
198 { "TEXT", "TXT" },
199 { "TIFF64", "TIFF" },
200 { "TIF", "TIFF" },
201 { "TTC", "TTF" },
202 { "UBRL", "BRAILLE" },
203 { "VDA", "TGA" },
204 { "VST", "TGA" },
205 { "WMV", "MPEG" },
206 { "WMFWIN32", "EMF" },
207 { "WMZ", "WMF" },
208 { "X3f", "DNG" },
209 { "XMP", "META" },
210 { "XTRNARRAY", "XTRN" },
211 { "XTRNBLOB", "XTRN" },
212 { "XTRNBSTR", "XTRN" },
213 { "XTRNFILE", "XTRN" },
214 { "XTRNIMAGE", "XTRN" },
215 { "XTRNSTREAM", "XTRN" },
216 { "XV", "VIFF" },
217 { "Y", "RAW" },
cristy54a531d2009-10-21 17:58:01 +0000218 { "YCbCrA", "YCbCr" }
cristye3e77a12009-10-16 00:47:21 +0000219 };
220
cristy3ed852e2009-09-05 21:47:34 +0000221static SemaphoreInfo
222 *coder_semaphore = (SemaphoreInfo *) NULL;
223
224static SplayTreeInfo
225 *coder_list = (SplayTreeInfo *) NULL;
226
227static volatile MagickBooleanType
228 instantiate_coder = MagickFalse;
229
230/*
231 Forward declarations.
232*/
233static MagickBooleanType
234 InitializeCoderList(ExceptionInfo *),
235 LoadCoderLists(const char *,ExceptionInfo *);
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
cristyf34a1452009-10-24 22:29:27 +0000242+ 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 +0000243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
cristyf34a1452009-10-24 22:29:27 +0000248% CoderComponentGenesis() instantiates the coder component.
cristy3ed852e2009-09-05 21:47:34 +0000249%
cristyf34a1452009-10-24 22:29:27 +0000250% The format of the CoderComponentGenesis method is:
cristy3ed852e2009-09-05 21:47:34 +0000251%
cristyf34a1452009-10-24 22:29:27 +0000252% MagickBooleanType CoderComponentGenesis(void)
cristy3ed852e2009-09-05 21:47:34 +0000253%
254*/
cristyf34a1452009-10-24 22:29:27 +0000255MagickExport MagickBooleanType CoderComponentGenesis(void)
256{
cristy165b6092009-10-26 13:52:10 +0000257 AcquireSemaphoreInfo(&coder_semaphore);
cristyf34a1452009-10-24 22:29:27 +0000258 return(MagickTrue);
259}
260
261/*
262%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263% %
264% %
265% %
266+ C o d e r C o m p o n e n t T e r m i n u s %
267% %
268% %
269% %
270%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271%
272% CoderComponentTerminus() destroys the coder component.
273%
274% The format of the CoderComponentTerminus method is:
275%
276% CoderComponentTerminus(void)
277%
278*/
279MagickExport void CoderComponentTerminus(void)
cristy3ed852e2009-09-05 21:47:34 +0000280{
cristy18b17442009-10-25 18:36:48 +0000281 if (coder_semaphore == (SemaphoreInfo *) NULL)
282 AcquireSemaphoreInfo(&coder_semaphore);
cristyf84a1932010-01-03 18:00:18 +0000283 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000284 if (coder_list != (SplayTreeInfo *) NULL)
285 coder_list=DestroySplayTree(coder_list);
286 instantiate_coder=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000287 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000288 DestroySemaphoreInfo(&coder_semaphore);
289}
290
291/*
292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293% %
294% %
295% %
296+ G e t C o d e r I n f o %
297% %
298% %
299% %
300%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301%
302% GetCoderInfo searches the coder list for the specified name and if found
303% returns attributes for that coder.
304%
305% The format of the GetCoderInfo method is:
306%
307% const CoderInfo *GetCoderInfo(const char *name,ExceptionInfo *exception)
308%
309% A description of each parameter follows:
310%
311% o name: the coder name.
312%
313% o exception: return any errors or warnings in this structure.
314%
315*/
316MagickExport const CoderInfo *GetCoderInfo(const char *name,
317 ExceptionInfo *exception)
318{
319 assert(exception != (ExceptionInfo *) NULL);
320 if ((coder_list == (SplayTreeInfo *) NULL) ||
321 (instantiate_coder == MagickFalse))
322 if (InitializeCoderList(exception) == MagickFalse)
323 return((const CoderInfo *) NULL);
324 if ((coder_list == (SplayTreeInfo *) NULL) ||
325 (GetNumberOfNodesInSplayTree(coder_list) == 0))
326 return((const CoderInfo *) NULL);
327 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
328 {
329 ResetSplayTreeIterator(coder_list);
330 return((const CoderInfo *) GetNextValueInSplayTree(coder_list));
331 }
332 return((const CoderInfo *) GetValueFromSplayTree(coder_list,name));
333}
334
335/*
336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337% %
338% %
339% %
340% G e t C o d e r I n f o L i s t %
341% %
342% %
343% %
344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345%
346% GetCoderInfoList() returns any coder_map that match the specified pattern.
347% The format of the GetCoderInfoList function is:
348%
349% const CoderInfo **GetCoderInfoList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000350% size_t *number_coders,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000351%
352% A description of each parameter follows:
353%
354% o pattern: Specifies a pointer to a text string containing a pattern.
355%
356% o number_coders: This integer returns the number of coders in the list.
357%
358% o exception: return any errors or warnings in this structure.
359%
360*/
361
362static int CoderInfoCompare(const void *x,const void *y)
363{
364 const CoderInfo
365 **p,
366 **q;
367
368 p=(const CoderInfo **) x,
369 q=(const CoderInfo **) y;
370 if (LocaleCompare((*p)->path,(*q)->path) == 0)
371 return(LocaleCompare((*p)->name,(*q)->name));
372 return(LocaleCompare((*p)->path,(*q)->path));
373}
374
375MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000376 size_t *number_coders,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000377{
378 const CoderInfo
379 **coder_map;
380
381 register const CoderInfo
382 *p;
383
cristybb503372010-05-27 20:51:26 +0000384 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000385 i;
386
387 /*
388 Allocate coder list.
389 */
390 assert(pattern != (char *) NULL);
391 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
cristybb503372010-05-27 20:51:26 +0000392 assert(number_coders != (size_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000393 *number_coders=0;
394 p=GetCoderInfo("*",exception);
395 if (p == (const CoderInfo *) NULL)
396 return((const CoderInfo **) NULL);
397 coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t)
398 GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map));
399 if (coder_map == (const CoderInfo **) NULL)
400 return((const CoderInfo **) NULL);
401 /*
402 Generate coder list.
403 */
cristyf84a1932010-01-03 18:00:18 +0000404 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000405 ResetSplayTreeIterator(coder_list);
406 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
407 for (i=0; p != (const CoderInfo *) NULL; )
408 {
409 if ((p->stealth == MagickFalse) &&
410 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
411 coder_map[i++]=p;
412 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
413 }
cristyf84a1932010-01-03 18:00:18 +0000414 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000415 qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare);
416 coder_map[i]=(CoderInfo *) NULL;
cristybb503372010-05-27 20:51:26 +0000417 *number_coders=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000418 return(coder_map);
419}
420
421/*
422%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423% %
424% %
425% %
426% G e t C o d e r L i s t %
427% %
428% %
429% %
430%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
431%
432% GetCoderList() returns any coder_map that match the specified pattern.
433%
434% The format of the GetCoderList function is:
435%
cristybb503372010-05-27 20:51:26 +0000436% char **GetCoderList(const char *pattern,size_t *number_coders,
cristy3ed852e2009-09-05 21:47:34 +0000437% ExceptionInfo *exception)
438%
439% A description of each parameter follows:
440%
441% o pattern: Specifies a pointer to a text string containing a pattern.
442%
443% o number_coders: This integer returns the number of coders in the list.
444%
445% o exception: return any errors or warnings in this structure.
446%
447*/
448
449static int CoderCompare(const void *x,const void *y)
450{
451 register const char
452 **p,
453 **q;
454
455 p=(const char **) x;
456 q=(const char **) y;
457 return(LocaleCompare(*p,*q));
458}
459
460MagickExport char **GetCoderList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000461 size_t *number_coders,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000462{
463 char
464 **coder_map;
465
466 register const CoderInfo
467 *p;
468
cristybb503372010-05-27 20:51:26 +0000469 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000470 i;
471
472 /*
473 Allocate coder list.
474 */
475 assert(pattern != (char *) NULL);
476 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
cristybb503372010-05-27 20:51:26 +0000477 assert(number_coders != (size_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000478 *number_coders=0;
479 p=GetCoderInfo("*",exception);
480 if (p == (const CoderInfo *) NULL)
481 return((char **) NULL);
482 coder_map=(char **) AcquireQuantumMemory((size_t)
483 GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map));
484 if (coder_map == (char **) NULL)
485 return((char **) NULL);
486 /*
487 Generate coder list.
488 */
cristyf84a1932010-01-03 18:00:18 +0000489 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000490 ResetSplayTreeIterator(coder_list);
491 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
492 for (i=0; p != (const CoderInfo *) NULL; )
493 {
494 if ((p->stealth == MagickFalse) &&
495 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
496 coder_map[i++]=ConstantString(p->name);
497 p=(const CoderInfo *) GetNextValueInSplayTree(coder_list);
498 }
cristyf84a1932010-01-03 18:00:18 +0000499 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000500 qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare);
501 coder_map[i]=(char *) NULL;
cristybb503372010-05-27 20:51:26 +0000502 *number_coders=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000503 return(coder_map);
504}
505
506/*
507%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508% %
509% %
510% %
511+ I n i t i a l i z e C o d e r L i s t %
512% %
513% %
514% %
515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516%
517% InitializeCoderList() initializes the coder list.
518%
519% The format of the InitializeCoderList method is:
520%
521% MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
522%
523% A description of each parameter follows.
524%
525% o exception: return any errors or warnings in this structure.
526%
527*/
528static MagickBooleanType InitializeCoderList(ExceptionInfo *exception)
529{
530 if ((coder_list == (SplayTreeInfo *) NULL) &&
531 (instantiate_coder == MagickFalse))
532 {
cristy4e1dff62009-10-25 20:36:03 +0000533 if (coder_semaphore == (SemaphoreInfo *) NULL)
534 AcquireSemaphoreInfo(&coder_semaphore);
cristyf84a1932010-01-03 18:00:18 +0000535 LockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000536 if ((coder_list == (SplayTreeInfo *) NULL) &&
537 (instantiate_coder == MagickFalse))
538 {
539 (void) LoadCoderLists(MagickCoderFilename,exception);
540 instantiate_coder=MagickTrue;
541 }
cristyf84a1932010-01-03 18:00:18 +0000542 UnlockSemaphoreInfo(coder_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000543 }
544 return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
545}
546
547/*
548%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549% %
550% %
551% %
552% L i s t C o d e r I n f o %
553% %
554% %
555% %
556%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557%
558% ListCoderInfo() lists the coder info to a file.
559%
560% The format of the ListCoderInfo coder is:
561%
562% MagickBooleanType ListCoderInfo(FILE *file,ExceptionInfo *exception)
563%
564% A description of each parameter follows.
565%
566% o file: An pointer to a FILE.
567%
568% o exception: return any errors or warnings in this structure.
569%
570*/
571MagickExport MagickBooleanType ListCoderInfo(FILE *file,
572 ExceptionInfo *exception)
573{
574 const char
575 *path;
576
577 const CoderInfo
578 **coder_info;
579
cristybb503372010-05-27 20:51:26 +0000580 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000581 j;
582
cristybb503372010-05-27 20:51:26 +0000583 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000584 i;
585
cristybb503372010-05-27 20:51:26 +0000586 size_t
cristy3ed852e2009-09-05 21:47:34 +0000587 number_coders;
588
589 if (file == (const FILE *) NULL)
590 file=stdout;
591 coder_info=GetCoderInfoList("*",&number_coders,exception);
592 if (coder_info == (const CoderInfo **) NULL)
593 return(MagickFalse);
594 path=(const char *) NULL;
cristybb503372010-05-27 20:51:26 +0000595 for (i=0; i < (ssize_t) number_coders; i++)
cristy3ed852e2009-09-05 21:47:34 +0000596 {
597 if (coder_info[i]->stealth != MagickFalse)
598 continue;
599 if ((path == (const char *) NULL) ||
600 (LocaleCompare(path,coder_info[i]->path) != 0))
601 {
602 if (coder_info[i]->path != (char *) NULL)
603 (void) fprintf(file,"\nPath: %s\n\n",coder_info[i]->path);
604 (void) fprintf(file,"Magick Coder\n");
605 (void) fprintf(file,"-------------------------------------------------"
606 "------------------------------\n");
607 }
608 path=coder_info[i]->path;
609 (void) fprintf(file,"%s",coder_info[i]->magick);
cristybb503372010-05-27 20:51:26 +0000610 for (j=(ssize_t) strlen(coder_info[i]->magick); j <= 11; j++)
cristy3ed852e2009-09-05 21:47:34 +0000611 (void) fprintf(file," ");
612 if (coder_info[i]->name != (char *) NULL)
613 (void) fprintf(file,"%s",coder_info[i]->name);
614 (void) fprintf(file,"\n");
615 }
616 coder_info=(const CoderInfo **) RelinquishMagickMemory((void *) coder_info);
617 (void) fflush(file);
618 return(MagickTrue);
619}
620
621/*
622%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623% %
624% %
625% %
626+ L o a d C o d e r L i s t %
627% %
628% %
629% %
630%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631%
632% LoadCoderList() loads the coder configuration file which provides a
633% mapping between coder attributes and a coder name.
634%
635% The format of the LoadCoderList coder is:
636%
637% MagickBooleanType LoadCoderList(const char *xml,const char *filename,
cristybb503372010-05-27 20:51:26 +0000638% const size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000639%
640% A description of each parameter follows:
641%
642% o xml: The coder list in XML format.
643%
644% o filename: The coder list filename.
645%
646% o depth: depth of <include /> statements.
647%
648% o exception: return any errors or warnings in this structure.
649%
650*/
651
652static void *DestroyCoderNode(void *coder_info)
653{
654 register CoderInfo
655 *p;
656
657 p=(CoderInfo *) coder_info;
cristye3e77a12009-10-16 00:47:21 +0000658 if (p->exempt == MagickFalse)
659 {
660 if (p->path != (char *) NULL)
661 p->path=DestroyString(p->path);
662 if (p->name != (char *) NULL)
663 p->name=DestroyString(p->name);
664 if (p->magick != (char *) NULL)
665 p->magick=DestroyString(p->magick);
666 }
cristy3ed852e2009-09-05 21:47:34 +0000667 return(RelinquishMagickMemory(p));
668}
669
670static MagickBooleanType LoadCoderList(const char *xml,const char *filename,
cristybb503372010-05-27 20:51:26 +0000671 const size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000672{
673 char
674 keyword[MaxTextExtent],
675 *token;
676
677 const char
678 *q;
679
680 CoderInfo
681 *coder_info;
682
683 MagickBooleanType
684 status;
685
686 /*
687 Load the coder map file.
688 */
689 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
690 "Loading coder configuration file \"%s\" ...",filename);
691 if (xml == (const char *) NULL)
692 return(MagickFalse);
693 if (coder_list == (SplayTreeInfo *) NULL)
694 {
695 coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
696 DestroyCoderNode);
697 if (coder_list == (SplayTreeInfo *) NULL)
698 {
699 ThrowFileException(exception,ResourceLimitError,
700 "MemoryAllocationFailed",filename);
701 return(MagickFalse);
702 }
703 }
704 status=MagickTrue;
705 coder_info=(CoderInfo *) NULL;
706 token=AcquireString(xml);
707 for (q=(char *) xml; *q != '\0'; )
708 {
709 /*
710 Interpret XML.
711 */
712 GetMagickToken(q,&q,token);
713 if (*token == '\0')
714 break;
715 (void) CopyMagickString(keyword,token,MaxTextExtent);
716 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
717 {
718 /*
719 Doctype element.
720 */
721 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
722 GetMagickToken(q,&q,token);
723 continue;
724 }
725 if (LocaleNCompare(keyword,"<!--",4) == 0)
726 {
727 /*
728 Comment element.
729 */
730 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
731 GetMagickToken(q,&q,token);
732 continue;
733 }
734 if (LocaleCompare(keyword,"<include") == 0)
735 {
736 /*
737 Include element.
738 */
739 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
740 {
741 (void) CopyMagickString(keyword,token,MaxTextExtent);
742 GetMagickToken(q,&q,token);
743 if (*token != '=')
744 continue;
745 GetMagickToken(q,&q,token);
746 if (LocaleCompare(keyword,"file") == 0)
747 {
748 if (depth > 200)
749 (void) ThrowMagickException(exception,GetMagickModule(),
750 ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
751 else
752 {
753 char
754 path[MaxTextExtent],
755 *xml;
756
757 GetPathComponent(filename,HeadPath,path);
758 if (*path != '\0')
759 (void) ConcatenateMagickString(path,DirectorySeparator,
760 MaxTextExtent);
761 if (*token == *DirectorySeparator)
762 (void) CopyMagickString(path,token,MaxTextExtent);
763 else
764 (void) ConcatenateMagickString(path,token,MaxTextExtent);
765 xml=FileToString(path,~0,exception);
766 if (xml != (char *) NULL)
767 {
768 status=LoadCoderList(xml,path,depth+1,exception);
769 xml=(char *) RelinquishMagickMemory(xml);
770 }
771 }
772 }
773 }
774 continue;
775 }
776 if (LocaleCompare(keyword,"<coder") == 0)
777 {
778 /*
779 Coder element.
780 */
cristy90823212009-12-12 20:48:33 +0000781 coder_info=(CoderInfo *) AcquireAlignedMemory(1,sizeof(*coder_info));
cristy3ed852e2009-09-05 21:47:34 +0000782 if (coder_info == (CoderInfo *) NULL)
783 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
784 (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
785 coder_info->path=ConstantString(filename);
cristye3e77a12009-10-16 00:47:21 +0000786 coder_info->exempt=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000787 coder_info->signature=MagickSignature;
788 continue;
789 }
790 if (coder_info == (CoderInfo *) NULL)
791 continue;
792 if (LocaleCompare(keyword,"/>") == 0)
793 {
794 status=AddValueToSplayTree(coder_list,ConstantString(
795 coder_info->magick),coder_info);
796 if (status == MagickFalse)
797 (void) ThrowMagickException(exception,GetMagickModule(),
798 ResourceLimitError,"MemoryAllocationFailed","`%s'",
799 coder_info->magick);
800 coder_info=(CoderInfo *) NULL;
801 }
802 GetMagickToken(q,(const char **) NULL,token);
803 if (*token != '=')
804 continue;
805 GetMagickToken(q,&q,token);
806 GetMagickToken(q,&q,token);
807 switch (*keyword)
808 {
809 case 'M':
810 case 'm':
811 {
812 if (LocaleCompare((char *) keyword,"magick") == 0)
813 {
814 coder_info->magick=ConstantString(token);
815 break;
816 }
817 break;
818 }
819 case 'N':
820 case 'n':
821 {
822 if (LocaleCompare((char *) keyword,"name") == 0)
823 {
824 coder_info->name=ConstantString(token);
825 break;
826 }
827 break;
828 }
829 case 'S':
830 case 's':
831 {
832 if (LocaleCompare((char *) keyword,"stealth") == 0)
833 {
834 coder_info->stealth=IsMagickTrue(token);
835 break;
836 }
837 break;
838 }
839 default:
840 break;
841 }
842 }
843 token=(char *) RelinquishMagickMemory(token);
844 return(status);
845}
846
847/*
848%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
849% %
850% %
851% %
852% L o a d C o d e r L i s t s %
853% %
854% %
855% %
856%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857%
858% LoadCoderLists() loads one or more coder configuration file which
859% provides a mapping between coder attributes and a coder name.
860%
861% The format of the LoadCoderLists coder is:
862%
863% MagickBooleanType LoadCoderLists(const char *filename,
864% ExceptionInfo *exception)
865%
866% A description of each parameter follows:
867%
868% o filename: the font file name.
869%
870% o exception: return any errors or warnings in this structure.
871%
872*/
873static MagickBooleanType LoadCoderLists(const char *filename,
874 ExceptionInfo *exception)
875{
cristy3ed852e2009-09-05 21:47:34 +0000876 const StringInfo
877 *option;
878
879 LinkedListInfo
880 *options;
881
882 MagickStatusType
883 status;
884
cristybb503372010-05-27 20:51:26 +0000885 register ssize_t
cristy54a531d2009-10-21 17:58:01 +0000886 i;
cristye3e77a12009-10-16 00:47:21 +0000887
888 /*
889 Load built-in coder map.
890 */
cristy3ed852e2009-09-05 21:47:34 +0000891 status=MagickFalse;
cristye3e77a12009-10-16 00:47:21 +0000892 if (coder_list == (SplayTreeInfo *) NULL)
893 {
894 coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
895 DestroyCoderNode);
896 if (coder_list == (SplayTreeInfo *) NULL)
897 {
898 ThrowFileException(exception,ResourceLimitError,
899 "MemoryAllocationFailed",filename);
900 return(MagickFalse);
901 }
902 }
cristybb503372010-05-27 20:51:26 +0000903 for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++)
cristye3e77a12009-10-16 00:47:21 +0000904 {
905 CoderInfo
906 *coder_info;
907
cristy54a531d2009-10-21 17:58:01 +0000908 register const CoderMapInfo
909 *p;
910
911 p=CoderMap+i;
cristy90823212009-12-12 20:48:33 +0000912 coder_info=(CoderInfo *) AcquireAlignedMemory(1,sizeof(*coder_info));
cristye3e77a12009-10-16 00:47:21 +0000913 if (coder_info == (CoderInfo *) NULL)
914 {
915 (void) ThrowMagickException(exception,GetMagickModule(),
916 ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
917 continue;
918 }
919 (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
cristy38b8ed92009-10-16 01:20:21 +0000920 coder_info->path=(char *) "[built-in]";
cristye3e77a12009-10-16 00:47:21 +0000921 coder_info->magick=(char *) p->magick;
922 coder_info->name=(char *) p->name;
923 coder_info->exempt=MagickTrue;
924 coder_info->signature=MagickSignature;
925 status=AddValueToSplayTree(coder_list,ConstantString(coder_info->magick),
926 coder_info);
927 if (status == MagickFalse)
928 (void) ThrowMagickException(exception,GetMagickModule(),
929 ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
930 }
931 /*
932 Load external coder map.
933 */
cristy3ed852e2009-09-05 21:47:34 +0000934 options=GetConfigureOptions(filename,exception);
935 option=(const StringInfo *) GetNextValueInLinkedList(options);
936 while (option != (const StringInfo *) NULL)
937 {
938 status|=LoadCoderList((const char *) GetStringInfoDatum(option),
939 GetStringInfoPath(option),0,exception);
940 option=(const StringInfo *) GetNextValueInLinkedList(options);
941 }
942 options=DestroyConfigureOptions(options);
cristy3ed852e2009-09-05 21:47:34 +0000943 return(status != 0 ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +0000944}