| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | #include "magick/studio.h" |
|---|
| 49 | #include "magick/property.h" |
|---|
| 50 | #include "magick/blob.h" |
|---|
| 51 | #include "magick/client.h" |
|---|
| 52 | #include "magick/configure.h" |
|---|
| 53 | #include "magick/constitute.h" |
|---|
| 54 | #include "magick/delegate.h" |
|---|
| 55 | #include "magick/exception.h" |
|---|
| 56 | #include "magick/exception-private.h" |
|---|
| 57 | #include "magick/hashmap.h" |
|---|
| 58 | #include "magick/list.h" |
|---|
| 59 | #include "magick/memory_.h" |
|---|
| 60 | #include "magick/resource_.h" |
|---|
| 61 | #include "magick/semaphore.h" |
|---|
| 62 | #include "magick/string_.h" |
|---|
| 63 | #include "magick/token.h" |
|---|
| 64 | #include "magick/utility.h" |
|---|
| 65 | #include "magick/xml-tree.h" |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #define DelegateFilename "delegates.xml" |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | static const char |
|---|
| 76 | *DelegateMap = (const char *) |
|---|
| 77 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
|---|
| 78 | "<delegatemap>" |
|---|
| 79 | " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>" |
|---|
| 80 | " <delegate decode=\"avi:decode\" stealth=\"True\" command=\""mplayer" "%i" -really-quiet -ao null -vo png:z=3\"/>" |
|---|
| 81 | " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" http://www.imagemagick.org/\"/>" |
|---|
| 82 | " <delegate decode=\"cgm\" thread-support=\"False\" command=\""ralcgm" -d ps -oC < "%i" > "%o" 2> "%u"\"/>" |
|---|
| 83 | " <delegate decode=\"dng:decode\" command=\""/usr/bin/ufraw-batch" --silent --wb=camera --black-point=auto --exposure=auto --create-id=also --out-type=ppm16 "--output=%u.pnm" "%i"\"/>" |
|---|
| 84 | " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>" |
|---|
| 85 | " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>" |
|---|
| 86 | " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>" |
|---|
| 87 | " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>" |
|---|
| 88 | " <delegate decode=\"gplt\" command=\""echo" "set size 1.25,0.62 set terminal postscript portrait color solid; set output "%o"; load "%i"" > "%u";"gnuplot" "%u"\"/>" |
|---|
| 89 | " <delegate decode=\"hdr\" command=\""ra_pfm" "%i" "%o"\"/>" |
|---|
| 90 | " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>" |
|---|
| 91 | " <delegate decode=\"hpgl\" command=\"if [ -e hp2xx -o -e /usr/bin/hp2xx ]; then hp2xx -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o else echo "You need to install hp2xx to use HPGL files with ImageMagick." exit 1 fi\"/>" |
|---|
| 92 | " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
|---|
| 93 | " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
|---|
| 94 | " <delegate decode=\"https\" command=\""wget" -q -O "%o" "https:%M"\"/>" |
|---|
| 95 | " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>" |
|---|
| 96 | " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>" |
|---|
| 97 | " <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\""ffmpeg" --i "%i" -vcodec pam -an -f rawvideo -y "%u0.pam" 2;> "%Z"\"/>" |
|---|
| 98 | " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" "%M%%d.jpg" "%u.%m" 2;> "%Z"\"/>" |
|---|
| 99 | " <delegate decode=\"pcl:color\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=ppmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>" |
|---|
| 100 | " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>" |
|---|
| 101 | " <delegate decode=\"pcl:mono\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>" |
|---|
| 102 | " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>" |
|---|
| 103 | " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>" |
|---|
| 104 | " <delegate decode=\"pic\" command=\""ra_pfm" "%i" "%o"\"/>" |
|---|
| 105 | " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>" |
|---|
| 106 | " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>" |
|---|
| 107 | " <delegate decode=\"pov\" command=\""povray" "+i"%i"" -D0 +o"%o" +fn%q +w%w +h%h +a -q9 -kfi"%s" -kff"%n" "convert" -concatenate "%o*.png" "%o"\"/>" |
|---|
| 108 | " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>" |
|---|
| 109 | " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>" |
|---|
| 110 | " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>" |
|---|
| 111 | " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
|---|
| 112 | " <delegate decode=\"ps:bbox\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bbox" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
|---|
| 113 | " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pam" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
|---|
| 114 | " <delegate decode=\"ps:color\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
|---|
| 115 | " <delegate decode=\"ps:mono\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
|---|
| 116 | " <delegate decode=\"rad\" command=\""ra_pfm" "%i" "%o"\"/>" |
|---|
| 117 | " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>" |
|---|
| 118 | " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>" |
|---|
| 119 | " <delegate encode=\"show\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "tmp:%i"\"/>" |
|---|
| 120 | " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
|---|
| 121 | " <delegate decode=\"svg\" command=\""wmf2eps" -o "%o" "%i"\"/>" |
|---|
| 122 | " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>" |
|---|
| 123 | " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "tmp:%i"\"/>" |
|---|
| 124 | " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>" |
|---|
| 125 | "</delegatemap>"; |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | static LinkedListInfo |
|---|
| 131 | *delegate_list = (LinkedListInfo *) NULL; |
|---|
| 132 | |
|---|
| 133 | static SemaphoreInfo |
|---|
| 134 | *delegate_semaphore = (SemaphoreInfo *) NULL; |
|---|
| 135 | |
|---|
| 136 | static volatile MagickBooleanType |
|---|
| 137 | instantiate_delegate = MagickFalse; |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | static MagickBooleanType |
|---|
| 143 | InitializeDelegateList(ExceptionInfo *), |
|---|
| 144 | LoadDelegateLists(const char *,ExceptionInfo *); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | static void *DestroyDelegate(void *delegate_info) |
|---|
| 166 | { |
|---|
| 167 | register DelegateInfo |
|---|
| 168 | *p; |
|---|
| 169 | |
|---|
| 170 | p=(DelegateInfo *) delegate_info; |
|---|
| 171 | if (p->path != (char *) NULL) |
|---|
| 172 | p->path=DestroyString(p->path); |
|---|
| 173 | if (p->decode != (char *) NULL) |
|---|
| 174 | p->decode=DestroyString(p->decode); |
|---|
| 175 | if (p->encode != (char *) NULL) |
|---|
| 176 | p->encode=DestroyString(p->encode); |
|---|
| 177 | if (p->commands != (char *) NULL) |
|---|
| 178 | p->commands=DestroyString(p->commands); |
|---|
| 179 | p=(DelegateInfo *) RelinquishMagickMemory(p); |
|---|
| 180 | return((void *) NULL); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | MagickExport void DestroyDelegateList(void) |
|---|
| 185 | { |
|---|
| 186 | AcquireSemaphoreInfo(&delegate_semaphore); |
|---|
| 187 | if (delegate_list != (LinkedListInfo *) NULL) |
|---|
| 188 | delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate); |
|---|
| 189 | instantiate_delegate=MagickFalse; |
|---|
| 190 | RelinquishSemaphoreInfo(delegate_semaphore); |
|---|
| 191 | DestroySemaphoreInfo(&delegate_semaphore); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image, |
|---|
| 232 | const char *decode,const char *encode,ExceptionInfo *exception) |
|---|
| 233 | { |
|---|
| 234 | char |
|---|
| 235 | *command, |
|---|
| 236 | **commands; |
|---|
| 237 | |
|---|
| 238 | const DelegateInfo |
|---|
| 239 | *delegate_info; |
|---|
| 240 | |
|---|
| 241 | register long |
|---|
| 242 | i; |
|---|
| 243 | |
|---|
| 244 | assert(image_info != (ImageInfo *) NULL); |
|---|
| 245 | assert(image_info->signature == MagickSignature); |
|---|
| 246 | assert(image != (Image *) NULL); |
|---|
| 247 | assert(image->signature == MagickSignature); |
|---|
| 248 | if (image->debug != MagickFalse) |
|---|
| 249 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 250 | delegate_info=GetDelegateInfo(decode,encode,exception); |
|---|
| 251 | if (delegate_info == (const DelegateInfo *) NULL) |
|---|
| 252 | { |
|---|
| 253 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
|---|
| 254 | "NoTagFound","`%s'",decode ? decode : encode); |
|---|
| 255 | return((char *) NULL); |
|---|
| 256 | } |
|---|
| 257 | commands=StringToList(delegate_info->commands); |
|---|
| 258 | if (commands == (char **) NULL) |
|---|
| 259 | { |
|---|
| 260 | (void) ThrowMagickException(exception,GetMagickModule(), |
|---|
| 261 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
|---|
| 262 | decode ? decode : encode); |
|---|
| 263 | return((char *) NULL); |
|---|
| 264 | } |
|---|
| 265 | command=InterpretImageProperties(image_info,image,commands[0]); |
|---|
| 266 | if (command == (char *) NULL) |
|---|
| 267 | (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, |
|---|
| 268 | "MemoryAllocationFailed","`%s'",commands[0]); |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | for (i=0; commands[i] != (char *) NULL; i++) |
|---|
| 273 | commands[i]=DestroyString(commands[i]); |
|---|
| 274 | commands=(char **) RelinquishMagickMemory(commands); |
|---|
| 275 | return(command); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info) |
|---|
| 301 | { |
|---|
| 302 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 303 | assert(delegate_info != (DelegateInfo *) NULL); |
|---|
| 304 | assert(delegate_info->signature == MagickSignature); |
|---|
| 305 | return(delegate_info->commands); |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, |
|---|
| 338 | const char *encode,ExceptionInfo *exception) |
|---|
| 339 | { |
|---|
| 340 | register const DelegateInfo |
|---|
| 341 | *p; |
|---|
| 342 | |
|---|
| 343 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 344 | if ((delegate_list == (LinkedListInfo *) NULL) || |
|---|
| 345 | (instantiate_delegate == MagickFalse)) |
|---|
| 346 | if (InitializeDelegateList(exception) == MagickFalse) |
|---|
| 347 | return((const DelegateInfo *) NULL); |
|---|
| 348 | if ((delegate_list == (LinkedListInfo *) NULL) || |
|---|
| 349 | (IsLinkedListEmpty(delegate_list) != MagickFalse)) |
|---|
| 350 | return((const DelegateInfo *) NULL); |
|---|
| 351 | if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0)) |
|---|
| 352 | return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0)); |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | AcquireSemaphoreInfo(&delegate_semaphore); |
|---|
| 357 | ResetLinkedListIterator(delegate_list); |
|---|
| 358 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 359 | while (p != (const DelegateInfo *) NULL) |
|---|
| 360 | { |
|---|
| 361 | if (p->mode > 0) |
|---|
| 362 | { |
|---|
| 363 | if (LocaleCompare(p->decode,decode) == 0) |
|---|
| 364 | break; |
|---|
| 365 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 366 | continue; |
|---|
| 367 | } |
|---|
| 368 | if (p->mode < 0) |
|---|
| 369 | { |
|---|
| 370 | if (LocaleCompare(p->encode,encode) == 0) |
|---|
| 371 | break; |
|---|
| 372 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 373 | continue; |
|---|
| 374 | } |
|---|
| 375 | if (LocaleCompare(decode,p->decode) == 0) |
|---|
| 376 | if (LocaleCompare(encode,p->encode) == 0) |
|---|
| 377 | break; |
|---|
| 378 | if (LocaleCompare(decode,"*") == 0) |
|---|
| 379 | if (LocaleCompare(encode,p->encode) == 0) |
|---|
| 380 | break; |
|---|
| 381 | if (LocaleCompare(decode,p->decode) == 0) |
|---|
| 382 | if (LocaleCompare(encode,"*") == 0) |
|---|
| 383 | break; |
|---|
| 384 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 385 | } |
|---|
| 386 | if (p != (const DelegateInfo *) NULL) |
|---|
| 387 | (void) InsertValueInLinkedList(delegate_list,0, |
|---|
| 388 | RemoveElementByValueFromLinkedList(delegate_list,p)); |
|---|
| 389 | RelinquishSemaphoreInfo(delegate_semaphore); |
|---|
| 390 | return(p); |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 423 | extern "C" { |
|---|
| 424 | #endif |
|---|
| 425 | |
|---|
| 426 | static int DelegateInfoCompare(const void *x,const void *y) |
|---|
| 427 | { |
|---|
| 428 | const DelegateInfo |
|---|
| 429 | **p, |
|---|
| 430 | **q; |
|---|
| 431 | |
|---|
| 432 | p=(const DelegateInfo **) x, |
|---|
| 433 | q=(const DelegateInfo **) y; |
|---|
| 434 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
|---|
| 435 | { |
|---|
| 436 | if ((*p)->decode == (char *) NULL) |
|---|
| 437 | if (((*p)->encode != (char *) NULL) && |
|---|
| 438 | ((*q)->encode != (char *) NULL)) |
|---|
| 439 | return(strcmp((*p)->encode,(*q)->encode)); |
|---|
| 440 | if (((*p)->decode != (char *) NULL) && |
|---|
| 441 | ((*q)->decode != (char *) NULL)) |
|---|
| 442 | return(strcmp((*p)->decode,(*q)->decode)); |
|---|
| 443 | } |
|---|
| 444 | return(LocaleCompare((*p)->path,(*q)->path)); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 448 | } |
|---|
| 449 | #endif |
|---|
| 450 | |
|---|
| 451 | MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern, |
|---|
| 452 | unsigned long *number_delegates,ExceptionInfo *exception) |
|---|
| 453 | { |
|---|
| 454 | const DelegateInfo |
|---|
| 455 | **delegates; |
|---|
| 456 | |
|---|
| 457 | register const DelegateInfo |
|---|
| 458 | *p; |
|---|
| 459 | |
|---|
| 460 | register long |
|---|
| 461 | i; |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | assert(pattern != (char *) NULL); |
|---|
| 467 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
|---|
| 468 | assert(number_delegates != (unsigned long *) NULL); |
|---|
| 469 | *number_delegates=0; |
|---|
| 470 | p=GetDelegateInfo("*","*",exception); |
|---|
| 471 | if (p == (const DelegateInfo *) NULL) |
|---|
| 472 | return((const DelegateInfo **) NULL); |
|---|
| 473 | delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t) |
|---|
| 474 | GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates)); |
|---|
| 475 | if (delegates == (const DelegateInfo **) NULL) |
|---|
| 476 | return((const DelegateInfo **) NULL); |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | AcquireSemaphoreInfo(&delegate_semaphore); |
|---|
| 481 | ResetLinkedListIterator(delegate_list); |
|---|
| 482 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 483 | for (i=0; p != (const DelegateInfo *) NULL; ) |
|---|
| 484 | { |
|---|
| 485 | if ((p->stealth == MagickFalse) && |
|---|
| 486 | ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) || |
|---|
| 487 | (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))) |
|---|
| 488 | delegates[i++]=p; |
|---|
| 489 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 490 | } |
|---|
| 491 | RelinquishSemaphoreInfo(delegate_semaphore); |
|---|
| 492 | qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare); |
|---|
| 493 | delegates[i]=(DelegateInfo *) NULL; |
|---|
| 494 | *number_delegates=(unsigned long) i; |
|---|
| 495 | return(delegates); |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 529 | extern "C" { |
|---|
| 530 | #endif |
|---|
| 531 | |
|---|
| 532 | static int DelegateCompare(const void *x,const void *y) |
|---|
| 533 | { |
|---|
| 534 | register const char |
|---|
| 535 | **p, |
|---|
| 536 | **q; |
|---|
| 537 | |
|---|
| 538 | p=(const char **) x; |
|---|
| 539 | q=(const char **) y; |
|---|
| 540 | return(LocaleCompare(*p,*q)); |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 544 | } |
|---|
| 545 | #endif |
|---|
| 546 | |
|---|
| 547 | MagickExport char **GetDelegateList(const char *pattern, |
|---|
| 548 | unsigned long *number_delegates,ExceptionInfo *exception) |
|---|
| 549 | { |
|---|
| 550 | char |
|---|
| 551 | **delegates; |
|---|
| 552 | |
|---|
| 553 | register const DelegateInfo |
|---|
| 554 | *p; |
|---|
| 555 | |
|---|
| 556 | register long |
|---|
| 557 | i; |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | assert(pattern != (char *) NULL); |
|---|
| 563 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
|---|
| 564 | assert(number_delegates != (unsigned long *) NULL); |
|---|
| 565 | *number_delegates=0; |
|---|
| 566 | p=GetDelegateInfo("*","*",exception); |
|---|
| 567 | if (p == (const DelegateInfo *) NULL) |
|---|
| 568 | return((char **) NULL); |
|---|
| 569 | delegates=(char **) AcquireQuantumMemory((size_t) |
|---|
| 570 | GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates)); |
|---|
| 571 | if (delegates == (char **) NULL) |
|---|
| 572 | return((char **) NULL); |
|---|
| 573 | AcquireSemaphoreInfo(&delegate_semaphore); |
|---|
| 574 | ResetLinkedListIterator(delegate_list); |
|---|
| 575 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 576 | for (i=0; p != (const DelegateInfo *) NULL; ) |
|---|
| 577 | { |
|---|
| 578 | if ((p->stealth == MagickFalse) && |
|---|
| 579 | (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse)) |
|---|
| 580 | delegates[i++]=ConstantString(p->decode); |
|---|
| 581 | if ((p->stealth == MagickFalse) && |
|---|
| 582 | (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)) |
|---|
| 583 | delegates[i++]=ConstantString(p->encode); |
|---|
| 584 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
|---|
| 585 | } |
|---|
| 586 | RelinquishSemaphoreInfo(delegate_semaphore); |
|---|
| 587 | qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare); |
|---|
| 588 | delegates[i]=(char *) NULL; |
|---|
| 589 | *number_delegates=(unsigned long) i; |
|---|
| 590 | return(delegates); |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | MagickExport long GetDelegateMode(const DelegateInfo *delegate_info) |
|---|
| 616 | { |
|---|
| 617 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 618 | assert(delegate_info != (DelegateInfo *) NULL); |
|---|
| 619 | assert(delegate_info->signature == MagickSignature); |
|---|
| 620 | return(delegate_info->mode); |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | MagickExport MagickBooleanType GetDelegateThreadSupport( |
|---|
| 648 | const DelegateInfo *delegate_info) |
|---|
| 649 | { |
|---|
| 650 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 651 | assert(delegate_info != (DelegateInfo *) NULL); |
|---|
| 652 | assert(delegate_info->signature == MagickSignature); |
|---|
| 653 | return(delegate_info->thread_support); |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | |
|---|
| 676 | |
|---|
| 677 | |
|---|
| 678 | static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception) |
|---|
| 679 | { |
|---|
| 680 | if ((delegate_list == (LinkedListInfo *) NULL) && |
|---|
| 681 | (instantiate_delegate == MagickFalse)) |
|---|
| 682 | { |
|---|
| 683 | AcquireSemaphoreInfo(&delegate_semaphore); |
|---|
| 684 | if ((delegate_list == (LinkedListInfo *) NULL) && |
|---|
| 685 | (instantiate_delegate == MagickFalse)) |
|---|
| 686 | { |
|---|
| 687 | (void) LoadDelegateLists(DelegateFilename,exception); |
|---|
| 688 | instantiate_delegate=MagickTrue; |
|---|
| 689 | } |
|---|
| 690 | RelinquishSemaphoreInfo(delegate_semaphore); |
|---|
| 691 | } |
|---|
| 692 | return(delegate_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); |
|---|
| 693 | } |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | static inline size_t MagickMin(const size_t x,const size_t y) |
|---|
| 726 | { |
|---|
| 727 | if (x < y) |
|---|
| 728 | return(x); |
|---|
| 729 | return(y); |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | static MagickBooleanType CopyDelegateFile(const char *source, |
|---|
| 733 | const char *destination) |
|---|
| 734 | { |
|---|
| 735 | int |
|---|
| 736 | destination_file, |
|---|
| 737 | source_file; |
|---|
| 738 | |
|---|
| 739 | MagickBooleanType |
|---|
| 740 | status; |
|---|
| 741 | |
|---|
| 742 | register size_t |
|---|
| 743 | i; |
|---|
| 744 | |
|---|
| 745 | size_t |
|---|
| 746 | length, |
|---|
| 747 | quantum; |
|---|
| 748 | |
|---|
| 749 | ssize_t |
|---|
| 750 | count; |
|---|
| 751 | |
|---|
| 752 | struct stat |
|---|
| 753 | attributes; |
|---|
| 754 | |
|---|
| 755 | unsigned char |
|---|
| 756 | *buffer; |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | assert(source != (const char *) NULL); |
|---|
| 762 | assert(destination != (char *) NULL); |
|---|
| 763 | status=GetPathAttributes(destination,&attributes); |
|---|
| 764 | if ((status != MagickFalse) && (attributes.st_size != 0)) |
|---|
| 765 | return(MagickTrue); |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE); |
|---|
| 770 | if (destination_file == -1) |
|---|
| 771 | return(MagickFalse); |
|---|
| 772 | source_file=open(source,O_RDONLY | O_BINARY); |
|---|
| 773 | if (source_file == -1) |
|---|
| 774 | { |
|---|
| 775 | (void) close(destination_file); |
|---|
| 776 | return(MagickFalse); |
|---|
| 777 | } |
|---|
| 778 | quantum=(size_t) MagickMaxBufferExtent; |
|---|
| 779 | if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0)) |
|---|
| 780 | quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent); |
|---|
| 781 | buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer)); |
|---|
| 782 | if (buffer == (unsigned char *) NULL) |
|---|
| 783 | { |
|---|
| 784 | (void) close(source_file); |
|---|
| 785 | (void) close(destination_file); |
|---|
| 786 | return(MagickFalse); |
|---|
| 787 | } |
|---|
| 788 | length=0; |
|---|
| 789 | for (i=0; ; i+=count) |
|---|
| 790 | { |
|---|
| 791 | count=(ssize_t) read(source_file,buffer,quantum); |
|---|
| 792 | if (count <= 0) |
|---|
| 793 | break; |
|---|
| 794 | length=(size_t) count; |
|---|
| 795 | count=(ssize_t) write(destination_file,buffer,length); |
|---|
| 796 | if ((size_t) count != length) |
|---|
| 797 | break; |
|---|
| 798 | } |
|---|
| 799 | (void) close(destination_file); |
|---|
| 800 | (void) close(source_file); |
|---|
| 801 | buffer=(unsigned char *) RelinquishMagickMemory(buffer); |
|---|
| 802 | return(i != 0 ? MagickTrue : MagickFalse); |
|---|
| 803 | } |
|---|
| 804 | |
|---|
| 805 | MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, |
|---|
| 806 | Image *image,const char *decode,const char *encode,ExceptionInfo *exception) |
|---|
| 807 | { |
|---|
| 808 | char |
|---|
| 809 | *command, |
|---|
| 810 | **commands, |
|---|
| 811 | input_filename[MaxTextExtent], |
|---|
| 812 | output_filename[MaxTextExtent]; |
|---|
| 813 | |
|---|
| 814 | const DelegateInfo |
|---|
| 815 | *delegate_info; |
|---|
| 816 | |
|---|
| 817 | register long |
|---|
| 818 | i; |
|---|
| 819 | |
|---|
| 820 | MagickBooleanType |
|---|
| 821 | status, |
|---|
| 822 | temporary; |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | |
|---|
| 826 | |
|---|
| 827 | assert(image_info != (ImageInfo *) NULL); |
|---|
| 828 | assert(image_info->signature == MagickSignature); |
|---|
| 829 | assert(image != (Image *) NULL); |
|---|
| 830 | assert(image->signature == MagickSignature); |
|---|
| 831 | if (image->debug != MagickFalse) |
|---|
| 832 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 833 | temporary=(*image->filename == '\0') ? MagickTrue : MagickFalse; |
|---|
| 834 | if (temporary != MagickFalse) |
|---|
| 835 | if (AcquireUniqueFilename(image->filename) == MagickFalse) |
|---|
| 836 | { |
|---|
| 837 | ThrowFileException(exception,FileOpenError, |
|---|
| 838 | "UnableToCreateTemporaryFile",image->filename); |
|---|
| 839 | return(MagickFalse); |
|---|
| 840 | } |
|---|
| 841 | delegate_info=GetDelegateInfo(decode,encode,exception); |
|---|
| 842 | if (delegate_info == (DelegateInfo *) NULL) |
|---|
| 843 | { |
|---|
| 844 | if (temporary != MagickFalse) |
|---|
| 845 | (void) RelinquishUniqueFileResource(image->filename); |
|---|
| 846 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
|---|
| 847 | "NoTagFound","`%s'",decode ? decode : encode); |
|---|
| 848 | return(MagickFalse); |
|---|
| 849 | } |
|---|