diff --git a/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
index d7498d286..766907361 100644
--- a/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
+++ b/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
@@ -15,7 +15,6 @@ namespace ImageProcessorCore
///
public class SkewProcessor : ImageSampler
{
-
///
/// The angle of rotation along the x-axis.
///
@@ -41,16 +40,6 @@ namespace ImageProcessorCore
set
{
- if (value > 360)
- {
- value -= 360;
- }
-
- if (value < 0)
- {
- value += 360;
- }
-
this.angleX = value;
}
}
@@ -67,16 +56,6 @@ namespace ImageProcessorCore
set
{
- if (value > 360)
- {
- value -= 360;
- }
-
- if (value < 0)
- {
- value += 360;
- }
-
this.angleY = value;
}
}
@@ -110,54 +89,51 @@ namespace ImageProcessorCore
// Get the padded bounds and resize the image.
Rectangle bounds = ResizeHelper.CalculateTargetLocationAndBounds(source, options);
- target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
+ target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width * rectangle.Height * 4]);
}
}
///
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
-
int skewMaxX = target.Width - source.Width;
int skewMaxY = target.Height - source.Height;
+ int offesetX = 0;
+ int offesetY = 0;
- int[] deltaX = new int[source.Height];
- for (int i = 0; i < deltaX.Length; i++)
+ if (ImageMaths.DegreesToRadians(angleX) < 0)
{
- deltaX[i] = GetSkewDelta(i, angleX);
- if (angleX < 0)
- {
- deltaX[i] += skewMaxX;
- }
+ offesetX = skewMaxX;
+ skewMaxX = -skewMaxX;
+
}
+ if (ImageMaths.DegreesToRadians(angleY) < 0)
+ {
+ offesetY = skewMaxY;
+ // skewMaxY = -skewMaxY;
+
+ }
+
+
Parallel.For(
0,
- source.Width,
- sx =>
+ source.Height,
+ sy =>
{
- int deltaY = GetSkewDelta(sx, angleY);
- if (AngleY < 0)
- {
- deltaY += skewMaxY;
- }
- for (int sy = 0; sy < source.Height; sy++)
+
+ for (int sx = 0; sx < source.Width; sx++)
{
- target[deltaX[sy] + sx, deltaY + sy] = source[sx, sy];
+ int skewY = ((skewMaxX * (sy)) / (source.Height - 1)) + offesetX;
+ int skewX = ((skewMaxY * (sx-source.Width-1)) / (source.Width - 1))+ offesetY;
+ target[skewY + sx, sy +skewX ] = source[sx, sy];
}
this.OnRowProcessed();
});
- }
- private int GetSkewDelta(int sy, float angle)
- {
- float radians = ImageMaths.DegreesToRadians(angle);
- double delta = Math.Tan(radians);
- delta = delta * sy;
- return ((int)delta);
- }
+ }
///
diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs
index ac610746e..c529e94d9 100644
--- a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs
+++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs
@@ -500,7 +500,7 @@
using (Image image = new Image(stream))
using (FileStream output = File.OpenWrite($"TestOutput/Skew/{filename}"))
{
- image.Skew(20, 10, this.ProgressUpdate)
+ image.Skew(5, -2, this.ProgressUpdate)
.Save(output);
}