|
|
|
@ -1,6 +1,7 @@ |
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using SixLabors.ImageSharp.Advanced; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
@ -8,8 +9,33 @@ using Xunit; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Advanced |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public class AdvancedImageExtensionsTests |
|
|
|
{ |
|
|
|
public class GetPixelMemory |
|
|
|
{ |
|
|
|
[Theory] |
|
|
|
[WithSolidFilledImages(1, 1, "Red", PixelTypes.Rgba32)] |
|
|
|
[WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] |
|
|
|
public void WhenMemoryIsOwned<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using (Image<TPixel> image = provider.GetImage()) |
|
|
|
{ |
|
|
|
Memory<TPixel> memory = image.GetPixelMemory(); |
|
|
|
Assert.Equal(image.Width * image.Height, memory.Length); |
|
|
|
|
|
|
|
var targetBuffer = new TPixel[image.Width * image.Height]; |
|
|
|
memory.Span.CopyTo(targetBuffer); |
|
|
|
|
|
|
|
image.ComparePixelBufferTo(targetBuffer); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] |
|
|
|
public unsafe void DangerousGetPinnableReference_CopyToBuffer<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
|