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