Browse Source

Cleanup + update tests

af/merge-core
James Jackson-South 8 years ago
parent
commit
95be7e6aa7
  1. 8
      src/ImageSharp/Processing/Processors/Transforms/AffineProcessor.cs
  2. 23
      src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
  3. 6
      tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs

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

@ -175,10 +175,6 @@ namespace SixLabors.ImageSharp.Processing.Processors
// Precalulating transformed weights would require prior knowledge of every transformed pixel location
// since they can be at sub-pixel positions on both axis.
// I've optimized where I can but am always open to suggestions.
//
// TODO: If we can somehow improve edge pixel handling that would be most beneficial.
// 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);
@ -200,12 +196,16 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
float xWeight = xSpan[xx];
var vector = source[i, j].ToVector4();
// Values are first premultiplied to prevent darkening of edge pixels
var mupltiplied = new Vector4(new Vector3(vector.X, vector.Y, vector.Z) * vector.W, vector.W);
sum += mupltiplied * xWeight * yWeight;
}
}
ref TPixel dest = ref destRow[x];
// Reverse the premultiplication
dest.PackFromVector4(new Vector4(new Vector3(sum.X, sum.Y, sum.Z) / sum.W, sum.W));
}
});

23
src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

@ -8,6 +8,7 @@ using System.Numerics;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -62,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
/// <inheritdoc/>
protected override unsafe void OnApply(ImageFrame<TPixel> source, ImageFrame<TPixel> cloned, Rectangle sourceRectangle, Configuration configuration)
protected override void OnApply(ImageFrame<TPixel> source, ImageFrame<TPixel> cloned, Rectangle sourceRectangle, Configuration configuration)
{
// Jump out, we'll deal with that later.
if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle)
@ -190,5 +191,25 @@ namespace SixLabors.ImageSharp.Processing.Processors
});
}
}
/// <inheritdoc/>
protected override void AfterImageApply(Image<TPixel> source, Image<TPixel> destination, Rectangle sourceRectangle)
{
ExifProfile profile = destination.MetaData.ExifProfile;
if (profile == null)
{
return;
}
if (profile.GetValue(ExifTag.PixelXDimension) != null)
{
profile.SetValue(ExifTag.PixelXDimension, destination.Width);
}
if (profile.GetValue(ExifTag.PixelYDimension) != null)
{
profile.SetValue(ExifTag.PixelYDimension, destination.Height);
}
}
}
}

6
tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs

@ -63,10 +63,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
IResampler resampler = GetResampler(resamplerName);
using (Image<TPixel> image = provider.GetImage())
{
// TODO: Modify this matrix if we change our origin-concept
var rotate = Matrix3x2.CreateRotation((float)Math.PI / 4f);
var rotate = Matrix3x2.CreateRotation((float)Math.PI / 4F, new Vector2(5 / 2F, 5 / 2F));
var translate = Matrix3x2.CreateTranslation((7 - 5) / 2F, (7 - 5) / 2F);
image.Mutate(c => c.Transform(rotate, resampler));
image.Mutate(c => c.Transform(rotate * translate, resampler));
image.DebugSave(provider, resamplerName);
VerifyAllPixelsAreWhiteOrTransparent(image);

Loading…
Cancel
Save