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