Browse Source

Fix Lancsoz banding + lighter skew tests

af/merge-core
James Jackson-South 9 years ago
parent
commit
4e12604761
  1. 6
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  2. 24
      src/ImageSharp/Processing/Processors/Transforms/AffineProcessor.cs
  3. 4
      tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs

6
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -162,10 +162,10 @@ namespace SixLabors.ImageSharp
float maxX = MathF.Max(tl.X, MathF.Max(tr.X, MathF.Max(bl.X, br.X))); float maxX = MathF.Max(tl.X, MathF.Max(tr.X, MathF.Max(bl.X, br.X)));
float minY = MathF.Min(tl.Y, MathF.Min(tr.Y, MathF.Min(bl.Y, br.Y))); float minY = MathF.Min(tl.Y, MathF.Min(tr.Y, MathF.Min(bl.Y, br.Y)));
float maxY = MathF.Max(tl.Y, MathF.Max(tr.Y, MathF.Max(bl.Y, br.Y))); float maxY = MathF.Max(tl.Y, MathF.Max(tr.Y, MathF.Max(bl.Y, br.Y)));
float sizeX = maxX - minX; float sizeX = maxX - minX + .5F;
float sizeY = maxY - minY; float sizeY = maxY - minY + .5F;
return new Rectangle((int)MathF.Floor(minX), (int)MathF.Floor(minY), (int)MathF.Ceiling(sizeX), (int)MathF.Ceiling(sizeY)); return new Rectangle((int)(MathF.Ceiling(minX) - .5F), (int)(MathF.Ceiling(minY) - .5F), (int)MathF.Floor(sizeX), (int)MathF.Floor(sizeY));
} }
/// <summary> /// <summary>

24
src/ImageSharp/Processing/Processors/Transforms/AffineProcessor.cs

@ -127,10 +127,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
Vector2 minXY = point - radius; Vector2 minXY = point - radius;
var extents = new Vector4( var extents = new Vector4(
MathF.Ceiling(maxXY.X), MathF.Floor(maxXY.X + .5F),
MathF.Ceiling(maxXY.Y), MathF.Floor(maxXY.Y + .5F),
MathF.Floor(minXY.X), MathF.Ceiling(minXY.X - .5F),
MathF.Floor(minXY.Y)); MathF.Ceiling(minXY.Y - .5F));
int right = (int)extents.X; int right = (int)extents.X;
int bottom = (int)extents.Y; int bottom = (int)extents.Y;
@ -154,23 +154,17 @@ namespace SixLabors.ImageSharp.Processing.Processors
// since they can be at sub-pixel positions on both axis. // since they can be at sub-pixel positions on both axis.
// I've optimized where I can but am always open to suggestions. // I've optimized where I can but am always open to suggestions.
// //
// Create and normalize the y-weights // TODO: If we can somehow improve edge pixel handling that would be most beneficial.
if (yScale > 1) // Currently the interpolated edge non-alpha components are altered which causes slight darkening of edges.
// Ideally the edge pixels should represent the nearest sample with altered alpha component only.
if (yScale > 1 && xScale > 1)
{ {
CalculateWeightsDown(top, bottom, minY, maxY, point.Y, sampler, yScale, ySpan); CalculateWeightsDown(top, bottom, minY, maxY, point.Y, sampler, yScale, ySpan);
}
else
{
CalculateWeightsScaleUp(minY, maxY, point.Y, sampler, ySpan);
}
// Create and normalize the x-weights
if (xScale > 1)
{
CalculateWeightsDown(left, right, minX, maxX, point.X, sampler, xScale, xSpan); CalculateWeightsDown(left, right, minX, maxX, point.X, sampler, xScale, xSpan);
} }
else else
{ {
CalculateWeightsScaleUp(minY, maxY, point.Y, sampler, ySpan);
CalculateWeightsScaleUp(minX, maxX, point.X, sampler, xSpan); CalculateWeightsScaleUp(minX, maxX, point.X, sampler, xSpan);
} }

4
tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
}; };
[Theory] [Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)] [WithTestPatternImages(nameof(SkewValues), 100, 50, DefaultPixelType)]
public void ImageShouldSkew<TPixel>(TestImageProvider<TPixel> provider, float x, float y) public void ImageShouldSkew<TPixel>(TestImageProvider<TPixel> provider, float x, float y)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
} }
[Theory] [Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)] [WithTestPatternImages(nameof(SkewValues), 100, 50, DefaultPixelType)]
public void ImageShouldSkewWithSampler<TPixel>(TestImageProvider<TPixel> provider, float x, float y) public void ImageShouldSkewWithSampler<TPixel>(TestImageProvider<TPixel> provider, float x, float y)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {

Loading…
Cancel
Save