diff options
| author | Mike Wey | 2011-09-17 17:46:28 +0200 |
|---|---|---|
| committer | Mike Wey | 2011-09-17 17:46:28 +0200 |
| commit | 9d2ddc506ef3ad96a545539ef56cb3a3c9033cc4 (patch) | |
| tree | 12c22727e849b1e6a5c88369f15af1fd2e0598e7 | |
| parent | 3535eb0887b805ce8e4538b3e91c290fbb596006 (diff) | |
Add animationDelay, animationIterrations, avarage, clone and display.
| -rw-r--r-- | dmagick/Array.d | 68 | ||||
| -rw-r--r-- | dmagick/Image.d | 14 |
2 files changed, 75 insertions, 7 deletions
diff --git a/dmagick/Array.d b/dmagick/Array.d index b80902b..cb538d6 100644 --- a/dmagick/Array.d +++ b/dmagick/Array.d @@ -8,6 +8,8 @@ module dmagick.Array; +import core.time; + import dmagick.Exception; import dmagick.Geometry; import dmagick.Image; @@ -15,7 +17,73 @@ import dmagick.Options; import dmagick.c.blob; import dmagick.c.constitute; +import dmagick.c.display; import dmagick.c.image : MagickCoreImage = Image; +import dmagick.c.statistic; + +/** + * Set the animationDelay for all images in the array. + */ +void animationDelay(Image[] images, Duration delay) +{ + size_t ticks = delay.total!"seconds"() * images[0].imageRef.ticks_per_second; + + foreach ( image; images ) + { + image.imageRef.delay = ticks; + } +} + +/** + * Number of iterations to loop an animation. + */ +void animationIterations(Image[] images, size_t iterations) +{ + images[0].animationIterations = iterations; +} + +/** + * Averages all the images together. Each image in the image must have + * the same width and height. + */ +Image average(Image[] images) +{ + linkImages(images); + scope(exit) unlinkImages(images); + + MagickCoreImage* image = + EvaluateImages(images[0].imageRef, MagickEvaluateOperator.MeanEvaluateOperator, DMagickExceptionInfo()); + + return new Image(image); +} + +/** + * Clone every image in the array. + */ +Image[] clone(const(Image)[] images) +{ + Image[] newImages = new Image[images.length]; + + foreach ( i, image; images ) + { + newImages[i] = image.clone(); + } + + return newImages; +} + +/** + * Repeatedly displays an image sequence to a X window screen. + */ +void display(Image[] images) +{ + linkImages(images); + scope(exit) unlinkImages(images); + + DisplayImages(images[0].options.imageInfo, images[0].imageRef); + + DMagickException.throwException(&(images[0].imageRef.exception)); +} /** * Read a multi frame Image by reading from the file or diff --git a/dmagick/Image.d b/dmagick/Image.d index c191a2b..f449011 100644 --- a/dmagick/Image.d +++ b/dmagick/Image.d @@ -12,6 +12,7 @@ import std.string; import std.typecons : Tuple; import core.memory; import core.runtime; +import core.time; import core.stdc.string; import core.sys.posix.sys.types; @@ -3076,18 +3077,17 @@ class Image } /** - * Number of ticks which must expire before displaying the - * next image in an animated sequence. The default number - * of ticks is 0. By default there are 100 ticks per second. + * Number time which must expire before displaying the + * next image in an animated sequence. */ - void animationDelay(ushort delay) + void animationDelay(Duration delay) { - imageRef.delay = delay; + imageRef.delay = delay.total!"seconds"() * imageRef.ticks_per_second; } ///ditto - ushort annimationDelay() const + Duration annimationDelay() const { - return cast(ushort)imageRef.delay; + return dur!"seconds"(imageRef.delay * imageRef.ticks_per_second); } /** |
