diff --git a/src/ImageProcessor/Filters/Alpha.cs b/src/ImageProcessor/Filters/Alpha.cs
index 9607fcbb0..067fb3cc3 100644
--- a/src/ImageProcessor/Filters/Alpha.cs
+++ b/src/ImageProcessor/Filters/Alpha.cs
@@ -55,6 +55,7 @@ namespace ImageProcessor.Filters
color *= alphaVector;
target[x, y] = Color.FromNonPremultiplied(new Color(color));
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/BackgroundColor.cs b/src/ImageProcessor/Filters/BackgroundColor.cs
index f089cc2a6..1683f964c 100644
--- a/src/ImageProcessor/Filters/BackgroundColor.cs
+++ b/src/ImageProcessor/Filters/BackgroundColor.cs
@@ -65,6 +65,7 @@ namespace ImageProcessor.Filters
target[x, y] = color;
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Binarization/Threshold.cs b/src/ImageProcessor/Filters/Binarization/Threshold.cs
index a48ca5aa0..9e76a121f 100644
--- a/src/ImageProcessor/Filters/Binarization/Threshold.cs
+++ b/src/ImageProcessor/Filters/Binarization/Threshold.cs
@@ -75,6 +75,7 @@ namespace ImageProcessor.Filters
// Any channel will do since it's greyscale.
target[x, y] = color.B >= threshold ? upper : lower;
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Blend.cs b/src/ImageProcessor/Filters/Blend.cs
index 9447c93b3..3c2cb8405 100644
--- a/src/ImageProcessor/Filters/Blend.cs
+++ b/src/ImageProcessor/Filters/Blend.cs
@@ -69,6 +69,7 @@ namespace ImageProcessor.Filters
target[x, y] = color;
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs b/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs
index d63732751..40188950f 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs
@@ -39,6 +39,7 @@ namespace ImageProcessor.Filters
{
target[x, y] = this.ApplyMatrix(source[x, y], matrix);
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Contrast.cs b/src/ImageProcessor/Filters/Contrast.cs
index da55507ff..0b8e58ecf 100644
--- a/src/ImageProcessor/Filters/Contrast.cs
+++ b/src/ImageProcessor/Filters/Contrast.cs
@@ -57,6 +57,7 @@ namespace ImageProcessor.Filters
color += shiftVector;
target[x, y] = Color.Compress(new Color(color));
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Convolution/Convolution2DFilter.cs b/src/ImageProcessor/Filters/Convolution/Convolution2DFilter.cs
index effdb1a82..688895901 100644
--- a/src/ImageProcessor/Filters/Convolution/Convolution2DFilter.cs
+++ b/src/ImageProcessor/Filters/Convolution/Convolution2DFilter.cs
@@ -101,6 +101,7 @@ namespace ImageProcessor.Filters
Color targetColor = target[x, y];
target[x, y] = new Color(red, green, blue, targetColor.A);
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Convolution/Convolution2PassFilter.cs b/src/ImageProcessor/Filters/Convolution/Convolution2PassFilter.cs
index e1507544f..2ebddd490 100644
--- a/src/ImageProcessor/Filters/Convolution/Convolution2PassFilter.cs
+++ b/src/ImageProcessor/Filters/Convolution/Convolution2PassFilter.cs
@@ -104,6 +104,7 @@ namespace ImageProcessor.Filters
target[x, y] = destination;
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Convolution/ConvolutionFilter.cs b/src/ImageProcessor/Filters/Convolution/ConvolutionFilter.cs
index 124049db2..f34488503 100644
--- a/src/ImageProcessor/Filters/Convolution/ConvolutionFilter.cs
+++ b/src/ImageProcessor/Filters/Convolution/ConvolutionFilter.cs
@@ -76,6 +76,7 @@ namespace ImageProcessor.Filters
target[x, y] = new Color(red, green, blue);
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Glow.cs b/src/ImageProcessor/Filters/Glow.cs
index e87da3a25..313ea5f55 100644
--- a/src/ImageProcessor/Filters/Glow.cs
+++ b/src/ImageProcessor/Filters/Glow.cs
@@ -51,6 +51,7 @@ namespace ImageProcessor.Filters
Color sourceColor = target[x, y];
target[x, y] = Color.Lerp(glowColor, sourceColor, .5f * (distance / maxDistance));
}
+ this.OnRowProcessed();
});
}
}
diff --git a/src/ImageProcessor/Filters/Invert.cs b/src/ImageProcessor/Filters/Invert.cs
index ab6c827b3..fbdd27595 100644
--- a/src/ImageProcessor/Filters/Invert.cs
+++ b/src/ImageProcessor/Filters/Invert.cs
@@ -35,6 +35,7 @@ namespace ImageProcessor.Filters
Vector3 vector = inverseVector - color.ToVector3();
target[x, y] = new Color(vector, color.A);
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Pixelate.cs b/src/ImageProcessor/Filters/Pixelate.cs
index 7f3b17674..44d047f5a 100644
--- a/src/ImageProcessor/Filters/Pixelate.cs
+++ b/src/ImageProcessor/Filters/Pixelate.cs
@@ -85,6 +85,7 @@ namespace ImageProcessor.Filters
}
}
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Filters/Vignette.cs b/src/ImageProcessor/Filters/Vignette.cs
index 8d29af642..245456d86 100644
--- a/src/ImageProcessor/Filters/Vignette.cs
+++ b/src/ImageProcessor/Filters/Vignette.cs
@@ -51,6 +51,7 @@ namespace ImageProcessor.Filters
Color sourceColor = target[x, y];
target[x, y] = Color.Lerp(vignetteColor, sourceColor, 1 - .9f * distance / maxDistance);
}
+ this.OnRowProcessed();
});
}
}
diff --git a/src/ImageProcessor/IImageProcessor.cs b/src/ImageProcessor/IImageProcessor.cs
index 8e31c4e1d..7f1a60e8d 100644
--- a/src/ImageProcessor/IImageProcessor.cs
+++ b/src/ImageProcessor/IImageProcessor.cs
@@ -5,13 +5,18 @@
namespace ImageProcessor
{
- public struct ProgressedEventArgs
+ public class ProgressEventArgs : System.EventArgs
{
public int numRowsProcessed;
public int totalRows;
}
- public delegate void ProgressedEventHandler(object sender, ProgressedEventArgs e);
+ ///
+ /// A delegate which is called as progress is made processing the image.
+ ///
+ ///
+ ///
+ public delegate void ProgressEventHandler(object sender, ProgressEventArgs e);
///
/// Encapsulates methods to alter the pixels of an image.
@@ -25,7 +30,7 @@ namespace ImageProcessor
/// This event may be called from threads other than the client thread, and from multiple threads simultaneously.
/// Individual row notifications may arrived out of order.
///
- event ProgressedEventHandler OnProgressed;
+ event ProgressEventHandler OnProgress;
///
/// Applies the process to the specified portion of the specified .
diff --git a/src/ImageProcessor/ParallelImageProcessor.cs b/src/ImageProcessor/ParallelImageProcessor.cs
index 4f34dd61d..b9a843f43 100644
--- a/src/ImageProcessor/ParallelImageProcessor.cs
+++ b/src/ImageProcessor/ParallelImageProcessor.cs
@@ -15,7 +15,7 @@ namespace ImageProcessor
public abstract class ParallelImageProcessor : IImageProcessor
{
///
- public event ProgressedEventHandler OnProgressed;
+ public event ProgressEventHandler OnProgress;
///
/// Gets or sets the count of workers to run the process in parallel.
@@ -37,12 +37,16 @@ namespace ImageProcessor
///
protected void OnRowProcessed()
{
- if(this.OnProgressed != null)
+ if(this.OnProgress != null)
{
int currThreadNumRows = Interlocked.Add(ref this.numRowsProcessed, 1);
+ // Multi-pass filters process multiple times more rows than totalRows, so update totalRows on the fly
+ if (currThreadNumRows > this.totalRows)
+ this.totalRows = currThreadNumRows;
+
// Report progress. This may be on the client's thread, or on a Task library thread.
- this.OnProgressed(this, new ProgressedEventArgs { numRowsProcessed = currThreadNumRows, totalRows = this.totalRows });
+ this.OnProgress(this, new ProgressEventArgs { numRowsProcessed = currThreadNumRows, totalRows = this.totalRows });
}
}
diff --git a/src/ImageProcessor/Samplers/Crop.cs b/src/ImageProcessor/Samplers/Crop.cs
index bae7a8dd4..f34808671 100644
--- a/src/ImageProcessor/Samplers/Crop.cs
+++ b/src/ImageProcessor/Samplers/Crop.cs
@@ -31,6 +31,7 @@ namespace ImageProcessor.Samplers
{
target[x, y] = source[x, y];
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Samplers/EntropyCrop.cs b/src/ImageProcessor/Samplers/EntropyCrop.cs
index 3ef7f0453..d657d37eb 100644
--- a/src/ImageProcessor/Samplers/EntropyCrop.cs
+++ b/src/ImageProcessor/Samplers/EntropyCrop.cs
@@ -89,6 +89,7 @@ namespace ImageProcessor.Samplers
target[x, y] = source[offsetX, offsetY];
}
+ this.OnRowProcessed();
});
}
}
diff --git a/src/ImageProcessor/Samplers/ImageSampleExtensions.cs b/src/ImageProcessor/Samplers/ImageSampleExtensions.cs
index 30ae55c71..b00775335 100644
--- a/src/ImageProcessor/Samplers/ImageSampleExtensions.cs
+++ b/src/ImageProcessor/Samplers/ImageSampleExtensions.cs
@@ -16,10 +16,11 @@ namespace ImageProcessor.Samplers
/// The image to resize.
/// The target image width.
/// The target image height.
+ /// A delegate which is called as progress is made processing the image.
/// The
- public static Image Crop(this Image source, int width, int height)
+ public static Image Crop(this Image source, int width, int height, ProgressEventHandler progressHandler = null)
{
- return Crop(source, width, height, source.Bounds);
+ return Crop(source, width, height, source.Bounds, progressHandler);
}
///
@@ -35,8 +36,9 @@ namespace ImageProcessor.Samplers
///
/// The structure that specifies the portion of the image object to draw.
///
+ /// A delegate which is called as progress is made processing the image.
/// The
- public static Image Crop(this Image source, int width, int height, Rectangle sourceRectangle)
+ public static Image Crop(this Image source, int width, int height, Rectangle sourceRectangle, ProgressEventHandler progressHandler = null)
{
if (sourceRectangle.Width < width || sourceRectangle.Height < height)
{
@@ -45,7 +47,16 @@ namespace ImageProcessor.Samplers
source = source.Resize(sourceRectangle.Width, sourceRectangle.Height);
}
- return source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), new Crop());
+ var processor = new Crop();
+ processor.OnProgress += progressHandler;
+ try
+ {
+ return source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), processor);
+ }
+ finally
+ {
+ processor.OnProgress -= progressHandler;
+ }
}
///
@@ -53,10 +64,20 @@ namespace ImageProcessor.Samplers
///
/// The image to crop.
/// The threshold for entropic density.
+ /// A delegate which is called as progress is made processing the image.
/// The
- public static Image EntropyCrop(this Image source, float threshold = .5f)
+ public static Image EntropyCrop(this Image source, float threshold = .5f, ProgressEventHandler progressHandler = null)
{
- return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, new EntropyCrop(threshold));
+ var processor = new EntropyCrop(threshold);
+ processor.OnProgress += progressHandler;
+ try
+ {
+ return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor);
+ }
+ finally
+ {
+ processor.OnProgress -= progressHandler;
+ }
}
///
@@ -65,11 +86,12 @@ namespace ImageProcessor.Samplers
/// The image to resize.
/// The target image width.
/// The target image height.
+ /// A delegate which is called as progress is made processing the image.
/// The
/// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image
- public static Image Resize(this Image source, int width, int height)
+ public static Image Resize(this Image source, int width, int height, ProgressEventHandler progressHandler = null)
{
- return Resize(source, width, height, new BicubicResampler());
+ return Resize(source, width, height, new BicubicResampler(), progressHandler);
}
///
@@ -79,11 +101,12 @@ namespace ImageProcessor.Samplers
/// The target image width.
/// The target image height.
/// The to perform the resampling.
+ /// A delegate which is called as progress is made processing the image.
/// The
/// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image
- public static Image Resize(this Image source, int width, int height, IResampler sampler)
+ public static Image Resize(this Image source, int width, int height, IResampler sampler, ProgressEventHandler progressHandler = null)
{
- return Resize(source, width, height, sampler, source.Bounds);
+ return Resize(source, width, height, sampler, source.Bounds, progressHandler);
}
///
@@ -97,9 +120,10 @@ namespace ImageProcessor.Samplers
///
/// The structure that specifies the portion of the image object to draw.
///
+ /// A delegate which is called as progress is made processing the image.
/// The
/// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image
- public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle)
+ public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, ProgressEventHandler progressHandler = null)
{
if (width == 0 && height > 0)
{
@@ -111,7 +135,16 @@ namespace ImageProcessor.Samplers
height = source.Height * width / source.Width;
}
- return source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), new Resize(sampler));
+ var processor = new Resize(sampler);
+ processor.OnProgress += progressHandler;
+ try
+ {
+ return source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), processor);
+ }
+ finally
+ {
+ processor.OnProgress -= progressHandler;
+ }
}
///
@@ -119,10 +152,11 @@ namespace ImageProcessor.Samplers
///
/// The image to resize.
/// The angle in degrees to perform the rotation.
+ /// A delegate which is called as progress is made processing the image.
/// The
- public static Image Rotate(this Image source, float degrees)
+ public static Image Rotate(this Image source, float degrees, ProgressEventHandler progressHandler = null)
{
- return Rotate(source, degrees, new BicubicResampler());
+ return Rotate(source, degrees, new BicubicResampler(), progressHandler);
}
///
@@ -131,10 +165,20 @@ namespace ImageProcessor.Samplers
/// The image to resize.
/// The angle in degrees to perform the rotation.
/// The to perform the resampling.
+ /// A delegate which is called as progress is made processing the image.
/// The
- public static Image Rotate(this Image source, float degrees, IResampler sampler)
+ public static Image Rotate(this Image source, float degrees, IResampler sampler, ProgressEventHandler progressHandler = null)
{
- return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, new Rotate(sampler) { Angle = degrees });
+ var processor = new Rotate(sampler) { Angle = degrees };
+ processor.OnProgress += progressHandler;
+ try
+ {
+ return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor);
+ }
+ finally
+ {
+ processor.OnProgress -= progressHandler;
+ }
}
///
@@ -143,10 +187,20 @@ namespace ImageProcessor.Samplers
/// The image to resize.
/// The to perform the rotation.
/// The to perform the flip.
+ /// A delegate which is called as progress is made processing the image.
/// The
- public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType)
+ public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType, ProgressEventHandler progressHandler = null)
{
- return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, new RotateFlip(rotateType, flipType));
+ var processor = new RotateFlip(rotateType, flipType);
+ processor.OnProgress += progressHandler;
+ try
+ {
+ return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor);
+ }
+ finally
+ {
+ processor.OnProgress -= progressHandler;
+ }
}
}
}
diff --git a/src/ImageProcessor/Samplers/Resize.cs b/src/ImageProcessor/Samplers/Resize.cs
index b7eea3c7b..64061244e 100644
--- a/src/ImageProcessor/Samplers/Resize.cs
+++ b/src/ImageProcessor/Samplers/Resize.cs
@@ -81,6 +81,7 @@ namespace ImageProcessor.Samplers
target[x, y] = source[originX, originY];
}
+ this.OnRowProcessed();
}
});
@@ -141,6 +142,7 @@ namespace ImageProcessor.Samplers
destination = Color.Compress(destination);
target[x, y] = destination;
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Samplers/Rotate.cs b/src/ImageProcessor/Samplers/Rotate.cs
index 71eb174c1..97491387f 100644
--- a/src/ImageProcessor/Samplers/Rotate.cs
+++ b/src/ImageProcessor/Samplers/Rotate.cs
@@ -102,6 +102,7 @@ namespace ImageProcessor.Samplers
target[x, y] = source[rotated.X, rotated.Y];
}
}
+ this.OnRowProcessed();
}
});
@@ -152,6 +153,7 @@ namespace ImageProcessor.Samplers
destination = Color.Compress(destination);
target[x, y] = destination;
}
+ this.OnRowProcessed();
}
});
}
diff --git a/src/ImageProcessor/Samplers/RotateFlip.cs b/src/ImageProcessor/Samplers/RotateFlip.cs
index 4163e83eb..94478e112 100644
--- a/src/ImageProcessor/Samplers/RotateFlip.cs
+++ b/src/ImageProcessor/Samplers/RotateFlip.cs
@@ -73,7 +73,7 @@ namespace ImageProcessor.Samplers
///
/// The target image.
/// The source image.
- private static void Rotate270(ImageBase target, ImageBase source)
+ private void Rotate270(ImageBase target, ImageBase source)
{
int width = source.Width;
int height = source.Height;
@@ -90,6 +90,7 @@ namespace ImageProcessor.Samplers
newY = width - newY - 1;
temp[newX, newY] = source[x, y];
}
+ this.OnRowProcessed();
});
target.SetPixels(height, width, temp.Pixels);
@@ -100,7 +101,7 @@ namespace ImageProcessor.Samplers
///
/// The target image.
/// The source image.
- private static void Rotate180(ImageBase target, ImageBase source)
+ private void Rotate180(ImageBase target, ImageBase source)
{
int width = source.Width;
int height = source.Height;
@@ -114,6 +115,7 @@ namespace ImageProcessor.Samplers
int newY = height - y - 1;
target[newX, newY] = source[x, y];
}
+ this.OnRowProcessed();
});
}
@@ -122,7 +124,7 @@ namespace ImageProcessor.Samplers
///
/// The target image.
/// The source image.
- private static void Rotate90(ImageBase target, ImageBase source)
+ private void Rotate90(ImageBase target, ImageBase source)
{
int width = source.Width;
int height = source.Height;
@@ -136,6 +138,7 @@ namespace ImageProcessor.Samplers
int newX = height - y - 1;
temp[newX, x] = source[x, y];
}
+ this.OnRowProcessed();
});
target.SetPixels(height, width, temp.Pixels);
@@ -146,7 +149,7 @@ namespace ImageProcessor.Samplers
/// at half the height of the image.
///
/// Target image to apply the process to.
- private static void FlipX(ImageBase target)
+ private void FlipX(ImageBase target)
{
int width = target.Width;
int height = target.Height;
@@ -163,6 +166,7 @@ namespace ImageProcessor.Samplers
target[x, y] = temp[x, newY];
target[x, newY] = temp[x, y];
}
+ this.OnRowProcessed();
});
}
@@ -171,7 +175,7 @@ namespace ImageProcessor.Samplers
/// at half of the width of the image.
///
/// Target image to apply the process to.
- private static void FlipY(ImageBase target)
+ private void FlipY(ImageBase target)
{
int width = target.Width;
int height = target.Height;
@@ -188,6 +192,7 @@ namespace ImageProcessor.Samplers
target[x, y] = temp[newX, y];
target[newX, y] = temp[x, y];
}
+ this.OnRowProcessed();
});
}
}
diff --git a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
index 3a24da33e..4414d79bf 100644
--- a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
+++ b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs
@@ -1,7 +1,6 @@
namespace ImageProcessor.Tests
{
- using System;
using System.Diagnostics;
using System.IO;
@@ -66,10 +65,9 @@ namespace ImageProcessor.Tests
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/Filter/{ Path.GetFileName(filename) }"))
{
- lastRowProcessed = 0;
- processor.OnProgressed += ProgressUpdate;
+ processor.OnProgress += ProgressUpdate;
image.Process(processor).Save(output);
- processor.OnProgressed -= ProgressUpdate;
+ processor.OnProgress -= ProgressUpdate;
}
Trace.WriteLine($"{ name }: { watch.ElapsedMilliseconds}ms");
@@ -77,14 +75,9 @@ namespace ImageProcessor.Tests
}
}
- private static int allowedVariability = Environment.ProcessorCount * 4;
- private int lastRowProcessed;
-
- private void ProgressUpdate(object sender, ProgressedEventArgs e)
+ private void ProgressUpdate(object sender, ProgressEventArgs e)
{
Assert.InRange(e.numRowsProcessed, 1, e.totalRows);
- Assert.InRange(e.numRowsProcessed, lastRowProcessed - allowedVariability, lastRowProcessed + allowedVariability);
- lastRowProcessed = e.numRowsProcessed;
}
}
}
diff --git a/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
index 0a1207c85..d215c0083 100644
--- a/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
+++ b/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
@@ -57,7 +57,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}"))
{
- image.Resize(image.Width / 2, image.Height / 2, sampler)
+ image.Resize(image.Width / 2, image.Height / 2, sampler, ProgressUpdate)
.Save(output);
}
@@ -85,7 +85,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}"))
{
- image.Resize(image.Width / 3, 0, new TriangleResampler())
+ image.Resize(image.Width / 3, 0, new TriangleResampler(), ProgressUpdate)
.Save(output);
}
@@ -113,7 +113,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}"))
{
- image.Resize(0, image.Height / 3, new TriangleResampler())
+ image.Resize(0, image.Height / 3, new TriangleResampler(), ProgressUpdate)
.Save(output);
}
@@ -140,7 +140,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-" + rotateType + flipType + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/RotateFlip/{filename}"))
{
- image.RotateFlip(rotateType, flipType)
+ image.RotateFlip(rotateType, flipType, ProgressUpdate)
.Save(output);
}
@@ -167,7 +167,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/Rotate/{filename}"))
{
- image.Rotate(45, sampler)
+ image.Rotate(45, sampler, ProgressUpdate)
//.BackgroundColor(Color.Aqua)
.Save(output);
}
@@ -193,7 +193,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-EntropyCrop" + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/EntropyCrop/{filename}"))
{
- image.EntropyCrop().Save(output);
+ image.EntropyCrop(.5f, ProgressUpdate).Save(output);
}
}
}
@@ -215,7 +215,7 @@
string filename = Path.GetFileNameWithoutExtension(file) + "-Crop" + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"TestOutput/Crop/{filename}"))
{
- image.Crop(image.Width / 2, image.Height / 2).Save(output);
+ image.Crop(image.Width / 2, image.Height / 2, ProgressUpdate).Save(output);
}
}
}
@@ -235,5 +235,10 @@
Assert.Equal(result, expected);
}
+
+ private void ProgressUpdate(object sender, ProgressEventArgs e)
+ {
+ Assert.InRange(e.numRowsProcessed, 1, e.totalRows);
+ }
}
}