Browse Source

a smal bug

Former-commit-id: c6e0afbd230747057de8314c9599821c69dc1ffe
Former-commit-id: be47dfa7a12de85db15a8c00ac434952213fafbb
Former-commit-id: 891a14bf95046a3a8eb5108c6e389060a01a5094
pull/1/head
Sverre Rekvin 10 years ago
parent
commit
6147ca03d9
  1. 67
      src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs
  2. 2
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

67
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();
});
}

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(5, -2, this.ProgressUpdate)
image.Skew(10, -20, this.ProgressUpdate)
.Save(output);
}

Loading…
Cancel
Save