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