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 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'dmagick/Image.d') 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=$0
+ * + * 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) } } + -- cgit v1.2.3