diff --git a/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs index 766907361..c50e7ccc5 100644 --- a/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs @@ -98,41 +98,42 @@ namespace ImageProcessorCore { int skewMaxX = target.Width - source.Width; int skewMaxY = target.Height - source.Height; - int offesetX = 0; - int offesetY = 0; - - if (ImageMaths.DegreesToRadians(angleX) < 0) - { - offesetX = skewMaxX; - skewMaxX = -skewMaxX; - - } - if (ImageMaths.DegreesToRadians(angleY) < 0) - { - offesetY = skewMaxY; - // skewMaxY = -skewMaxY; - - } - - - + bool revX = ImageMaths.DegreesToRadians(angleX) < 0; + bool revY = ImageMaths.DegreesToRadians(angleY) < 0; Parallel.For( - 0, - source.Height, - sy => - { - - for (int sx = 0; sx < source.Width; sx++) - { - 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(); - }); - - + 0, + source.Height, + sy => + { + int deltaX; + if (revX) + { + deltaX = ((skewMaxX * (-sy + (source.Height - 1))) / (source.Height - 1)); + } + else + { + deltaX = (((skewMaxX * sy)) / (source.Height - 1)); + } + + for (int sx = 0; sx < source.Width; sx++) + { + int deltaY; + if (revY) + { + deltaY = ((((skewMaxY * -sx ))+ (skewMaxY-1)) -(skewMaxY-1)) / (source.Width - 1) + skewMaxY; + //deltaY = (((skewMaxY * sx)) / (source.Height - 1)); + // deltaY = -deltaY + skewMaxY; + //deltaY = 0; + } + else + { + deltaY = ((skewMaxY * sx) / (source.Width - 1)); + } + target[deltaX + sx, sy + deltaY] = source[sx, sy]; + } + this.OnRowProcessed(); + }); } diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs index c529e94d9..b628049aa 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(5, -2, this.ProgressUpdate) + image.Skew(10, -20, this.ProgressUpdate) .Save(output); }