Browse Source

found stepping bug

Former-commit-id: ee2d54efce687030938c51f5886331974183cbd4
Former-commit-id: 8c080d5a56232ce06304afecb56ac339dd677689
Former-commit-id: 06bb22b1b2c9f757a52194a79641eb56d9d747aa
pull/1/head
Sverre Rekvin 10 years ago
parent
commit
8bb74abd47
  1. 70
      src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
  2. 2
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

70
src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs

@ -15,7 +15,6 @@ namespace ImageProcessorCore
/// </summary>
public class SkewProcessor : ImageSampler
{
/// <summary>
/// The angle of rotation along the x-axis.
/// </summary>
@ -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]);
}
}
/// <inheritdoc/>
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);
}
}
/// <inheritdoc/>

2
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);
}

Loading…
Cancel
Save