Browse Source

No need to store the firstpass image as a variable.

Former-commit-id: a1f0b1c9a76b4bf24a704cfd95a922b11ded8189
Former-commit-id: df58b4f394a68e48fd3755ce250ec4ec062cc62f
Former-commit-id: 9234222f848afbdf9461e16ea76974fe56da37a6
af/merge-core
James Jackson-South 10 years ago
parent
commit
96370a7901
  1. 10
      src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs
  2. 8
      tests/ImageProcessorCore.Benchmarks/Samplers/Resize.cs

10
src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs

@ -13,11 +13,6 @@ namespace ImageProcessorCore.Processors
/// </summary>
public class ResizeProcessor : ImageSampler
{
/// <summary>
/// The image used for storing the first pass pixels.
/// </summary>
private Image firstPass;
/// <summary>
/// Initializes a new instance of the <see cref="ResizeProcessor"/> class.
/// </summary>
@ -54,8 +49,6 @@ namespace ImageProcessorCore.Processors
this.HorizontalWeights = this.PrecomputeWeights(targetRectangle.Width, sourceRectangle.Width);
this.VerticalWeights = this.PrecomputeWeights(targetRectangle.Height, sourceRectangle.Height);
}
this.firstPass = new Image(target.Width, source.Height);
}
/// <inheritdoc/>
@ -121,8 +114,9 @@ namespace ImageProcessorCore.Processors
// A 2-pass 1D algorithm appears to be faster than splitting a 1-pass 2D algorithm
// First process the columns. Since we are not using multiple threads startY and endY
// are the upper and lower bounds of the source rectangle.
Image firstPass = new Image(target.Width, source.Height);
using (PixelAccessor sourcePixels = source.Lock())
using (PixelAccessor firstPassPixels = this.firstPass.Lock())
using (PixelAccessor firstPassPixels = firstPass.Lock())
using (PixelAccessor targetPixels = target.Lock())
{
Parallel.For(

8
tests/ImageProcessorCore.Benchmarks/Samplers/Resize.cs

@ -12,9 +12,9 @@
[Benchmark(Baseline = true, Description = "System.Drawing Resize")]
public Size ResizeSystemDrawing()
{
using (Bitmap source = new Bitmap(400, 400))
using (Bitmap source = new Bitmap(2000, 2000))
{
using (Bitmap destination = new Bitmap(100, 100))
using (Bitmap destination = new Bitmap(400, 400))
{
using (Graphics graphics = Graphics.FromImage(destination))
{
@ -32,8 +32,8 @@
[Benchmark(Description = "ImageProcessorCore Resize")]
public CoreSize ResizeCore()
{
CoreImage image = new CoreImage(400, 400);
image.Resize(100, 100);
CoreImage image = new CoreImage(2000, 2000);
image.Resize(400, 400);
return new CoreSize(image.Width, image.Height);
}
}

Loading…
Cancel
Save