Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}