MagickCore 6.9.13
Loading...
Searching...
No Matches
coder.c
1/*
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% Cristy %
17% May 2001 %
18% %
19% %
20% Copyright 1999 ImageMagick Studio LLC, a non-profit organization %
21% 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% https://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#include "magick/xml-tree-private.h"
61
62/*
63 Define declarations.
64*/
65#define MagickCoderFilename "coder.xml"
66
67/*
68 Typedef declarations.
69*/
70typedef struct _CoderMapInfo
71{
72 const char
73 *magick,
74 *name;
76
77/*
78 Static declarations.
79*/
80static const CoderMapInfo
81 CoderMap[] =
82 {
83 { "3FR", "DNG" },
84 { "3GP", "VIDEO" },
85 { "3G2", "VIDEO" },
86 { "8BIM", "META" },
87 { "8BIMTEXT", "META" },
88 { "8BIMWTEXT", "META" },
89 { "AFM", "TTF" },
90 { "A", "RAW" },
91 { "AI", "PDF" },
92 { "APNG", "VIDEO" },
93 { "APP1JPEG", "META" },
94 { "APP1", "META" },
95 { "ARW", "DNG" },
96 { "AVI", "VIDEO" },
97 { "AVIF", "HEIC" },
98 { "BIE", "JBIG" },
99 { "BMP2", "BMP" },
100 { "BMP3", "BMP" },
101 { "B", "RAW" },
102 { "BRF", "BRAILLE" },
103 { "BGRA", "BGR" },
104 { "BGRO", "BGR" },
105 { "CMYKA", "CMYK" },
106 { "C", "RAW" },
107 { "CAL", "CALS" },
108 { "CANVAS", "XC" },
109 { "CMYKA", "CMYK" },
110 { "CR2", "DNG" },
111 { "CR3", "DNG" },
112 { "CRW", "DNG" },
113 { "CUR", "ICON" },
114 { "DATA", "INLINE" },
115 { "DCR", "DNG" },
116 { "DCX", "PCX" },
117 { "DFONT", "TTF" },
118 { "DXT1", "DDS" },
119 { "DXT5", "DDS" },
120 { "EPDF", "PDF" },
121 { "EPI", "PS" },
122 { "EPS2", "PS2" },
123 { "EPS3", "PS3" },
124 { "EPSF", "PS" },
125 { "EPSI", "PS" },
126 { "EPS", "PS" },
127 { "EPT2", "EPT" },
128 { "EPT3", "EPT" },
129 { "ERF", "DNG" },
130 { "EXIF", "META" },
131 { "FILE", "URL" },
132 { "FRACTAL", "PLASMA" },
133 { "FTP", "URL" },
134 { "FTS", "FITS" },
135 { "G3", "FAX" },
136 { "G4", "FAX" },
137 { "GIF87", "GIF" },
138 { "G", "RAW" },
139 { "GRANITE", "MAGICK" },
140 { "GRAYA", "GRAY" },
141 { "GROUP4", "TIFF" },
142 { "GV", "DOT" },
143 { "HTM", "HTML" },
144 { "ICB", "TGA" },
145 { "ICO", "ICON" },
146 { "ICODIB", "DIB" },
147 { "IIQ", "DNG" },
148 { "K25", "DNG" },
149 { "KDC", "DNG" },
150 { "H", "MAGICK" },
151 { "HTM", "HTML" },
152 { "HTTP", "URL" },
153 { "HTTPS", "URL" },
154 { "ICB", "TGA" },
155 { "ICC", "META" },
156 { "ICM", "META" },
157 { "ICO", "ICON" },
158 { "IMPLICIT", "***" },
159 { "IPTC", "META" },
160 { "IPTCTEXT", "META" },
161 { "IPTCWTEXT", "META" },
162 { "ISOBRL", "BRAILLE" },
163 { "ISOBRL6", "BRAILLE" },
164 { "JBG", "JBIG" },
165 { "JNG", "PNG" },
166 { "JPC", "JP2" },
167 { "JPT", "JP2" },
168 { "JPM", "JP2" },
169 { "J2C", "JP2" },
170 { "J2K", "JP2" },
171 { "JNG", "PNG" },
172 { "JPE", "JPEG" },
173 { "JPG", "JPEG" },
174 { "JPM", "JP2" },
175 { "JPS", "JPEG" },
176 { "JPT", "JP2" },
177 { "JPX", "JP2" },
178 { "K", "RAW" },
179 { "K25", "DNG" },
180 { "KDC", "DNG" },
181 { "LOGO", "MAGICK" },
182 { "M", "RAW" },
183 { "M2V", "VIDEO" },
184 { "M4V", "VIDEO" },
185 { "MEF", "DNG" },
186 { "MKV", "VIDEO" },
187 { "MNG", "PNG" },
188 { "MOV", "VIDEO" },
189 { "MP4", "VIDEO" },
190 { "MPEG", "VIDEO" },
191 { "MPG", "VIDEO" },
192 { "MPRI", "MPR" },
193 { "MEF", "DNG" },
194 { "MRW", "DNG" },
195 { "MSVG", "SVG" },
196 { "NEF", "DNG" },
197 { "NETSCAPE", "MAGICK" },
198 { "NRW", "DNG" },
199 { "O", "RAW" },
200 { "ORF", "DNG" },
201 { "OTF", "TTF" },
202 { "P7", "PNM" },
203 { "PAL", "UYVY" },
204 { "PAM", "PNM" },
205 { "PBM", "PNM" },
206 { "PCDS", "PCD" },
207 { "PCT", "PICT" },
208 { "PDFA", "PDF" },
209 { "PEF", "DNG" },
210 { "PEF", "DNG" },
211 { "PFA", "TTF" },
212 { "PFB", "TTF" },
213 { "PFM", "PNM" },
214 { "PGM", "PNM" },
215 { "PICON", "XPM" },
216 { "PJPEG", "JPEG" },
217 { "PM", "XPM" },
218 { "PNG00", "PNG" },
219 { "PNG24", "PNG" },
220 { "PNG32", "PNG" },
221 { "PNG48", "PNG" },
222 { "PNG64", "PNG" },
223 { "PNG8", "PNG" },
224 { "PPM", "PNM" },
225 { "PSB", "PSD" },
226 { "PTIF", "TIFF" },
227 { "R", "RAW" },
228 { "RADIAL-GRADIENT", "GRADIENT" },
229 { "RAF", "DNG" },
230 { "RAS", "SUN" },
231 { "RAW", "DNG" },
232 { "RGBA", "RGB" },
233 { "RGBO", "RGB" },
234 { "RMF", "DNG" },
235 { "ROSE", "MAGICK" },
236 { "RW2", "DNG" },
237 { "SHTML", "HTML" },
238 { "SIX", "SIXEL" },
239 { "SPARSE-COLOR", "TXT" },
240 { "SR2", "DNG" },
241 { "SRF", "DNG" },
242 { "SVGZ", "SVG" },
243 { "TEXT", "TXT" },
244 { "TIFF64", "TIFF" },
245 { "TIF", "TIFF" },
246 { "TTC", "TTF" },
247 { "UBRL", "BRAILLE" },
248 { "UBRL6", "BRAILLE" },
249 { "VDA", "TGA" },
250 { "VST", "TGA" },
251 { "WEBM", "VIDEO" },
252 { "WIZARD", "MAGICK" },
253#if defined(MAGICKCORE_WINGDI32_DELEGATE)
254 { "WMF", "EMF" },
255#endif
256 { "WMV", "VIDEO" },
257 { "WMZ", "WMF" },
258 { "X3f", "DNG" },
259 { "XMP", "META" },
260 { "XV", "VIFF" },
261 { "Y", "RAW" },
262 { "YCbCrA", "YCbCr" }
263 };
264
265static SemaphoreInfo
266 *coder_semaphore = (SemaphoreInfo *) NULL;
267
268static SplayTreeInfo
269 *coder_cache = (SplayTreeInfo *) NULL;
270
271/*
272 Forward declarations.
273*/
274static MagickBooleanType
275 IsCoderTreeInstantiated(ExceptionInfo *);
276
277#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
278static MagickBooleanType
279 LoadCoderCache(SplayTreeInfo *,const char *,const char *,const size_t,
280 ExceptionInfo *);
281#endif
282
283/*
284%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285% %
286% %
287% %
288+ A c q u i r e C o d e r C a c h e %
289% %
290% %
291% %
292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293%
294% AcquireCoderCache() caches one or more coder configurations which
295% provides a mapping between coder attributes and a coder name.
296%
297% The format of the AcquireCoderCache coder is:
298%
299% SplayTreeInfo *AcquireCoderCache(const char *filename,
300% ExceptionInfo *exception)
301%
302% A description of each parameter follows:
303%
304% o filename: the font file name.
305%
306% o exception: return any errors or warnings in this structure.
307%
308*/
309
310static void *DestroyCoderNode(void *coder_info)
311{
313 *p;
314
315 p=(CoderInfo *) coder_info;
316 if (p->exempt == MagickFalse)
317 {
318 if (p->path != (char *) NULL)
319 p->path=DestroyString(p->path);
320 if (p->name != (char *) NULL)
321 p->name=DestroyString(p->name);
322 if (p->magick != (char *) NULL)
323 p->magick=DestroyString(p->magick);
324 }
325 return(RelinquishMagickMemory(p));
326}
327
328static SplayTreeInfo *AcquireCoderCache(const char *filename,
329 ExceptionInfo *exception)
330{
331 MagickStatusType
332 status;
333
334 ssize_t
335 i;
336
338 *cache;
339
340 /*
341 Load external coder map.
342 */
343 cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
344 DestroyCoderNode);
345 if (cache == (SplayTreeInfo *) NULL)
346 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
347 status=MagickTrue;
348#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
349 {
350 const StringInfo
351 *option;
352
354 *options;
355
356 options=GetConfigureOptions(filename,exception);
357 option=(const StringInfo *) GetNextValueInLinkedList(options);
358 while (option != (const StringInfo *) NULL)
359 {
360 status&=LoadCoderCache(cache,(const char *)
361 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
362 option=(const StringInfo *) GetNextValueInLinkedList(options);
363 }
364 options=DestroyConfigureOptions(options);
365 }
366#endif
367 /*
368 Load built-in coder map.
369 */
370 for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++)
371 {
373 *coder_info;
374
375 const CoderMapInfo
376 *p;
377
378 p=CoderMap+i;
379 coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
380 if (coder_info == (CoderInfo *) NULL)
381 {
382 (void) ThrowMagickException(exception,GetMagickModule(),
383 ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name);
384 continue;
385 }
386 (void) memset(coder_info,0,sizeof(*coder_info));
387 coder_info->path=(char *) "[built-in]";
388 coder_info->magick=(char *) p->magick;
389 coder_info->name=(char *) p->name;
390 coder_info->exempt=MagickTrue;
391 coder_info->signature=MagickCoreSignature;
392 status&=AddValueToSplayTree(cache,ConstantString(coder_info->magick),
393 coder_info);
394 if (status == MagickFalse)
395 (void) ThrowMagickException(exception,GetMagickModule(),
396 ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name);
397 }
398 return(cache);
399}
400
401/*
402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403% %
404% %
405% %
406+ C o d e r C o m p o n e n t G e n e s i s %
407% %
408% %
409% %
410%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411%
412% CoderComponentGenesis() instantiates the coder component.
413%
414% The format of the CoderComponentGenesis method is:
415%
416% MagickBooleanType CoderComponentGenesis(void)
417%
418*/
419MagickExport MagickBooleanType CoderComponentGenesis(void)
420{
421 if (coder_semaphore == (SemaphoreInfo *) NULL)
422 coder_semaphore=AllocateSemaphoreInfo();
423 return(MagickTrue);
424}
425
426/*
427%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428% %
429% %
430% %
431+ C o d e r C o m p o n e n t T e r m i n u s %
432% %
433% %
434% %
435%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436%
437% CoderComponentTerminus() destroys the coder component.
438%
439% The format of the CoderComponentTerminus method is:
440%
441% CoderComponentTerminus(void)
442%
443*/
444MagickExport void CoderComponentTerminus(void)
445{
446 if (coder_semaphore == (SemaphoreInfo *) NULL)
447 ActivateSemaphoreInfo(&coder_semaphore);
448 LockSemaphoreInfo(coder_semaphore);
449 if (coder_cache != (SplayTreeInfo *) NULL)
450 coder_cache=DestroySplayTree(coder_cache);
451 UnlockSemaphoreInfo(coder_semaphore);
452 DestroySemaphoreInfo(&coder_semaphore);
453}
454
455/*
456%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457% %
458% %
459% %
460+ G e t C o d e r I n f o %
461% %
462% %
463% %
464%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465%
466% GetCoderInfo searches the coder list for the specified name and if found
467% returns attributes for that coder.
468%
469% The format of the GetCoderInfo method is:
470%
471% const CoderInfo *GetCoderInfo(const char *name,ExceptionInfo *exception)
472%
473% A description of each parameter follows:
474%
475% o name: the coder name.
476%
477% o exception: return any errors or warnings in this structure.
478%
479*/
480MagickExport const CoderInfo *GetCoderInfo(const char *name,
481 ExceptionInfo *exception)
482{
483 assert(exception != (ExceptionInfo *) NULL);
484 if (IsCoderTreeInstantiated(exception) == MagickFalse)
485 return((const CoderInfo *) NULL);
486 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
487 return((const CoderInfo *) GetRootValueFromSplayTree(coder_cache));
488 return((const CoderInfo *) GetValueFromSplayTree(coder_cache,name));
489}
490
491/*
492%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493% %
494% %
495% %
496% G e t C o d e r I n f o L i s t %
497% %
498% %
499% %
500%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
501%
502% GetCoderInfoList() returns any coder_map that match the specified pattern.
503% The format of the GetCoderInfoList function is:
504%
505% const CoderInfo **GetCoderInfoList(const char *pattern,
506% size_t *number_coders,ExceptionInfo *exception)
507%
508% A description of each parameter follows:
509%
510% o pattern: Specifies a pointer to a text string containing a pattern.
511%
512% o number_coders: This integer returns the number of coders in the list.
513%
514% o exception: return any errors or warnings in this structure.
515%
516*/
517
518static int CoderInfoCompare(const void *x,const void *y)
519{
520 const CoderInfo
521 **p,
522 **q;
523
524 p=(const CoderInfo **) x,
525 q=(const CoderInfo **) y;
526 if (LocaleCompare((*p)->path,(*q)->path) == 0)
527 return(LocaleCompare((*p)->name,(*q)->name));
528 return(LocaleCompare((*p)->path,(*q)->path));
529}
530
531MagickExport const CoderInfo **GetCoderInfoList(const char *pattern,
532 size_t *number_coders,ExceptionInfo *exception)
533{
534 const CoderInfo
535 **coder_map;
536
537 const CoderInfo
538 *p;
539
540 ssize_t
541 i;
542
543 /*
544 Allocate coder list.
545 */
546 assert(pattern != (char *) NULL);
547 assert(number_coders != (size_t *) NULL);
548 if (IsEventLogging() != MagickFalse)
549 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
550 *number_coders=0;
551 p=GetCoderInfo("*",exception);
552 if (p == (const CoderInfo *) NULL)
553 return((const CoderInfo **) NULL);
554 coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t)
555 GetNumberOfNodesInSplayTree(coder_cache)+1UL,sizeof(*coder_map));
556 if (coder_map == (const CoderInfo **) NULL)
557 return((const CoderInfo **) NULL);
558 /*
559 Generate coder list.
560 */
561 LockSemaphoreInfo(coder_semaphore);
562 ResetSplayTreeIterator(coder_cache);
563 p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache);
564 for (i=0; p != (const CoderInfo *) NULL; )
565 {
566 if ((p->stealth == MagickFalse) &&
567 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
568 coder_map[i++]=p;
569 p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache);
570 }
571 UnlockSemaphoreInfo(coder_semaphore);
572 qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare);
573 coder_map[i]=(CoderInfo *) NULL;
574 *number_coders=(size_t) i;
575 return(coder_map);
576}
577
578/*
579%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580% %
581% %
582% %
583% G e t C o d e r L i s t %
584% %
585% %
586% %
587%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588%
589% GetCoderList() returns any coder_map that match the specified pattern.
590%
591% The format of the GetCoderList function is:
592%
593% char **GetCoderList(const char *pattern,size_t *number_coders,
594% ExceptionInfo *exception)
595%
596% A description of each parameter follows:
597%
598% o pattern: Specifies a pointer to a text string containing a pattern.
599%
600% o number_coders: This integer returns the number of coders in the list.
601%
602% o exception: return any errors or warnings in this structure.
603%
604*/
605
606static int CoderCompare(const void *x,const void *y)
607{
608 const char
609 **p,
610 **q;
611
612 p=(const char **) x;
613 q=(const char **) y;
614 return(LocaleCompare(*p,*q));
615}
616
617MagickExport char **GetCoderList(const char *pattern,
618 size_t *number_coders,ExceptionInfo *exception)
619{
620 char
621 **coder_map;
622
623 const CoderInfo
624 *p;
625
626 ssize_t
627 i;
628
629 /*
630 Allocate coder list.
631 */
632 assert(pattern != (char *) NULL);
633 assert(number_coders != (size_t *) NULL);
634 if (IsEventLogging() != MagickFalse)
635 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
636 *number_coders=0;
637 p=GetCoderInfo("*",exception);
638 if (p == (const CoderInfo *) NULL)
639 return((char **) NULL);
640 coder_map=(char **) AcquireQuantumMemory((size_t)
641 GetNumberOfNodesInSplayTree(coder_cache)+1UL,sizeof(*coder_map));
642 if (coder_map == (char **) NULL)
643 return((char **) NULL);
644 /*
645 Generate coder list.
646 */
647 LockSemaphoreInfo(coder_semaphore);
648 ResetSplayTreeIterator(coder_cache);
649 p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache);
650 for (i=0; p != (const CoderInfo *) NULL; )
651 {
652 if ((p->stealth == MagickFalse) &&
653 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
654 coder_map[i++]=ConstantString(p->name);
655 p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache);
656 }
657 UnlockSemaphoreInfo(coder_semaphore);
658 qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare);
659 coder_map[i]=(char *) NULL;
660 *number_coders=(size_t) i;
661 return(coder_map);
662}
663
664/*
665%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666% %
667% %
668% %
669+ I s C o d e r T r e e I n s t a n t i a t e d %
670% %
671% %
672% %
673%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674%
675% IsCoderTreeInstantiated() determines if the coder tree is instantiated. If
676% not, it instantiates the tree and returns it.
677%
678% The format of the IsCoderInstantiated method is:
679%
680% MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception)
681%
682% A description of each parameter follows.
683%
684% o exception: return any errors or warnings in this structure.
685%
686*/
687static MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception)
688{
689 if (coder_cache == (SplayTreeInfo *) NULL)
690 {
691 if (coder_semaphore == (SemaphoreInfo *) NULL)
692 ActivateSemaphoreInfo(&coder_semaphore);
693 LockSemaphoreInfo(coder_semaphore);
694 if (coder_cache == (SplayTreeInfo *) NULL)
695 coder_cache=AcquireCoderCache(MagickCoderFilename,exception);
696 UnlockSemaphoreInfo(coder_semaphore);
697 }
698 return(coder_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
699}
700
701/*
702%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703% %
704% %
705% %
706% L i s t C o d e r I n f o %
707% %
708% %
709% %
710%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
711%
712% ListCoderInfo() lists the coder info to a file.
713%
714% The format of the ListCoderInfo coder is:
715%
716% MagickBooleanType ListCoderInfo(FILE *file,ExceptionInfo *exception)
717%
718% A description of each parameter follows.
719%
720% o file: An pointer to a FILE.
721%
722% o exception: return any errors or warnings in this structure.
723%
724*/
725MagickExport MagickBooleanType ListCoderInfo(FILE *file,
726 ExceptionInfo *exception)
727{
728 const char
729 *path;
730
731 const CoderInfo
732 **coder_info;
733
734 ssize_t
735 i;
736
737 size_t
738 number_coders;
739
740 ssize_t
741 j;
742
743 if (file == (const FILE *) NULL)
744 file=stdout;
745 coder_info=GetCoderInfoList("*",&number_coders,exception);
746 if (coder_info == (const CoderInfo **) NULL)
747 return(MagickFalse);
748 path=(const char *) NULL;
749 for (i=0; i < (ssize_t) number_coders; i++)
750 {
751 if (coder_info[i]->stealth != MagickFalse)
752 continue;
753 if ((path == (const char *) NULL) ||
754 (LocaleCompare(path,coder_info[i]->path) != 0))
755 {
756 if (coder_info[i]->path != (char *) NULL)
757 (void) FormatLocaleFile(file,"\nPath: %s\n\n",coder_info[i]->path);
758 (void) FormatLocaleFile(file,"Magick Coder\n");
759 (void) FormatLocaleFile(file,
760 "-------------------------------------------------"
761 "------------------------------\n");
762 }
763 path=coder_info[i]->path;
764 (void) FormatLocaleFile(file,"%s",coder_info[i]->magick);
765 for (j=(ssize_t) strlen(coder_info[i]->magick); j <= 11; j++)
766 (void) FormatLocaleFile(file," ");
767 if (coder_info[i]->name != (char *) NULL)
768 (void) FormatLocaleFile(file,"%s",coder_info[i]->name);
769 (void) FormatLocaleFile(file,"\n");
770 }
771 coder_info=(const CoderInfo **) RelinquishMagickMemory((void *) coder_info);
772 (void) fflush(file);
773 return(MagickTrue);
774}
775
776#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
777/*
778%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
779% %
780% %
781% %
782+ L o a d C o d e r C a c h e %
783% %
784% %
785% %
786%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
787%
788% LoadCoderCache() loads the coder configurations which provides a
789% mapping between coder attributes and a coder name.
790%
791% The format of the LoadCoderCache coder is:
792%
793% MagickBooleanType LoadCoderCache(SplayTreeInfo *cache,const char *xml,
794% const char *filename,const size_t depth,ExceptionInfo *exception)
795%
796% A description of each parameter follows:
797%
798% o xml: The coder list in XML format.
799%
800% o filename: The coder list filename.
801%
802% o depth: depth of <include /> statements.
803%
804% o exception: return any errors or warnings in this structure.
805%
806*/
807static MagickBooleanType LoadCoderCache(SplayTreeInfo *cache,const char *xml,
808 const char *filename,const size_t depth,ExceptionInfo *exception)
809{
810 char
811 keyword[MaxTextExtent],
812 *token;
813
814 const char
815 *q;
816
818 *coder_info;
819
820 MagickStatusType
821 status;
822
823 size_t
824 extent;
825
826 /*
827 Load the coder map file.
828 */
829 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
830 "Loading coder configuration file \"%s\" ...",filename);
831 if (xml == (const char *) NULL)
832 return(MagickFalse);
833 status=MagickTrue;
834 coder_info=(CoderInfo *) NULL;
835 token=AcquireString(xml);
836 extent=strlen(token)+MaxTextExtent;
837 for (q=(char *) xml; *q != '\0'; )
838 {
839 /*
840 Interpret XML.
841 */
842 (void) GetNextToken(q,&q,extent,token);
843 if (*token == '\0')
844 break;
845 (void) CopyMagickString(keyword,token,MaxTextExtent);
846 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
847 {
848 /*
849 Doctype element.
850 */
851 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
852 (void) GetNextToken(q,&q,extent,token);
853 continue;
854 }
855 if (LocaleNCompare(keyword,"<!--",4) == 0)
856 {
857 /*
858 Comment element.
859 */
860 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
861 (void) GetNextToken(q,&q,extent,token);
862 continue;
863 }
864 if (LocaleCompare(keyword,"<include") == 0)
865 {
866 /*
867 Include element.
868 */
869 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
870 {
871 (void) CopyMagickString(keyword,token,MaxTextExtent);
872 (void) GetNextToken(q,&q,extent,token);
873 if (*token != '=')
874 continue;
875 (void) GetNextToken(q,&q,extent,token);
876 if (LocaleCompare(keyword,"file") == 0)
877 {
878 if (depth > MagickMaxRecursionDepth)
879 (void) ThrowMagickException(exception,GetMagickModule(),
880 ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
881 else
882 {
883 char
884 path[MaxTextExtent],
885 *xml;
886
887 GetPathComponent(filename,HeadPath,path);
888 if (*path != '\0')
889 (void) ConcatenateMagickString(path,DirectorySeparator,
890 MaxTextExtent);
891 if (*token == *DirectorySeparator)
892 (void) CopyMagickString(path,token,MaxTextExtent);
893 else
894 (void) ConcatenateMagickString(path,token,MaxTextExtent);
895 xml=FileToXML(path,~0UL);
896 if (xml != (char *) NULL)
897 {
898 status&=LoadCoderCache(cache,xml,path,depth+1,
899 exception);
900 xml=(char *) RelinquishMagickMemory(xml);
901 }
902 }
903 }
904 }
905 continue;
906 }
907 if (LocaleCompare(keyword,"<coder") == 0)
908 {
909 /*
910 Coder element.
911 */
912 coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
913 if (coder_info == (CoderInfo *) NULL)
914 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
915 (void) memset(coder_info,0,sizeof(*coder_info));
916 coder_info->path=ConstantString(filename);
917 coder_info->exempt=MagickFalse;
918 coder_info->signature=MagickCoreSignature;
919 continue;
920 }
921 if (coder_info == (CoderInfo *) NULL)
922 continue;
923 if ((LocaleCompare(keyword,"/>") == 0) ||
924 (LocaleCompare(keyword,"</policy>") == 0))
925 {
926 status=AddValueToSplayTree(cache,ConstantString(
927 coder_info->magick),coder_info);
928 if (status == MagickFalse)
929 (void) ThrowMagickException(exception,GetMagickModule(),
930 ResourceLimitError,"MemoryAllocationFailed","`%s'",
931 coder_info->magick);
932 coder_info=(CoderInfo *) NULL;
933 continue;
934 }
935 (void) GetNextToken(q,(const char **) NULL,extent,token);
936 if (*token != '=')
937 continue;
938 (void) GetNextToken(q,&q,extent,token);
939 (void) GetNextToken(q,&q,extent,token);
940 switch (*keyword)
941 {
942 case 'M':
943 case 'm':
944 {
945 if (LocaleCompare((char *) keyword,"magick") == 0)
946 {
947 coder_info->magick=ConstantString(token);
948 break;
949 }
950 break;
951 }
952 case 'N':
953 case 'n':
954 {
955 if (LocaleCompare((char *) keyword,"name") == 0)
956 {
957 coder_info->name=ConstantString(token);
958 break;
959 }
960 break;
961 }
962 case 'S':
963 case 's':
964 {
965 if (LocaleCompare((char *) keyword,"stealth") == 0)
966 {
967 coder_info->stealth=IsMagickTrue(token);
968 break;
969 }
970 break;
971 }
972 default:
973 break;
974 }
975 }
976 token=(char *) RelinquishMagickMemory(token);
977 return(status != 0 ? MagickTrue : MagickFalse);
978}
979#endif