diff --git a/src/ImageProcessor/Samplers/Resampler.cs b/src/ImageProcessor/Samplers/Resampler.cs
index f3c474e75..a36d68b36 100644
--- a/src/ImageProcessor/Samplers/Resampler.cs
+++ b/src/ImageProcessor/Samplers/Resampler.cs
@@ -7,6 +7,7 @@ namespace ImageProcessor.Samplers
{
using System;
using System.Collections.Generic;
+ using System.Numerics;
using System.Threading.Tasks;
using ImageProcessor.Filters;
@@ -83,8 +84,6 @@ namespace ImageProcessor.Samplers
this.horizontalWeights = this.PrecomputeWeights(targetRectangle.Width, sourceRectangle.Width);
this.verticalWeights = this.PrecomputeWeights(targetRectangle.Height, sourceRectangle.Height);
}
-
- new BackgroundColor(Color.Transparent).Apply(source, source, sourceRectangle);
}
///
@@ -103,6 +102,16 @@ namespace ImageProcessor.Samplers
}
}
+ ///
+ protected override void AfterApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle)
+ {
+ // Copy the pixels over.
+ if (source.Bounds == target.Bounds && Math.Abs(this.angle) < 0.001f)
+ {
+ target.ClonePixels(target.Width, target.Height, source.Pixels);
+ }
+ }
+
///
/// Resamples the specified at the specified location
/// and with the specified size.
@@ -121,9 +130,9 @@ namespace ImageProcessor.Samplers
///
private void ApplyResizeOnly(ImageBase target, ImageBase source, Rectangle targetRectangle, int startY, int endY)
{
+ // Jump out, we'll deal with that later.
if (source.Bounds == target.Bounds)
{
- target.ClonePixels(target.Width, target.Height, source.Pixels);
return;
}
@@ -163,6 +172,7 @@ namespace ImageProcessor.Samplers
}
// Interpolate the image using the calculated weights.
+ // TODO: Figure out a way to split this up so we can reduce complexity and speed things up.
Parallel.For(
startY,
endY,
@@ -187,8 +197,7 @@ namespace ImageProcessor.Samplers
{
int originX = xw.Index;
Color sourceColor = Color.Expand(source[originX, originY]);
- float weight = yw.Value * xw.Value;
- destination += sourceColor * weight;
+ destination += sourceColor * yw.Value * xw.Value;
}
}
@@ -297,8 +306,7 @@ namespace ImageProcessor.Samplers
if (sourceRectangle.Contains(rotated.X, rotated.Y))
{
Color sourceColor = Color.Expand(source[rotated.X, rotated.Y]);
- float weight = yw.Value * xw.Value;
- destination += sourceColor * weight;
+ destination += sourceColor * yw.Value * xw.Value;
}
}
}
diff --git a/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
index 04709b883..0a1207c85 100644
--- a/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
+++ b/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
@@ -21,7 +21,7 @@
//{ "Lanczos5", new Lanczos5Resampler() },
//{ "Lanczos8", new Lanczos8Resampler() },
//{ "MitchellNetravali", new MitchellNetravaliResampler() },
- //{ "NearestNeighbor", new NearestNeighborResampler() },
+ { "NearestNeighbor", new NearestNeighborResampler() },
//{ "Hermite", new HermiteResampler() },
//{ "Spline", new SplineResampler() },
//{ "Robidoux", new RobidouxResampler() },