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 | 93b707b | 2017-12-06 07:05:51 -0500 | [diff] [blame] | 20 | % Copyright 1999-2018 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 | % % |
Cristy | 9ddfcca | 2018-09-09 19:46:34 -0400 | [diff] [blame] | 26 | % https://imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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" |
dirk | abed7e2 | 2016-01-31 17:10:21 +0100 | [diff] [blame] | 51 | #include "MagickCore/linked-list.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 52 | #include "MagickCore/log.h" |
| 53 | #include "MagickCore/memory_.h" |
Dirk Lemstra | 06344a0 | 2017-10-15 10:10:01 +0200 | [diff] [blame] | 54 | #include "MagickCore/memory-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 55 | #include "MagickCore/option.h" |
| 56 | #include "MagickCore/semaphore.h" |
| 57 | #include "MagickCore/string_.h" |
| 58 | #include "MagickCore/splay-tree.h" |
| 59 | #include "MagickCore/token.h" |
| 60 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 61 | #include "MagickCore/utility-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 62 | #include "MagickCore/xml-tree.h" |
cristy | 3291f51 | 2014-03-16 22:16:22 +0000 | [diff] [blame] | 63 | #include "MagickCore/xml-tree-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 66 | Typedef declarations. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | */ |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 68 | typedef struct _CoderMapInfo |
| 69 | { |
| 70 | const char |
| 71 | *magick, |
| 72 | *name; |
| 73 | } CoderMapInfo; |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | Static declarations. |
| 77 | */ |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 78 | static const CoderMapInfo |
| 79 | CoderMap[] = |
| 80 | { |
| 81 | { "3FR", "DNG" }, |
Cristy | b066eae | 2017-01-20 09:15:54 -0500 | [diff] [blame] | 82 | { "3GP", "MPEG" }, |
| 83 | { "3G2", "MPEG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 84 | { "8BIMTEXT", "META" }, |
| 85 | { "8BIMWTEXT", "META" }, |
| 86 | { "AFM", "TTF" }, |
| 87 | { "A", "RAW" }, |
| 88 | { "AI", "PDF" }, |
| 89 | { "APP1JPEG", "META" }, |
| 90 | { "APP1", "META" }, |
| 91 | { "ARW", "DNG" }, |
cristy | 0fc0259 | 2010-05-24 14:12:38 +0000 | [diff] [blame] | 92 | { "AVI", "MPEG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 93 | { "BIE", "JBIG" }, |
| 94 | { "BMP2", "BMP" }, |
| 95 | { "BMP3", "BMP" }, |
| 96 | { "B", "RAW" }, |
| 97 | { "BRF", "BRAILLE" }, |
cristy | 90dbac7 | 2010-08-22 15:08:40 +0000 | [diff] [blame] | 98 | { "BGRA", "BGR" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 99 | { "BGRO", "BGR" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 100 | { "CMYKA", "CMYK" }, |
| 101 | { "C", "RAW" }, |
| 102 | { "CAL", "CALS" }, |
cristy | c05417c | 2010-09-21 16:30:32 +0000 | [diff] [blame] | 103 | { "CANVAS", "XC" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 104 | { "CMYKA", "CMYK" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 105 | { "CR2", "DNG" }, |
| 106 | { "CRW", "DNG" }, |
| 107 | { "CUR", "ICON" }, |
Cristy | 6ffac4f | 2015-08-23 10:55:57 -0400 | [diff] [blame] | 108 | { "DATA", "INLINE" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 109 | { "DCR", "DNG" }, |
| 110 | { "DCX", "PCX" }, |
| 111 | { "DFONT", "TTF" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 112 | { "DXT1", "DDS" }, |
| 113 | { "DXT5", "DDS" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 114 | { "EPDF", "PDF" }, |
| 115 | { "EPI", "PS" }, |
| 116 | { "EPS2", "PS2" }, |
| 117 | { "EPS3", "PS3" }, |
| 118 | { "EPSF", "PS" }, |
| 119 | { "EPSI", "PS" }, |
| 120 | { "EPS", "PS" }, |
| 121 | { "EPT2", "EPT" }, |
| 122 | { "EPT3", "EPT" }, |
| 123 | { "ERF", "DNG" }, |
| 124 | { "EXIF", "META" }, |
| 125 | { "FILE", "URL" }, |
| 126 | { "FRACTAL", "PLASMA" }, |
| 127 | { "FTP", "URL" }, |
| 128 | { "FTS", "FITS" }, |
| 129 | { "G3", "FAX" }, |
dirk | 52456ef | 2016-06-17 15:29:46 +0200 | [diff] [blame] | 130 | { "G4", "FAX" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 131 | { "GIF87", "GIF" }, |
| 132 | { "G", "RAW" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 133 | { "GRANITE", "MAGICK" }, |
Cristy | b2d2441 | 2018-03-09 19:41:19 -0500 | [diff] [blame] | 134 | { "GRAYA", "GRAY" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 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 | ea59e6b | 2018-02-09 19:32:57 -0500 | [diff] [blame] | 140 | { "ICODIB", "DIB" }, |
cristy | a5338bb | 2014-11-05 18:25:16 +0000 | [diff] [blame] | 141 | { "IIQ", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 142 | { "K25", "DNG" }, |
| 143 | { "KDC", "DNG" }, |
| 144 | { "H", "MAGICK" }, |
| 145 | { "HTM", "HTML" }, |
| 146 | { "HTTP", "URL" }, |
dirk | 853b77b | 2013-09-21 19:04:42 +0000 | [diff] [blame] | 147 | { "HTTPS", "URL" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 148 | { "ICB", "TGA" }, |
| 149 | { "ICC", "META" }, |
| 150 | { "ICM", "META" }, |
| 151 | { "ICO", "ICON" }, |
| 152 | { "IMPLICIT", "***" }, |
| 153 | { "IPTC", "META" }, |
| 154 | { "IPTCTEXT", "META" }, |
| 155 | { "IPTCWTEXT", "META" }, |
| 156 | { "ISOBRL", "BRAILLE" }, |
Samuel Thibault | 531aa15 | 2015-11-01 23:36:24 +0100 | [diff] [blame] | 157 | { "ISOBRL6", "BRAILLE" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 158 | { "JBG", "JBIG" }, |
| 159 | { "JNG", "PNG" }, |
| 160 | { "JPC", "JP2" }, |
cristy | 2267fa4 | 2014-09-12 10:27:47 +0000 | [diff] [blame] | 161 | { "JPT", "JP2" }, |
| 162 | { "JPM", "JP2" }, |
cristy | 02f1fda | 2009-12-10 15:23:56 +0000 | [diff] [blame] | 163 | { "J2C", "JP2" }, |
cristy | 4faac68 | 2012-05-10 12:09:45 +0000 | [diff] [blame] | 164 | { "J2K", "JP2" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 165 | { "JNG", "PNG" }, |
cristy | b338b71 | 2014-11-27 14:06:34 +0000 | [diff] [blame] | 166 | { "JPE", "JPEG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 167 | { "JPG", "JPEG" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 168 | { "JPM", "JP2" }, |
cristy | a663a4f | 2015-01-23 12:11:57 +0000 | [diff] [blame] | 169 | { "JPS", "JPEG" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 170 | { "JPT", "JP2" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 171 | { "JPX", "JP2" }, |
| 172 | { "K", "RAW" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 173 | { "K25", "DNG" }, |
| 174 | { "KDC", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 175 | { "LOGO", "MAGICK" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 176 | { "M", "RAW" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 177 | { "M2V", "MPEG" }, |
| 178 | { "M4V", "MPEG" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 179 | { "MEF", "DNG" }, |
cristy | a3d8142 | 2015-04-03 13:00:33 +0000 | [diff] [blame] | 180 | { "MKV", "MPEG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 181 | { "MNG", "PNG" }, |
cristy | 1dbd5a3 | 2010-11-28 22:23:27 +0000 | [diff] [blame] | 182 | { "MOV", "MPEG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 183 | { "MP4", "MPEG" }, |
| 184 | { "MPG", "MPEG" }, |
| 185 | { "MPRI", "MPR" }, |
cristy | 1be98ec | 2012-01-30 16:51:12 +0000 | [diff] [blame] | 186 | { "MEF", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 187 | { "MRW", "DNG" }, |
| 188 | { "MSVG", "SVG" }, |
| 189 | { "NEF", "DNG" }, |
| 190 | { "NETSCAPE", "MAGICK" }, |
cristy | cb8f0ae | 2012-03-02 12:26:21 +0000 | [diff] [blame] | 191 | { "NRW", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 192 | { "O", "RAW" }, |
| 193 | { "ORF", "DNG" }, |
| 194 | { "OTF", "TTF" }, |
| 195 | { "P7", "PNM" }, |
| 196 | { "PAL", "UYVY" }, |
| 197 | { "PAM", "PNM" }, |
| 198 | { "PBM", "PNM" }, |
| 199 | { "PCDS", "PCD" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 200 | { "PCT", "PICT" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 201 | { "PDFA", "PDF" }, |
| 202 | { "PEF", "DNG" }, |
| 203 | { "PEF", "DNG" }, |
| 204 | { "PFA", "TTF" }, |
| 205 | { "PFB", "TTF" }, |
| 206 | { "PFM", "PNM" }, |
| 207 | { "PGM", "PNM" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 208 | { "PICON", "XPM" }, |
| 209 | { "PJPEG", "JPEG" }, |
| 210 | { "PM", "XPM" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 211 | { "PNG00", "PNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 212 | { "PNG24", "PNG" }, |
| 213 | { "PNG32", "PNG" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 214 | { "PNG48", "PNG" }, |
| 215 | { "PNG64", "PNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 216 | { "PNG8", "PNG" }, |
| 217 | { "PPM", "PNM" }, |
cristy | b423301 | 2010-02-28 20:09:14 +0000 | [diff] [blame] | 218 | { "PSB", "PSD" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 219 | { "PTIF", "TIFF" }, |
dirk | 2a2d3d6 | 2015-07-27 11:09:58 +0000 | [diff] [blame] | 220 | { "R", "RAW" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 221 | { "RADIAL-GRADIENT", "GRADIENT" }, |
| 222 | { "RAF", "DNG" }, |
| 223 | { "RAS", "SUN" }, |
cristy | 1b1f072 | 2014-06-10 10:14:59 +0000 | [diff] [blame] | 224 | { "RAW", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 225 | { "RGBA", "RGB" }, |
| 226 | { "RGBO", "RGB" }, |
cristy | 15e2296 | 2014-02-21 22:56:26 +0000 | [diff] [blame] | 227 | { "RMF", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 228 | { "ROSE", "MAGICK" }, |
cristy | 98aceb8 | 2012-10-20 21:24:00 +0000 | [diff] [blame] | 229 | { "RW2", "DNG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 230 | { "SHTML", "HTML" }, |
dirk | a1e4ab8 | 2014-10-07 05:06:49 +0000 | [diff] [blame] | 231 | { "SIX", "SIXEL" }, |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 232 | { "SPARSE-COLOR", "TXT" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 233 | { "SR2", "DNG" }, |
| 234 | { "SRF", "DNG" }, |
| 235 | { "SVGZ", "SVG" }, |
| 236 | { "TEXT", "TXT" }, |
| 237 | { "TIFF64", "TIFF" }, |
| 238 | { "TIF", "TIFF" }, |
| 239 | { "TTC", "TTF" }, |
| 240 | { "UBRL", "BRAILLE" }, |
Samuel Thibault | 531aa15 | 2015-11-01 23:36:24 +0100 | [diff] [blame] | 241 | { "UBRL6", "BRAILLE" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 242 | { "VDA", "TGA" }, |
| 243 | { "VST", "TGA" }, |
cristy | ed40d62 | 2011-01-17 15:51:00 +0000 | [diff] [blame] | 244 | { "WIZARD", "MAGICK" }, |
dirk | 073ff37 | 2014-01-05 14:05:25 +0000 | [diff] [blame] | 245 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
| 246 | { "WMF", "EMF" }, |
| 247 | #endif |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 248 | { "WMV", "MPEG" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 249 | { "WMZ", "WMF" }, |
| 250 | { "X3f", "DNG" }, |
| 251 | { "XMP", "META" }, |
| 252 | { "XTRNARRAY", "XTRN" }, |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 253 | { "XV", "VIFF" }, |
| 254 | { "Y", "RAW" }, |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 255 | { "YCbCrA", "YCbCr" } |
cristy | e3e77a1 | 2009-10-16 00:47:21 +0000 | [diff] [blame] | 256 | }; |
| 257 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 258 | static SemaphoreInfo |
| 259 | *coder_semaphore = (SemaphoreInfo *) NULL; |
| 260 | |
| 261 | static SplayTreeInfo |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 262 | *coder_cache = (SplayTreeInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | Forward declarations. |
| 266 | */ |
| 267 | static MagickBooleanType |
Dirk Lemstra | e2939a4 | 2018-10-04 23:20:08 +0200 | [diff] [blame^] | 268 | IsCoderTreeInstantiated(ExceptionInfo *); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 272 | % % |
| 273 | % % |
| 274 | % % |
cristy | 6c6322e | 2014-09-09 22:39:21 +0000 | [diff] [blame] | 275 | + 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] | 276 | % % |
| 277 | % % |
| 278 | % % |
| 279 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 280 | % |
cristy | 6c6322e | 2014-09-09 22:39:21 +0000 | [diff] [blame] | 281 | % AcquireCoderCache() caches one or more coder configurations which provides a |
| 282 | % mapping between coder attributes and a coder name. |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 283 | % |
| 284 | % The format of the AcquireCoderCache coder is: |
| 285 | % |
| 286 | % SplayTreeInfo *AcquireCoderCache(const char *filename, |
| 287 | % ExceptionInfo *exception) |
| 288 | % |
| 289 | % A description of each parameter follows: |
| 290 | % |
| 291 | % o filename: the font file name. |
| 292 | % |
| 293 | % o exception: return any errors or warnings in this structure. |
| 294 | % |
| 295 | */ |
| 296 | |
| 297 | static void *DestroyCoderNode(void *coder_info) |
| 298 | { |
| 299 | register CoderInfo |
| 300 | *p; |
| 301 | |
| 302 | p=(CoderInfo *) coder_info; |
| 303 | if (p->exempt == MagickFalse) |
| 304 | { |
| 305 | if (p->path != (char *) NULL) |
| 306 | p->path=DestroyString(p->path); |
| 307 | if (p->name != (char *) NULL) |
| 308 | p->name=DestroyString(p->name); |
| 309 | if (p->magick != (char *) NULL) |
| 310 | p->magick=DestroyString(p->magick); |
| 311 | } |
| 312 | return(RelinquishMagickMemory(p)); |
| 313 | } |
| 314 | |
Dirk Lemstra | e2939a4 | 2018-10-04 23:20:08 +0200 | [diff] [blame^] | 315 | static SplayTreeInfo *AcquireCoderCache(ExceptionInfo *exception) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 316 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 317 | MagickStatusType |
| 318 | status; |
| 319 | |
| 320 | register ssize_t |
| 321 | i; |
| 322 | |
| 323 | SplayTreeInfo |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 324 | *cache; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 325 | |
| 326 | /* |
Dirk Lemstra | e2939a4 | 2018-10-04 23:20:08 +0200 | [diff] [blame^] | 327 | Load built-in coder map. |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 328 | */ |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 329 | cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 330 | DestroyCoderNode); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 331 | status=MagickTrue; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 332 | for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) |
| 333 | { |
| 334 | CoderInfo |
| 335 | *coder_info; |
| 336 | |
| 337 | register const CoderMapInfo |
| 338 | *p; |
| 339 | |
| 340 | p=CoderMap+i; |
| 341 | coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); |
| 342 | if (coder_info == (CoderInfo *) NULL) |
| 343 | { |
| 344 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 345 | ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); |
| 346 | continue; |
| 347 | } |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 348 | (void) memset(coder_info,0,sizeof(*coder_info)); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 349 | coder_info->path=(char *) "[built-in]"; |
| 350 | coder_info->magick=(char *) p->magick; |
| 351 | coder_info->name=(char *) p->name; |
| 352 | coder_info->exempt=MagickTrue; |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 353 | coder_info->signature=MagickCoreSignature; |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 354 | status&=AddValueToSplayTree(cache,ConstantString(coder_info->magick), |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 355 | coder_info); |
| 356 | if (status == MagickFalse) |
| 357 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 358 | ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); |
| 359 | } |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 360 | return(cache); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 361 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 362 | |
| 363 | /* |
| 364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 365 | % % |
| 366 | % % |
| 367 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 368 | + 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] | 369 | % % |
| 370 | % % |
| 371 | % % |
| 372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 373 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 374 | % CoderComponentGenesis() instantiates the coder component. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 376 | % The format of the CoderComponentGenesis method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 377 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 378 | % MagickBooleanType CoderComponentGenesis(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | % |
| 380 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 381 | MagickPrivate MagickBooleanType CoderComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 382 | { |
cristy | 7c97706 | 2014-04-04 14:05:53 +0000 | [diff] [blame] | 383 | if (coder_semaphore == (SemaphoreInfo *) NULL) |
| 384 | coder_semaphore=AcquireSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 385 | return(MagickTrue); |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 390 | % % |
| 391 | % % |
| 392 | % % |
| 393 | + C o d e r C o m p o n e n t T e r m i n u s % |
| 394 | % % |
| 395 | % % |
| 396 | % % |
| 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 398 | % |
| 399 | % CoderComponentTerminus() destroys the coder component. |
| 400 | % |
| 401 | % The format of the CoderComponentTerminus method is: |
| 402 | % |
| 403 | % CoderComponentTerminus(void) |
| 404 | % |
| 405 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 406 | MagickPrivate void CoderComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 407 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 408 | if (coder_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 409 | ActivateSemaphoreInfo(&coder_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 410 | LockSemaphoreInfo(coder_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 411 | if (coder_cache != (SplayTreeInfo *) NULL) |
| 412 | coder_cache=DestroySplayTree(coder_cache); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 413 | UnlockSemaphoreInfo(coder_semaphore); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 414 | RelinquishSemaphoreInfo(&coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* |
| 418 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 419 | % % |
| 420 | % % |
| 421 | % % |
| 422 | + G e t C o d e r I n f o % |
| 423 | % % |
| 424 | % % |
| 425 | % % |
| 426 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 427 | % |
| 428 | % GetCoderInfo searches the coder list for the specified name and if found |
| 429 | % returns attributes for that coder. |
| 430 | % |
| 431 | % The format of the GetCoderInfo method is: |
| 432 | % |
| 433 | % const CoderInfo *GetCoderInfo(const char *name,ExceptionInfo *exception) |
| 434 | % |
| 435 | % A description of each parameter follows: |
| 436 | % |
| 437 | % o name: the coder name. |
| 438 | % |
| 439 | % o exception: return any errors or warnings in this structure. |
| 440 | % |
| 441 | */ |
| 442 | MagickExport const CoderInfo *GetCoderInfo(const char *name, |
| 443 | ExceptionInfo *exception) |
| 444 | { |
| 445 | assert(exception != (ExceptionInfo *) NULL); |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 446 | if (IsCoderTreeInstantiated(exception) == MagickFalse) |
| 447 | return((const CoderInfo *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) |
Cristy | 1d8b1f1 | 2017-09-16 10:13:23 -0400 | [diff] [blame] | 449 | return((const CoderInfo *) GetRootValueFromSplayTree(coder_cache)); |
| 450 | return((const CoderInfo *) GetValueFromSplayTree(coder_cache,name)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* |
| 454 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 455 | % % |
| 456 | % % |
| 457 | % % |
| 458 | % G e t C o d e r I n f o L i s t % |
| 459 | % % |
| 460 | % % |
| 461 | % % |
| 462 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 463 | % |
| 464 | % GetCoderInfoList() returns any coder_map that match the specified pattern. |
| 465 | % The format of the GetCoderInfoList function is: |
| 466 | % |
| 467 | % const CoderInfo **GetCoderInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 468 | % size_t *number_coders,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 469 | % |
| 470 | % A description of each parameter follows: |
| 471 | % |
| 472 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 473 | % |
| 474 | % o number_coders: This integer returns the number of coders in the list. |
| 475 | % |
| 476 | % o exception: return any errors or warnings in this structure. |
| 477 | % |
| 478 | */ |
| 479 | |
| 480 | static int CoderInfoCompare(const void *x,const void *y) |
| 481 | { |
| 482 | const CoderInfo |
| 483 | **p, |
| 484 | **q; |
| 485 | |
| 486 | p=(const CoderInfo **) x, |
| 487 | q=(const CoderInfo **) y; |
| 488 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 489 | return(LocaleCompare((*p)->name,(*q)->name)); |
| 490 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 491 | } |
| 492 | |
| 493 | MagickExport const CoderInfo **GetCoderInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 494 | size_t *number_coders,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 495 | { |
| 496 | const CoderInfo |
| 497 | **coder_map; |
| 498 | |
| 499 | register const CoderInfo |
| 500 | *p; |
| 501 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 502 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 503 | i; |
| 504 | |
| 505 | /* |
| 506 | Allocate coder list. |
| 507 | */ |
| 508 | assert(pattern != (char *) NULL); |
| 509 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 510 | assert(number_coders != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 511 | *number_coders=0; |
| 512 | p=GetCoderInfo("*",exception); |
| 513 | if (p == (const CoderInfo *) NULL) |
| 514 | return((const CoderInfo **) NULL); |
| 515 | coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 516 | GetNumberOfNodesInSplayTree(coder_cache)+1UL,sizeof(*coder_map)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 517 | if (coder_map == (const CoderInfo **) NULL) |
| 518 | return((const CoderInfo **) NULL); |
| 519 | /* |
| 520 | Generate coder list. |
| 521 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 522 | LockSemaphoreInfo(coder_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 523 | ResetSplayTreeIterator(coder_cache); |
| 524 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 525 | for (i=0; p != (const CoderInfo *) NULL; ) |
| 526 | { |
| 527 | if ((p->stealth == MagickFalse) && |
| 528 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 529 | coder_map[i++]=p; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 530 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 532 | UnlockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 533 | qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare); |
| 534 | coder_map[i]=(CoderInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 535 | *number_coders=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 536 | return(coder_map); |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 541 | % % |
| 542 | % % |
| 543 | % % |
| 544 | % G e t C o d e r L i s t % |
| 545 | % % |
| 546 | % % |
| 547 | % % |
| 548 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 549 | % |
| 550 | % GetCoderList() returns any coder_map that match the specified pattern. |
| 551 | % |
| 552 | % The format of the GetCoderList function is: |
| 553 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 554 | % char **GetCoderList(const char *pattern,size_t *number_coders, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 555 | % ExceptionInfo *exception) |
| 556 | % |
| 557 | % A description of each parameter follows: |
| 558 | % |
| 559 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 560 | % |
| 561 | % o number_coders: This integer returns the number of coders in the list. |
| 562 | % |
| 563 | % o exception: return any errors or warnings in this structure. |
| 564 | % |
| 565 | */ |
| 566 | |
| 567 | static int CoderCompare(const void *x,const void *y) |
| 568 | { |
| 569 | register const char |
| 570 | **p, |
| 571 | **q; |
| 572 | |
| 573 | p=(const char **) x; |
| 574 | q=(const char **) y; |
| 575 | return(LocaleCompare(*p,*q)); |
| 576 | } |
| 577 | |
| 578 | MagickExport char **GetCoderList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 579 | size_t *number_coders,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 580 | { |
| 581 | char |
| 582 | **coder_map; |
| 583 | |
| 584 | register const CoderInfo |
| 585 | *p; |
| 586 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 587 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | i; |
| 589 | |
| 590 | /* |
| 591 | Allocate coder list. |
| 592 | */ |
| 593 | assert(pattern != (char *) NULL); |
| 594 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 595 | assert(number_coders != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 596 | *number_coders=0; |
| 597 | p=GetCoderInfo("*",exception); |
| 598 | if (p == (const CoderInfo *) NULL) |
| 599 | return((char **) NULL); |
| 600 | coder_map=(char **) AcquireQuantumMemory((size_t) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 601 | GetNumberOfNodesInSplayTree(coder_cache)+1UL,sizeof(*coder_map)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 602 | if (coder_map == (char **) NULL) |
| 603 | return((char **) NULL); |
| 604 | /* |
| 605 | Generate coder list. |
| 606 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 607 | LockSemaphoreInfo(coder_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 608 | ResetSplayTreeIterator(coder_cache); |
| 609 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 610 | for (i=0; p != (const CoderInfo *) NULL; ) |
| 611 | { |
| 612 | if ((p->stealth == MagickFalse) && |
| 613 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 614 | coder_map[i++]=ConstantString(p->name); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 615 | p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 617 | UnlockSemaphoreInfo(coder_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 618 | qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare); |
| 619 | coder_map[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 620 | *number_coders=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 621 | return(coder_map); |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 626 | % % |
| 627 | % % |
| 628 | % % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 629 | + 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] | 630 | % % |
| 631 | % % |
| 632 | % % |
| 633 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 634 | % |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 635 | % IsCoderTreeInstantiated() determines if the coder tree is instantiated. If |
| 636 | % not, it instantiates the tree and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 637 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 638 | % The format of the IsCoderInstantiated method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 639 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 640 | % MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 641 | % |
| 642 | % A description of each parameter follows. |
| 643 | % |
| 644 | % o exception: return any errors or warnings in this structure. |
| 645 | % |
| 646 | */ |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 647 | static MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 648 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 649 | if (coder_cache == (SplayTreeInfo *) NULL) |
| 650 | { |
| 651 | if (coder_semaphore == (SemaphoreInfo *) NULL) |
| 652 | ActivateSemaphoreInfo(&coder_semaphore); |
| 653 | LockSemaphoreInfo(coder_semaphore); |
| 654 | if (coder_cache == (SplayTreeInfo *) NULL) |
Dirk Lemstra | e2939a4 | 2018-10-04 23:20:08 +0200 | [diff] [blame^] | 655 | coder_cache=AcquireCoderCache(exception); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 656 | UnlockSemaphoreInfo(coder_semaphore); |
| 657 | } |
| 658 | return(coder_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /* |
| 662 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 663 | % % |
| 664 | % % |
| 665 | % % |
| 666 | % L i s t C o d e r I n f o % |
| 667 | % % |
| 668 | % % |
| 669 | % % |
| 670 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 671 | % |
| 672 | % ListCoderInfo() lists the coder info to a file. |
| 673 | % |
| 674 | % The format of the ListCoderInfo coder is: |
| 675 | % |
| 676 | % MagickBooleanType ListCoderInfo(FILE *file,ExceptionInfo *exception) |
| 677 | % |
| 678 | % A description of each parameter follows. |
| 679 | % |
| 680 | % o file: An pointer to a FILE. |
| 681 | % |
| 682 | % o exception: return any errors or warnings in this structure. |
| 683 | % |
| 684 | */ |
| 685 | MagickExport MagickBooleanType ListCoderInfo(FILE *file, |
| 686 | ExceptionInfo *exception) |
| 687 | { |
| 688 | const char |
| 689 | *path; |
| 690 | |
| 691 | const CoderInfo |
| 692 | **coder_info; |
| 693 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 694 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 695 | i; |
| 696 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 697 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 698 | number_coders; |
| 699 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 700 | ssize_t |
| 701 | j; |
| 702 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 703 | if (file == (const FILE *) NULL) |
| 704 | file=stdout; |
| 705 | coder_info=GetCoderInfoList("*",&number_coders,exception); |
| 706 | if (coder_info == (const CoderInfo **) NULL) |
| 707 | return(MagickFalse); |
| 708 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 709 | for (i=0; i < (ssize_t) number_coders; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 710 | { |
| 711 | if (coder_info[i]->stealth != MagickFalse) |
| 712 | continue; |
| 713 | if ((path == (const char *) NULL) || |
| 714 | (LocaleCompare(path,coder_info[i]->path) != 0)) |
| 715 | { |
| 716 | if (coder_info[i]->path != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 717 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",coder_info[i]->path); |
| 718 | (void) FormatLocaleFile(file,"Magick Coder\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 719 | (void) FormatLocaleFile(file, |
| 720 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 721 | "------------------------------\n"); |
| 722 | } |
| 723 | path=coder_info[i]->path; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 724 | (void) FormatLocaleFile(file,"%s",coder_info[i]->magick); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 725 | for (j=(ssize_t) strlen(coder_info[i]->magick); j <= 11; j++) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 726 | (void) FormatLocaleFile(file," "); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 727 | if (coder_info[i]->name != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 728 | (void) FormatLocaleFile(file,"%s",coder_info[i]->name); |
| 729 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | } |
| 731 | coder_info=(const CoderInfo **) RelinquishMagickMemory((void *) coder_info); |
| 732 | (void) fflush(file); |
| 733 | return(MagickTrue); |
| 734 | } |