From e48e1f4f081a2c84addc604136c4383bb92de8c6 Mon Sep 17 00:00:00 2001
From: Mike Wey
Date: Sat, 13 Aug 2011 16:08:22 +0200
Subject: Implement setting the progress monitor.
---
dmagick/Image.d | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--
dmagick/ImageView.d | 4 ++--
2 files changed, 54 insertions(+), 4 deletions(-)
(limited to 'dmagick')
diff --git a/dmagick/Image.d b/dmagick/Image.d
index 50c56a7..2bd2cd3 100644
--- a/dmagick/Image.d
+++ b/dmagick/Image.d
@@ -2,6 +2,15 @@
* Copyright: Mike Wey 2011
* License: zlib (See accompanying LICENSE file)
* Authors: Mike Wey
+ *
+ * Macros:
+ * TABLE=
+ *
+ * TH=$1 | $(TH $+)
+ * HEADERS=$(TH $1, $+)
+ *
+ * TD=$1 | $(TD $+)
+ * ROW=$(TD $1, $+)
*/
module dmagick.Image;
@@ -36,6 +45,8 @@ class Image
ImageRef imageRef;
Options options; ///The options for this image.
+ private bool delegate(string, long, ulong) progressMonitor;
+
///
this()
{
@@ -2601,8 +2612,6 @@ class Image
imageRef = ImageRef(image);
}
- //TODO: set process monitor.
-
/**
* Splice the background color into the image as defined by the geometry.
* This method is the opposite of chop.
@@ -3754,6 +3763,46 @@ class Image
return depth;
}
+ /**
+ * Establish a progress monitor. Most Image and ImageList methods
+ * will periodically call the monitor with arguments indicating the
+ * progress of the method.
+ *
+ * The delegate receves the folowing params: $(BR)
+ * $(TABLE
+ * $(ROW string $(I methodName), The name of the monitored method.)
+ * $(ROW long $(I offset ), A number between 0 and extent that
+ * identifies how much of the operation has been completed
+ * (or, in some cases, remains to be completed).)
+ * $(ROW ulong $(I extent ), The number of quanta needed to
+ * complete the operation.)
+ * )
+ */
+ void monitor(bool delegate(string methodName, long offset, ulong extent) progressMonitor)
+ {
+ if ( this.progressMonitor is null )
+ SetImageProgressMonitor(imageRef, cast(MagickProgressMonitor)&ImageProgressMonitor, cast(void*)this);
+
+ this.progressMonitor = progressMonitor;
+
+ if ( progressMonitor is null )
+ SetImageProgressMonitor(imageRef, null, null);
+ }
+ ///ditto
+ bool delegate(string, long, ulong) monitor()
+ {
+ return progressMonitor;
+ }
+
+ static extern(C) MagickBooleanType ImageProgressMonitor(
+ const(char)* methodName,
+ MagickOffsetType offset,
+ MagickSizeType extend,
+ Image image)
+ {
+ return image.progressMonitor(to!(string)(methodName), offset, extend);
+ }
+
/**
* Tile size and offset within an image montage.
* Only valid for images produced by montage.
@@ -4067,3 +4116,4 @@ version (Windows)
}
}
+
diff --git a/dmagick/ImageView.d b/dmagick/ImageView.d
index 2428b24..61600b9 100644
--- a/dmagick/ImageView.d
+++ b/dmagick/ImageView.d
@@ -165,10 +165,10 @@ class ImageView
if ( result )
return result;
- if ( image.imageRef.progress_monitor !is null )
+ if ( image.monitor !is null )
{
atomicOp!"+="(progress, 1);
- image.imageRef.progress_monitor(toStringz("ImageView/" ~ image.filename), progress, extent.height, image.imageRef.client_data);
+ image.monitor()("ImageView/" ~ image.filename, progress, extent.height);
}
}
--
cgit v1.2.3