mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 121 additions and 114 deletions
@ -0,0 +1,38 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using Xunit; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using System.Runtime.CompilerServices; |
|||
// ReSharper disable InconsistentNaming
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Advanced |
|||
{ |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
public class AdvancedImageExtensionsTests |
|||
{ |
|||
[Theory] |
|||
[WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] |
|||
public unsafe void DangerousGetPinnableReference_CopyToBuffer<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
TPixel[] targetBuffer = new TPixel[image.Width * image.Height]; |
|||
|
|||
ref byte source = ref Unsafe.As<TPixel, byte>(ref targetBuffer[0]); |
|||
ref byte dest = ref Unsafe.As<TPixel, byte>(ref image.DangerousGetPinnableReferenceToPixelBuffer()); |
|||
|
|||
fixed (byte* targetPtr = &source) |
|||
fixed (byte* pixelBasePtr = &dest) |
|||
{ |
|||
uint dataSizeInBytes = (uint)(image.Width * image.Height * Unsafe.SizeOf<TPixel>()); |
|||
Unsafe.CopyBlock(targetPtr, pixelBasePtr, dataSizeInBytes); |
|||
} |
|||
|
|||
image.ComparePixelBufferTo(targetBuffer); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using Xunit; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Advanced |
|||
{ |
|||
public class ImageExtensionsTests |
|||
{ |
|||
[Fact] |
|||
public unsafe void DangerousGetPinnableReference_CopyToBuffer() |
|||
{ |
|||
var image = new Image<Rgba32>(128, 128); |
|||
for (int y = 0; y < image.Height; y++) |
|||
for (int x = 0; x < image.Width; x++) |
|||
{ |
|||
image[x, y] = new Rgba32(x, 255 - y, x + y); |
|||
} |
|||
|
|||
Rgba32[] targetBuffer = new Rgba32[image.Width * image.Height]; |
|||
|
|||
fixed (Rgba32* targetPtr = targetBuffer) |
|||
fixed (Rgba32* pixelBasePtr = &image.DangerousGetPinnableReferenceToPixelBuffer()) |
|||
{ |
|||
uint dataSizeInBytes = (uint)(image.Width * image.Height * Unsafe.SizeOf<Rgba32>()); |
|||
Unsafe.CopyBlock(targetPtr, pixelBasePtr, dataSizeInBytes); |
|||
} |
|||
|
|||
for (int y = 0; y < image.Height; y++) |
|||
for (int x = 0; x < image.Width; x++) |
|||
{ |
|||
int linearIndex = y * image.Width + x; |
|||
Assert.Equal(image[x, y], targetBuffer[linearIndex]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue