summaryrefslogtreecommitdiff
path: root/dmagick
diff options
context:
space:
mode:
authorMike Wey2011-11-03 19:42:57 +0100
committerMike Wey2011-11-03 19:42:57 +0100
commit447d1555701e6c219f81d9cdd1798440546dcd0e (patch)
tree2658c8fe3da15b137b80945b91a51995481e6de4 /dmagick
parent1f826aaefce18d47e66b32f9cfaa5f9a109e7f26 (diff)
Merge the changes from Andrej Mitovic. https://github.com/AndrejMitrovic/DMagickSamples
Diffstat (limited to 'dmagick')
-rw-r--r--dmagick/Image.d48
1 files changed, 39 insertions, 9 deletions
diff --git a/dmagick/Image.d b/dmagick/Image.d
index 9caf0de..cce3d77 100644
--- a/dmagick/Image.d
+++ b/dmagick/Image.d
@@ -233,7 +233,7 @@ class Image
* $(B blob size) if present.
* )
*/
- string toString()
+ override string toString()
{
string result;
@@ -253,7 +253,7 @@ class Image
if ( imageRef.page.width > 0 || imageRef.page.height > 0
|| imageRef.page.x != 0 || imageRef.page.y != 0 )
{
- result ~= std.string.format("%sx%s%+ld%+ld ",
+ result ~= std.string.format("%sx%s%+s%+s ",
imageRef.page.width, imageRef.page.height,
imageRef.page.x, imageRef.page.y);
}
@@ -263,7 +263,7 @@ class Image
else
result ~= "PseudoClass ";
- result = std.string.format("%s-bit", GetImageQuantumDepth(imageRef, true));
+ result = std.string.format("%s-bit ", GetImageQuantumDepth(imageRef, true));
//Size of the image.
MagickSizeType size = GetBlobSize(imageRef);
@@ -1330,16 +1330,46 @@ class Image
T[] exportPixels(T)(Geometry area, string map = "RGBA") const
{
StorageType storage = getStorageType!(T);
- void[] pixels = new T[area.width*area.height];
-
- ExportImagePixels(imageRef,
- area.xOffset, area.yOffset,
- area.width, area.height,
- toStringz(map), storage, pixels.ptr, DMagickExceptionInfo());
+ void[] 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());
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 )
+ throw new ImageException(format("Pixel buffer needs more storage for %s channels.", map));
+
+ StorageType storage = getStorageType!(T);
+
+ ExportImagePixels(
+ imageRef,
+ area.xOffset,
+ area.yOffset,
+ area.width,
+ area.height,
+ toStringz(map),
+ storage,
+ pixels.ptr,
+ DMagickExceptionInfo());
+ }
+
/**
* If the Geometry is larger than this Image, extends the image to
* the specified geometry. And the new pixels are set to the