1 /** 2 * Copyright: Mike Wey 2011 3 * License: zlib (See accompanying LICENSE file) 4 * Authors: Mike Wey 5 */ 6 7 module dmagick.CoderInfo; 8 9 import std.conv; 10 import std..string; 11 12 import dmagick.Exception; 13 14 import dmagick.c.magick; 15 16 /** 17 * This provides information about the image formats supported by 18 * Imagemagick. The MatchType determines if a coder should be returned 19 * in the array. MatchType.Any matches both MatchType.True 20 * and MatchType.True. 21 * 22 * Params: 23 * readable = Does the coder need to provide read support. 24 * writable = Does the coder need to provide write support. 25 * multiFrame = Does the coder need to provide multi frame support. 26 */ 27 CoderInfo[] coderInfoList(MatchType readable, MatchType writable, MatchType multiFrame) 28 { 29 size_t length; 30 CoderInfo[] list; 31 32 const(MagickInfo)*[] infoList = 33 GetMagickInfoList("*", &length, DMagickExceptionInfo())[0 .. length]; 34 35 foreach ( info; infoList ) 36 { 37 CoderInfo coder = CoderInfo(info); 38 39 if ( readable == MatchType.False && coder.readable ) 40 continue; 41 42 if ( readable == MatchType.True && !coder.readable ) 43 continue; 44 45 if ( writable == MatchType.False && coder.writable ) 46 continue; 47 48 if ( writable == MatchType.True && !coder.writable ) 49 continue; 50 51 if ( multiFrame == MatchType.False && coder.supportsMultiFrame ) 52 continue; 53 54 if ( multiFrame == MatchType.True && !coder.supportsMultiFrame ) 55 continue; 56 57 list ~= coder; 58 } 59 60 return list; 61 } 62 63 /** 64 * CoderInfo provides the means to get information regarding ImageMagick 65 * support for an image format (designated by a magick string). It may be 66 * used to provide information for a specific named format (provided as an 67 * argument to the constructor). 68 */ 69 struct CoderInfo 70 { 71 /** 72 * Format name. (e.g. "GIF") 73 */ 74 string name; 75 76 /** 77 * Format description. (e.g. "CompuServe graphics interchange format") 78 */ 79 string description; 80 81 /** 82 * Format is readable. 83 */ 84 bool readable; 85 86 /** 87 * Format is writable. 88 */ 89 bool writable; 90 91 /** 92 * Format supports multiple frames. 93 */ 94 bool supportsMultiFrame; 95 96 97 /** 98 * Construct object corresponding to named format. (e.g. "GIF") 99 */ 100 this (string format) 101 { 102 const(MagickInfo)* info = 103 GetMagickInfo(toStringz(format), DMagickExceptionInfo()); 104 105 this(info); 106 } 107 108 this (const(MagickInfo)* info) 109 { 110 name = to!(string)(info.name); 111 description = to!(string)(info.description); 112 readable = info.decoder !is null; 113 writable = info.encoder !is null; 114 supportsMultiFrame = info.adjoin != 0; 115 } 116 } 117 118 /// 119 enum MatchType 120 { 121 Any, /// Don't care. 122 True, /// Matches. 123 False /// Doesn't match. 124 }