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 | { |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame^] | 327 | const CoderInfo |
| 328 | *coder_info; |
| 329 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | assert(exception != (ExceptionInfo *) NULL); |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 331 | if (IsCoderTreeInstantiated(exception) == MagickFalse) |
| 332 | return((const CoderInfo *) NULL); |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame^] | 333 | LockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) |
| 335 | { |
| 336 | ResetSplayTreeIterator(coder_list); |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame^] | 337 | coder_info=(const CoderInfo *) GetNextValueInSplayTree(coder_list); |
| 338 | UnlockSemaphoreInfo(coder_semaphore); |
| 339 | return(coder_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 340 | } |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame^] | 341 | coder_info=(const CoderInfo *) GetValueFromSplayTree(coder_list,name); |
| 342 | UnlockSemaphoreInfo(coder_semaphore); |
| 343 | return(coder_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* |
| 347 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 348 | % % |
| 349 | % % |
| 350 | % % |
| 351 | % G e t C o d e r I n f o L i s t % |
| 352 | % % |
| 353 | % % |
| 354 | % % |
| 355 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 356 | % |
| 357 | % GetCoderInfoList() returns any coder_map that match the specified pattern. |
| 358 | % The format of the GetCoderInfoList function is: |
| 359 | % |
| 360 | % const CoderInfo **GetCoderInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 361 | % size_t *number_coders,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 362 | % |
| 363 | % A description of each parameter follows: |
| 364 | % |
| 365 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 366 | % |
| 367 | % o number_coders: This integer returns the number of coders in the list. |
| 368 | % |
| 369 | % o exception: return any errors or warnings in this structure. |
| 370 | % |
| 371 | */ |
| 372 | |
| 373 | static int CoderInfoCompare(const void *x,const void *y) |
| 374 | { |
| 375 | const CoderInfo |
| 376 | **p, |
| 377 | **q; |
| 378 | |
| 379 | p=(const CoderInfo **) x, |
| 380 | q=(const CoderInfo **) y; |
| 381 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 382 | return(LocaleCompare((*p)->name,(*q)->name)); |
| 383 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 384 | } |
| 385 | |
| 386 | MagickExport const CoderInfo **GetCoderInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 387 | size_t *number_coders,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | { |
| 389 | const CoderInfo |
| 390 | **coder_map; |
| 391 | |
| 392 | register const CoderInfo |
| 393 | *p; |
| 394 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 395 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 396 | i; |
| 397 | |
| 398 | /* |
| 399 | Allocate coder list. |
| 400 | */ |
| 401 | assert(pattern != (char *) NULL); |
| 402 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 403 | assert(number_coders != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | *number_coders=0; |
| 405 | p=GetCoderInfo("*",exception); |
| 406 | if (p == (const CoderInfo *) NULL) |
| 407 | return((const CoderInfo **) NULL); |
| 408 | coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t) |
| 409 | GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map)); |
| 410 | if (coder_map == (const CoderInfo **) NULL) |
| 411 | return((const CoderInfo **) NULL); |
| 412 | /* |
| 413 | Generate coder list. |
| 414 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 415 | LockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 416 | ResetSplayTreeIterator(coder_list); |
| 417 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); |
| 418 | for (i=0; p != (const CoderInfo *) NULL; ) |
| 419 | { |
| 420 | if ((p->stealth == MagickFalse) && |
| 421 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 422 | coder_map[i++]=p; |
| 423 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); |
| 424 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 425 | UnlockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 426 | qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare); |
| 427 | coder_map[i]=(CoderInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 428 | *number_coders=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 429 | return(coder_map); |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 434 | % % |
| 435 | % % |
| 436 | % % |
| 437 | % G e t C o d e r L i s t % |
| 438 | % % |
| 439 | % % |
| 440 | % % |
| 441 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 442 | % |
| 443 | % GetCoderList() returns any coder_map that match the specified pattern. |
| 444 | % |
| 445 | % The format of the GetCoderList function is: |
| 446 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 447 | % char **GetCoderList(const char *pattern,size_t *number_coders, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | % ExceptionInfo *exception) |
| 449 | % |
| 450 | % A description of each parameter follows: |
| 451 | % |
| 452 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 453 | % |
| 454 | % o number_coders: This integer returns the number of coders in the list. |
| 455 | % |
| 456 | % o exception: return any errors or warnings in this structure. |
| 457 | % |
| 458 | */ |
| 459 | |
| 460 | static int CoderCompare(const void *x,const void *y) |
| 461 | { |
| 462 | register const char |
| 463 | **p, |
| 464 | **q; |
| 465 | |
| 466 | p=(const char **) x; |
| 467 | q=(const char **) y; |
| 468 | return(LocaleCompare(*p,*q)); |
| 469 | } |
| 470 | |
| 471 | MagickExport char **GetCoderList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 472 | size_t *number_coders,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | { |
| 474 | char |
| 475 | **coder_map; |
| 476 | |
| 477 | register const CoderInfo |
| 478 | *p; |
| 479 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 480 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | i; |
| 482 | |
| 483 | /* |
| 484 | Allocate coder list. |
| 485 | */ |
| 486 | assert(pattern != (char *) NULL); |
| 487 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 488 | assert(number_coders != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | *number_coders=0; |
| 490 | p=GetCoderInfo("*",exception); |
| 491 | if (p == (const CoderInfo *) NULL) |
| 492 | return((char **) NULL); |
| 493 | coder_map=(char **) AcquireQuantumMemory((size_t) |
| 494 | GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map)); |
| 495 | if (coder_map == (char **) NULL) |
| 496 | return((char **) NULL); |
| 497 | /* |
| 498 | Generate coder list. |
| 499 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 500 | LockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 501 | ResetSplayTreeIterator(coder_list); |
| 502 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); |
| 503 | for (i=0; p != (const CoderInfo *) NULL; ) |
| 504 | { |
| 505 | if ((p->stealth == MagickFalse) && |
| 506 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 507 | coder_map[i++]=ConstantString(p->name); |
| 508 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); |
| 509 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 510 | UnlockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 511 | qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare); |
| 512 | coder_map[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 513 | *number_coders=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 514 | return(coder_map); |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 519 | % % |
| 520 | % % |
| 521 | % % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 522 | + 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] | 523 | % % |
| 524 | % % |
| 525 | % % |
| 526 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 527 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 528 | % IsCoderTreeInstantiated() determines if the coder tree is instantiated. |
| 529 | % If not, it instantiates the tree and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 530 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 531 | % The format of the IsCoderInstantiated method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 532 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 533 | % MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | % |
| 535 | % A description of each parameter follows. |
| 536 | % |
| 537 | % o exception: return any errors or warnings in this structure. |
| 538 | % |
| 539 | */ |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 540 | static MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 541 | { |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 542 | if (coder_semaphore == (SemaphoreInfo *) NULL) |
| 543 | ActivateSemaphoreInfo(&coder_semaphore); |
| 544 | LockSemaphoreInfo(coder_semaphore); |
| 545 | if (coder_list == (SplayTreeInfo *) NULL) |
| 546 | (void) LoadCoderLists(MagickCoderFilename,exception); |
| 547 | UnlockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 548 | return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 553 | % % |
| 554 | % % |
| 555 | % % |
| 556 | % L i s t C o d e r I n f o % |
| 557 | % % |
| 558 | % % |
| 559 | % % |
| 560 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 561 | % |
| 562 | % ListCoderInfo() lists the coder info to a file. |
| 563 | % |
| 564 | % The format of the ListCoderInfo coder is: |
| 565 | % |
| 566 | % MagickBooleanType ListCoderInfo(FILE *file,ExceptionInfo *exception) |
| 567 | % |
| 568 | % A description of each parameter follows. |
| 569 | % |
| 570 | % o file: An pointer to a FILE. |
| 571 | % |
| 572 | % o exception: return any errors or warnings in this structure. |
| 573 | % |
| 574 | */ |
| 575 | MagickExport MagickBooleanType ListCoderInfo(FILE *file, |
| 576 | ExceptionInfo *exception) |
| 577 | { |
| 578 | const char |
| 579 | *path; |
| 580 | |
| 581 | const CoderInfo |
| 582 | **coder_info; |
| 583 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 584 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 585 | i; |
| 586 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 587 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | number_coders; |
| 589 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 590 | ssize_t |
| 591 | j; |
| 592 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 593 | if (file == (const FILE *) NULL) |
| 594 | file=stdout; |
| 595 | coder_info=GetCoderInfoList("*",&number_coders,exception); |
| 596 | if (coder_info == (const CoderInfo **) NULL) |
| 597 | return(MagickFalse); |
| 598 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 599 | for (i=0; i < (ssize_t) number_coders; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | { |
| 601 | if (coder_info[i]->stealth != MagickFalse) |
| 602 | continue; |
| 603 | if ((path == (const char *) NULL) || |
| 604 | (LocaleCompare(path,coder_info[i]->path) != 0)) |
| 605 | { |
| 606 | if (coder_info[i]->path != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 607 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",coder_info[i]->path); |
| 608 | (void) FormatLocaleFile(file,"Magick Coder\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 609 | (void) FormatLocaleFile(file, |
| 610 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 611 | "------------------------------\n"); |
| 612 | } |
| 613 | path=coder_info[i]->path; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 614 | (void) FormatLocaleFile(file,"%s",coder_info[i]->magick); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 615 | for (j=(ssize_t) strlen(coder_info[i]->magick); j <= 11; j++) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 616 | (void) FormatLocaleFile(file," "); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 617 | if (coder_info[i]->name != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 618 | (void) FormatLocaleFile(file,"%s",coder_info[i]->name); |
| 619 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 620 | } |
| 621 | coder_info=(const CoderInfo **) RelinquishMagickMemory((void *) coder_info); |
| 622 | (void) fflush(file); |
| 623 | return(MagickTrue); |
| 624 | } |
| 625 | |
| 626 | /* |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % % |
| 629 | % % |
| 630 | % % |
| 631 | + L o a d C o d e r L i s t % |
| 632 | % % |
| 633 | % % |
| 634 | % % |
| 635 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 636 | % |
| 637 | % LoadCoderList() loads the coder configuration file which provides a |
| 638 | % mapping between coder attributes and a coder name. |
| 639 | % |
| 640 | % The format of the LoadCoderList coder is: |
| 641 | % |
| 642 | % MagickBooleanType LoadCoderList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 643 | % const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | % |
| 645 | % A description of each parameter follows: |
| 646 | % |
| 647 | % o xml: The coder list in XML format. |
| 648 | % |
| 649 | % o filename: The coder list filename. |
| 650 | % |
| 651 | % o depth: depth of <include /> statements. |
| 652 | % |
| 653 | % o exception: return any errors or warnings in this structure. |
| 654 | % |
| 655 | */ |
| 656 | |
| 657 | static void *DestroyCoderNode(void *coder_info) |
| 658 | { |
| 659 | register CoderInfo |
| 660 | *p; |
| 661 | |
| 662 | p=(CoderInfo *) coder_info; |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 663 | if (p->exempt == MagickFalse) |
| 664 | { |
| 665 | if (p->path != (char *) NULL) |
| 666 | p->path=DestroyString(p->path); |
| 667 | if (p->name != (char *) NULL) |
| 668 | p->name=DestroyString(p->name); |
| 669 | if (p->magick != (char *) NULL) |
| 670 | p->magick=DestroyString(p->magick); |
| 671 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 672 | return(RelinquishMagickMemory(p)); |
| 673 | } |
| 674 | |
| 675 | static MagickBooleanType LoadCoderList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 676 | const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 677 | { |
| 678 | char |
| 679 | keyword[MaxTextExtent], |
| 680 | *token; |
| 681 | |
| 682 | const char |
| 683 | *q; |
| 684 | |
| 685 | CoderInfo |
| 686 | *coder_info; |
| 687 | |
| 688 | MagickBooleanType |
| 689 | status; |
| 690 | |
| 691 | /* |
| 692 | Load the coder map file. |
| 693 | */ |
| 694 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 695 | "Loading coder configuration file \"%s\" ...",filename); |
| 696 | if (xml == (const char *) NULL) |
| 697 | return(MagickFalse); |
| 698 | if (coder_list == (SplayTreeInfo *) NULL) |
| 699 | { |
| 700 | coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
| 701 | DestroyCoderNode); |
| 702 | if (coder_list == (SplayTreeInfo *) NULL) |
| 703 | { |
| 704 | ThrowFileException(exception,ResourceLimitError, |
| 705 | "MemoryAllocationFailed",filename); |
| 706 | return(MagickFalse); |
| 707 | } |
| 708 | } |
| 709 | status=MagickTrue; |
| 710 | coder_info=(CoderInfo *) NULL; |
| 711 | token=AcquireString(xml); |
| 712 | for (q=(char *) xml; *q != '\0'; ) |
| 713 | { |
| 714 | /* |
| 715 | Interpret XML. |
| 716 | */ |
| 717 | GetMagickToken(q,&q,token); |
| 718 | if (*token == '\0') |
| 719 | break; |
| 720 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 721 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 722 | { |
| 723 | /* |
| 724 | Doctype element. |
| 725 | */ |
| 726 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
| 727 | GetMagickToken(q,&q,token); |
| 728 | continue; |
| 729 | } |
| 730 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 731 | { |
| 732 | /* |
| 733 | Comment element. |
| 734 | */ |
| 735 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
| 736 | GetMagickToken(q,&q,token); |
| 737 | continue; |
| 738 | } |
| 739 | if (LocaleCompare(keyword,"<include") == 0) |
| 740 | { |
| 741 | /* |
| 742 | Include element. |
| 743 | */ |
| 744 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 745 | { |
| 746 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 747 | GetMagickToken(q,&q,token); |
| 748 | if (*token != '=') |
| 749 | continue; |
| 750 | GetMagickToken(q,&q,token); |
| 751 | if (LocaleCompare(keyword,"file") == 0) |
| 752 | { |
| 753 | if (depth > 200) |
| 754 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 755 | ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 756 | else |
| 757 | { |
| 758 | char |
| 759 | path[MaxTextExtent], |
| 760 | *xml; |
| 761 | |
| 762 | GetPathComponent(filename,HeadPath,path); |
| 763 | if (*path != '\0') |
| 764 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 765 | MaxTextExtent); |
| 766 | if (*token == *DirectorySeparator) |
| 767 | (void) CopyMagickString(path,token,MaxTextExtent); |
| 768 | else |
| 769 | (void) ConcatenateMagickString(path,token,MaxTextExtent); |
cristy | 3a5987c | 2013-11-07 14:18:46 +0000 | [diff] [blame] | 770 | xml=FileToString(path,~0UL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 771 | if (xml != (char *) NULL) |
| 772 | { |
| 773 | status=LoadCoderList(xml,path,depth+1,exception); |
| 774 | xml=(char *) RelinquishMagickMemory(xml); |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | continue; |
| 780 | } |
| 781 | if (LocaleCompare(keyword,"<coder") == 0) |
| 782 | { |
| 783 | /* |
| 784 | Coder element. |
| 785 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 786 | coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 787 | if (coder_info == (CoderInfo *) NULL) |
| 788 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 789 | (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); |
| 790 | coder_info->path=ConstantString(filename); |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 791 | coder_info->exempt=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 792 | coder_info->signature=MagickSignature; |
| 793 | continue; |
| 794 | } |
| 795 | if (coder_info == (CoderInfo *) NULL) |
| 796 | continue; |
| 797 | if (LocaleCompare(keyword,"/>") == 0) |
| 798 | { |
| 799 | status=AddValueToSplayTree(coder_list,ConstantString( |
| 800 | coder_info->magick),coder_info); |
| 801 | if (status == MagickFalse) |
| 802 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 803 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 804 | coder_info->magick); |
| 805 | coder_info=(CoderInfo *) NULL; |
cristy | d45122f | 2014-01-14 23:46:16 +0000 | [diff] [blame] | 806 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 807 | } |
| 808 | GetMagickToken(q,(const char **) NULL,token); |
| 809 | if (*token != '=') |
| 810 | continue; |
| 811 | GetMagickToken(q,&q,token); |
| 812 | GetMagickToken(q,&q,token); |
| 813 | switch (*keyword) |
| 814 | { |
| 815 | case 'M': |
| 816 | case 'm': |
| 817 | { |
| 818 | if (LocaleCompare((char *) keyword,"magick") == 0) |
| 819 | { |
| 820 | coder_info->magick=ConstantString(token); |
| 821 | break; |
| 822 | } |
| 823 | break; |
| 824 | } |
| 825 | case 'N': |
| 826 | case 'n': |
| 827 | { |
| 828 | if (LocaleCompare((char *) keyword,"name") == 0) |
| 829 | { |
| 830 | coder_info->name=ConstantString(token); |
| 831 | break; |
| 832 | } |
| 833 | break; |
| 834 | } |
| 835 | case 'S': |
| 836 | case 's': |
| 837 | { |
| 838 | if (LocaleCompare((char *) keyword,"stealth") == 0) |
| 839 | { |
anthony | 6f20131 | 2012-03-30 04:08:15 +0000 | [diff] [blame] | 840 | coder_info->stealth=IsStringTrue(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 841 | break; |
| 842 | } |
| 843 | break; |
| 844 | } |
| 845 | default: |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | token=(char *) RelinquishMagickMemory(token); |
| 850 | return(status); |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 855 | % % |
| 856 | % % |
| 857 | % % |
| 858 | % L o a d C o d e r L i s t s % |
| 859 | % % |
| 860 | % % |
| 861 | % % |
| 862 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 863 | % |
| 864 | % LoadCoderLists() loads one or more coder configuration file which |
| 865 | % provides a mapping between coder attributes and a coder name. |
| 866 | % |
| 867 | % The format of the LoadCoderLists coder is: |
| 868 | % |
| 869 | % MagickBooleanType LoadCoderLists(const char *filename, |
| 870 | % ExceptionInfo *exception) |
| 871 | % |
| 872 | % A description of each parameter follows: |
| 873 | % |
| 874 | % o filename: the font file name. |
| 875 | % |
| 876 | % o exception: return any errors or warnings in this structure. |
| 877 | % |
| 878 | */ |
| 879 | static MagickBooleanType LoadCoderLists(const char *filename, |
| 880 | ExceptionInfo *exception) |
| 881 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 882 | const StringInfo |
| 883 | *option; |
| 884 | |
| 885 | LinkedListInfo |
| 886 | *options; |
| 887 | |
| 888 | MagickStatusType |
| 889 | status; |
| 890 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 891 | register ssize_t |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 892 | i; |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 893 | |
| 894 | /* |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 895 | Load external coder map. |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 896 | */ |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 897 | if (coder_list == (SplayTreeInfo *) NULL) |
| 898 | { |
| 899 | coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
| 900 | DestroyCoderNode); |
| 901 | if (coder_list == (SplayTreeInfo *) NULL) |
| 902 | { |
| 903 | ThrowFileException(exception,ResourceLimitError, |
| 904 | "MemoryAllocationFailed",filename); |
| 905 | return(MagickFalse); |
| 906 | } |
| 907 | } |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 908 | status=MagickTrue; |
| 909 | options=GetConfigureOptions(filename,exception); |
| 910 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 911 | while (option != (const StringInfo *) NULL) |
| 912 | { |
cristy | aae13f6 | 2013-08-15 14:41:32 +0000 | [diff] [blame] | 913 | status&=LoadCoderList((const char *) GetStringInfoDatum(option), |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 914 | GetStringInfoPath(option),0,exception); |
| 915 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 916 | } |
| 917 | options=DestroyConfigureOptions(options); |
| 918 | /* |
| 919 | Load built-in coder map. |
| 920 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 921 | for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 922 | { |
| 923 | CoderInfo |
| 924 | *coder_info; |
| 925 | |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 926 | register const CoderMapInfo |
| 927 | *p; |
| 928 | |
| 929 | p=CoderMap+i; |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 930 | coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 931 | if (coder_info == (CoderInfo *) NULL) |
| 932 | { |
| 933 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | d45122f | 2014-01-14 23:46:16 +0000 | [diff] [blame] | 934 | ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 935 | continue; |
| 936 | } |
| 937 | (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); |
cristy | 38b8ed9 | 2009-10-16 01:20:21 +0000 | [diff] [blame] | 938 | coder_info->path=(char *) "[built-in]"; |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 939 | coder_info->magick=(char *) p->magick; |
| 940 | coder_info->name=(char *) p->name; |
| 941 | coder_info->exempt=MagickTrue; |
| 942 | coder_info->signature=MagickSignature; |
cristy | aae13f6 | 2013-08-15 14:41:32 +0000 | [diff] [blame] | 943 | status&=AddValueToSplayTree(coder_list,ConstantString(coder_info->magick), |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 944 | coder_info); |
| 945 | if (status == MagickFalse) |
| 946 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 947 | ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 948 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 949 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 950 | } |