diff options
| author | Mike Wey | 2011-10-01 17:59:49 +0200 |
|---|---|---|
| committer | Mike Wey | 2011-10-01 17:59:49 +0200 |
| commit | 93dbb3b6d6ddc3b581e7228c1a9f34a98f1a548e (patch) | |
| tree | 283f77f4ec67df7819b43b80ca73ea6a0b775671 | |
| parent | 2bfdc7b8ea45cfebc450ae355690b11bcc1017a5 (diff) | |
Add dmagick.CoderInfo.
| -rw-r--r-- | dmagick/CoderInfo.d | 115 | ||||
| -rw-r--r-- | dmagick/ImageView.d | 1 | ||||
| -rw-r--r-- | docs/dmagick.ddoc | 1 |
3 files changed, 116 insertions, 1 deletions
diff --git a/dmagick/CoderInfo.d b/dmagick/CoderInfo.d new file mode 100644 index 0000000..e003763 --- /dev/null +++ b/dmagick/CoderInfo.d @@ -0,0 +1,115 @@ +/** + * Copyright: Mike Wey 2011 + * License: zlib (See accompanying LICENSE file) + * Authors: Mike Wey + */ + +module dmagick.CoderInfo; + +import std.conv; +import std.string; + +import dmagick.Exception; + +import dmagick.c.magick; + +/** + * This provides information about the image formats supported by + * Imagemagick. The MatchType determines if a coder should be returned + * in the array. MatchType.Any matches both MatchType.True + * and MatchType.True. + * + * Params: + * readable = Does the coder need to provide read support. + * writable = Does the coder need to provide write support. + * multiFrame = Does the coder need to provide multi frame support. + */ +CoderInfo[] coderInfoList(MatchType readable, MatchType writable, MatchType multiFrame) +{ + size_t length; + CoderInfo[] list; + + const(MagickInfo)*[] infoList = + GetMagickInfoList("*", &length, DMagickExceptionInfo())[0 .. length]; + + foreach ( info; infoList ) + { + CoderInfo coder = CoderInfo(info); + + if ( readable == MatchType.False && coder.readable ) + continue; + + if ( writable == MatchType.False && coder.writable ) + continue; + + if ( multiFrame == MatchType.False && coder.supportsMultiFrame ) + continue; + + list ~= coder; + } + + return list; +} + +/** + * CoderInfo provides the means to get information regarding ImageMagick + * support for an image format (designated by a magick string). It may be + * used to provide information for a specific named format (provided as an + * argument to the constructor). + */ +struct CoderInfo +{ + /** + * Format name. (e.g. "GIF") + */ + string name; + + /** + * Format description. (e.g. "CompuServe graphics interchange format") + */ + string description; + + /** + * Format is readable. + */ + bool readable; + + /** + * Format is writable. + */ + bool writable; + + /** + * Format supports multiple frames. + */ + bool supportsMultiFrame; + + + /** + * Construct object corresponding to named format. (e.g. "GIF") + */ + this (string format) + { + const(MagickInfo)* info = + GetMagickInfo(toStringz(format), DMagickExceptionInfo()); + + this(info); + } + + this (const(MagickInfo)* info) + { + name = to!(string)(info.name); + description = to!(string)(info.description); + readable = info.decoder !is null; + writable = info.encoder !is null; + supportsMultiFrame = info.adjoin != 0; + } +} + +/// +enum MatchType +{ + Any, /// Don't care. + True, /// Matches. + False /// Doesn't match. +} diff --git a/dmagick/ImageView.d b/dmagick/ImageView.d index 79b39c4..567e0de 100644 --- a/dmagick/ImageView.d +++ b/dmagick/ImageView.d @@ -153,7 +153,6 @@ class ImageView * Support the usage of foreach to loop over the rows in the view. * The foreach is executed in parallel. */ - //TODO: Should the foreach be parallel? int opApply(int delegate(ref Pixels) dg) { shared(int) progress; diff --git a/docs/dmagick.ddoc b/docs/dmagick.ddoc index ab7f726..afe58fc 100644 --- a/docs/dmagick.ddoc +++ b/docs/dmagick.ddoc @@ -31,6 +31,7 @@ NAVIGATION = $(LIST $(NAVLINK Array), + $(NAVLINK Coderinfo), $(NAVLINK Color), $(NAVLINK ColorCMYK), $(NAVLINK ColorGray), |
