diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineProcessor.cs
index 6fdf061b8..ad8221b88 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/AffineProcessor.cs
+++ b/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));
}
});
diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
index ecfcc7dd2..0d8d0d911 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
+++ b/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
}
///
- protected override unsafe void OnApply(ImageFrame source, ImageFrame cloned, Rectangle sourceRectangle, Configuration configuration)
+ protected override void OnApply(ImageFrame source, ImageFrame 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
});
}
}
+
+ ///
+ protected override void AfterImageApply(Image source, Image 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);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs
index b2e183de7..54a3af36f 100644
--- a/tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs
@@ -63,10 +63,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
IResampler resampler = GetResampler(resamplerName);
using (Image 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);