|
|
|
@ -176,6 +176,87 @@ namespace SixLabors.ImageSharp.Tests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class ProcessPixelRows |
|
|
|
{ |
|
|
|
[Fact] |
|
|
|
public void PixelAccessorDimensionsAreCorrect() |
|
|
|
{ |
|
|
|
using var image = new Image<Rgb24>(123, 456); |
|
|
|
image.ProcessPixelRows(accessor => |
|
|
|
{ |
|
|
|
Assert.Equal(123, accessor.Width); |
|
|
|
Assert.Equal(456, accessor.Height); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void WritesImagePixels() |
|
|
|
{ |
|
|
|
using var image = new Image<L16>(256, 256); |
|
|
|
image.ProcessPixelRows(accessor => |
|
|
|
{ |
|
|
|
for (int y = 0; y < accessor.Height; y++) |
|
|
|
{ |
|
|
|
Span<L16> row = accessor.GetRowSpan(y); |
|
|
|
for (int x = 0; x < row.Length; x++) |
|
|
|
{ |
|
|
|
row[x] = new L16((ushort)(x * y)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
Buffer2D<L16> buffer = image.Frames.RootFrame.PixelBuffer; |
|
|
|
for (int y = 0; y < 256; y++) |
|
|
|
{ |
|
|
|
Span<L16> row = buffer.GetRowSpan(y); |
|
|
|
for (int x = 0; x < 256; x++) |
|
|
|
{ |
|
|
|
int actual = row[x].PackedValue; |
|
|
|
Assert.Equal(x * y, actual); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CopyImagePixels() |
|
|
|
{ |
|
|
|
using var img1 = new Image<L16>(256, 256); |
|
|
|
Buffer2D<L16> buffer = img1.Frames.RootFrame.PixelBuffer; |
|
|
|
for (int y = 0; y < 256; y++) |
|
|
|
{ |
|
|
|
Span<L16> row = buffer.GetRowSpan(y); |
|
|
|
for (int x = 0; x < 256; x++) |
|
|
|
{ |
|
|
|
row[x] = new L16((ushort)(x * y)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
using var img2 = new Image<L16>(256, 256); |
|
|
|
|
|
|
|
img1.ProcessPixelRows(img2, (accessor1, accessor2) => |
|
|
|
{ |
|
|
|
for (int y = 0; y < accessor1.Height; y++) |
|
|
|
{ |
|
|
|
Span<L16> row1 = accessor1.GetRowSpan(y); |
|
|
|
Span<L16> row2 = accessor2.GetRowSpan(accessor2.Height - y - 1); |
|
|
|
row1.CopyTo(row2); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
buffer = img2.Frames.RootFrame.PixelBuffer; |
|
|
|
for (int y = 0; y < 256; y++) |
|
|
|
{ |
|
|
|
Span<L16> row = buffer.GetRowSpan(y); |
|
|
|
for (int x = 0; x < 256; x++) |
|
|
|
{ |
|
|
|
int actual = row[x].PackedValue; |
|
|
|
Assert.Equal(x * (256 - y - 1), actual); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class Dispose |
|
|
|
{ |
|
|
|
private readonly Configuration configuration = Configuration.CreateDefaultInstance(); |
|
|
|
|