Browse Source

Apply fix and tests

pull/1945/head
James Jackson-South 4 years ago
parent
commit
b97ac35d5b
  1. 9
      src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs
  2. 9
      src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs
  3. 11
      tests/ImageSharp.Tests/Processing/Processors/Transforms/AffineTransformTests.cs
  4. 10
      tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs

9
src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs

@ -64,7 +64,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
if (matrix.Equals(default) || matrix.Equals(Matrix3x2.Identity)) if (matrix.Equals(default) || matrix.Equals(Matrix3x2.Identity))
{ {
// The clone will be blank here copy all the pixel data over // The clone will be blank here copy all the pixel data over
source.GetPixelMemoryGroup().CopyTo(destination.GetPixelMemoryGroup()); var interest = Rectangle.Intersect(this.SourceRectangle, destination.Bounds());
Buffer2DRegion<TPixel> sourceBuffer = source.PixelBuffer.GetRegion(interest);
Buffer2DRegion<TPixel> destbuffer = destination.PixelBuffer.GetRegion(interest);
for (int y = 0; y < sourceBuffer.Height; y++)
{
sourceBuffer.DangerousGetRowSpan(y).CopyTo(destbuffer.DangerousGetRowSpan(y));
}
return; return;
} }

9
src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs

@ -63,7 +63,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
if (matrix.Equals(default) || matrix.Equals(Matrix4x4.Identity)) if (matrix.Equals(default) || matrix.Equals(Matrix4x4.Identity))
{ {
// The clone will be blank here copy all the pixel data over // The clone will be blank here copy all the pixel data over
source.GetPixelMemoryGroup().CopyTo(destination.GetPixelMemoryGroup()); var interest = Rectangle.Intersect(this.SourceRectangle, destination.Bounds());
Buffer2DRegion<TPixel> sourceBuffer = source.PixelBuffer.GetRegion(interest);
Buffer2DRegion<TPixel> destbuffer = destination.PixelBuffer.GetRegion(interest);
for (int y = 0; y < sourceBuffer.Height; y++)
{
sourceBuffer.DangerousGetRowSpan(y).CopyTo(destbuffer.DangerousGetRowSpan(y));
}
return; return;
} }

11
tests/ImageSharp.Tests/Processing/Processors/Transforms/AffineTransformTests.cs

@ -4,6 +4,7 @@
using System; using System;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Processing.Processors.Transforms;
@ -224,6 +225,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
c => c.Transform(builder)); c => c.Transform(builder));
} }
[Fact]
public void Issue1911()
{
using var image = new Image<Rgba32>(100, 100);
image.Mutate(x => x = x.Transform(new Rectangle(0, 0, 99, 100), Matrix3x2.Identity, new Size(99, 100), KnownResamplers.Lanczos2));
Assert.Equal(99, image.Width);
Assert.Equal(100, image.Height);
}
private static IResampler GetResampler(string name) private static IResampler GetResampler(string name)
{ {
PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name);

10
tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs

@ -147,6 +147,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
} }
} }
[Fact]
public void Issue1911()
{
using var image = new Image<Rgba32>(100, 100);
image.Mutate(x => x = x.Transform(new Rectangle(0, 0, 99, 100), Matrix4x4.Identity, new Size(99, 100), KnownResamplers.Lanczos2));
Assert.Equal(99, image.Width);
Assert.Equal(100, image.Height);
}
private static IResampler GetResampler(string name) private static IResampler GetResampler(string name)
{ {
PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name);

Loading…
Cancel
Save