summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmagick/Image.d27
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