Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rold2007/ImageSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
rold2007 committed Sep 26, 2020
2 parents 81509ff + b06cb32 commit 856d8af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private static void ApplyNNResizeFrameTransform(
var operation = new NNRowOperation(
sourceRectangle,
destinationRectangle,
interest,
widthFactor,
heightFactor,
source,
Expand Down Expand Up @@ -197,6 +198,7 @@ private static void ApplyResizeFrameTransform(
{
private readonly Rectangle sourceBounds;
private readonly Rectangle destinationBounds;
private readonly Rectangle interest;
private readonly float widthFactor;
private readonly float heightFactor;
private readonly ImageFrame<TPixel> source;
Expand All @@ -206,13 +208,15 @@ private static void ApplyResizeFrameTransform(
public NNRowOperation(
Rectangle sourceBounds,
Rectangle destinationBounds,
Rectangle interest,
float widthFactor,
float heightFactor,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination)
{
this.sourceBounds = sourceBounds;
this.destinationBounds = destinationBounds;
this.interest = interest;
this.widthFactor = widthFactor;
this.heightFactor = heightFactor;
this.source = source;
Expand All @@ -224,19 +228,19 @@ public void Invoke(int y)
{
int sourceX = this.sourceBounds.X;
int sourceY = this.sourceBounds.Y;
int destX = this.destinationBounds.X;
int destY = this.destinationBounds.Y;
int destLeft = this.destinationBounds.Left;
int destRight = this.destinationBounds.Right;
int destOriginX = this.destinationBounds.X;
int destOriginY = this.destinationBounds.Y;
int destLeft = this.interest.Left;
int destRight = this.interest.Right;

// Y coordinates of source points
Span<TPixel> sourceRow = this.source.GetPixelRowSpan((int)(((y - destY) * this.heightFactor) + sourceY));
Span<TPixel> sourceRow = this.source.GetPixelRowSpan((int)(((y - destOriginY) * this.heightFactor) + sourceY));
Span<TPixel> targetRow = this.destination.GetPixelRowSpan(y);

for (int x = destLeft; x < destRight; x++)
{
// X coordinates of source points
targetRow[x] = sourceRow[(int)(((x - destX) * this.widthFactor) + sourceX)];
targetRow[x] = sourceRow[(int)(((x - destOriginX) * this.widthFactor) + sourceX)];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,29 @@ public void Issue1195()
}));
}
}

[Theory]
[InlineData(1, 1)]
[InlineData(4, 6)]
[InlineData(2, 10)]
[InlineData(8, 1)]
[InlineData(3, 7)]
public void Issue1342(int width, int height)
{
using (var image = new Image<Rgba32>(1, 1))
{
var size = new Size(width, height);
image.Mutate(x => x
.Resize(
new ResizeOptions
{
Size = size,
Sampler = KnownResamplers.NearestNeighbor
}));

Assert.Equal(width, image.Width);
Assert.Equal(height, image.Height);
}
}
}
}

0 comments on commit 856d8af

Please sign in to comment.