diff options
| author | Mike Wey | 2011-11-05 13:08:11 +0100 |
|---|---|---|
| committer | Mike Wey | 2011-11-05 13:08:11 +0100 |
| commit | 5d592fd050bad55ef7ee1d3d471ffbbc2f26261b (patch) | |
| tree | 35db95bc85c6bab35841ed01fa4ef6d7b6cb9cdd | |
| parent | 344ea66f0bcac5b20a0e824fbf105c9473efc7b3 (diff) | |
Refactor exportPixels a little.
| -rw-r--r-- | dmagick/Image.d | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/dmagick/Image.d b/dmagick/Image.d index 2303676..4a173a7 100644 --- a/dmagick/Image.d +++ b/dmagick/Image.d @@ -1330,30 +1330,21 @@ class Image T[] exportPixels(T)(Geometry area, string map = "RGBA") const { StorageType storage = getStorageType!(T); - void[] pixels = new T[(area.width * area.height) * map.length]; + T[] pixels = new T[(area.width * area.height) * map.length]; - ExportImagePixels( - imageRef, - area.xOffset, - area.yOffset, - area.width, - area.height, - toStringz(map), - storage, - pixels.ptr, - DMagickExceptionInfo()); + exportPixels(area, pixels, map); - return cast(typeof(return))pixels; + return pixels; } - /* + /** * Ditto, but takes an existing pixel buffer. Does a runtime check * on the length of the buffer, if the buffer length is insufficient * it throws an ImageException. */ void exportPixels(T)(Geometry area, T[] pixels, string map = "RGBA") const { - if ( pixels.length < (area.width * area.height) * map.count ) + if ( pixels.length < (area.width * area.height) * map.length ) throw new ImageException(std.string.format("Pixel buffer needs more storage for %s channels.", map)); StorageType storage = getStorageType!(T); @@ -1370,6 +1361,14 @@ class Image DMagickExceptionInfo()); } + unittest + { + Image image = new Image(Geometry(100, 100), new Color("red")); + byte[] bytes = image.exportPixels!(byte)(Geometry(10,10,10,10)); + + assert(bytes.length == 10 * 10 * 4); + } + /** * If the Geometry is larger than this Image, extends the image to * the specified geometry. And the new pixels are set to the |
