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