Browse Source

- Use Configuration.Default.MemoryManager in tests

pull/431/head
Lauri Kotilainen 8 years ago
parent
commit
f1412d3c76
  1. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
  2. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs
  3. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs
  4. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs
  5. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
  6. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
  7. 2
      tests/ImageSharp.Benchmarks/General/ClearBuffer.cs
  8. 2
      tests/ImageSharp.Benchmarks/General/IterateArray.cs
  9. 2
      tests/ImageSharp.Benchmarks/General/PixelIndexing.cs
  10. 10
      tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs
  11. 2
      tests/ImageSharp.Benchmarks/Image/EncodePng.cs
  12. 2
      tests/ImageSharp.Benchmarks/Image/Jpeg/YCbCrColorConversion.cs
  13. 6
      tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs
  14. 4
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  15. 16
      tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs
  16. 4
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs
  17. 6
      tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs
  18. 2
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
  19. 4
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  20. 4
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  21. 40
      tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs
  22. 2
      tests/ImageSharp.Tests/Image/ImageTests.cs
  23. 10
      tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
  24. 4
      tests/ImageSharp.Tests/Memory/BufferAreaTests.cs
  25. 22
      tests/ImageSharp.Tests/Memory/BufferTests.cs
  26. 2
      tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs
  27. 6
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  28. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs
  29. 12
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs
  30. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs

4
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs

@ -22,8 +22,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[GlobalSetup]
public void Setup()
{
this.destination = MemoryManager.Current.Allocate<TPixel>(this.Count);
this.source = MemoryManager.Current.Allocate<Vector4>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<TPixel>(this.Count);
this.source = Configuration.Default.MemoryManager.Allocate<Vector4>(this.Count);
}
[GlobalCleanup]

4
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs

@ -25,8 +25,8 @@
[GlobalSetup]
public void Setup()
{
this.destination = MemoryManager.Current.Allocate<Rgba32>(this.Count);
this.source = MemoryManager.Current.Allocate<Vector4>(this.Count * 4);
this.destination = Configuration.Default.MemoryManager.Allocate<Rgba32>(this.Count);
this.source = Configuration.Default.MemoryManager.Allocate<Vector4>(this.Count * 4);
this.source.Pin();
this.destination.Pin();
}

4
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs

@ -19,8 +19,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[GlobalSetup]
public void Setup()
{
this.destination = MemoryManager.Current.Allocate<TPixel>(this.Count);
this.source = MemoryManager.Current.Allocate<byte>(this.Count * 4);
this.destination = Configuration.Default.MemoryManager.Allocate<TPixel>(this.Count);
this.source = Configuration.Default.MemoryManager.Allocate<byte>(this.Count * 4);
}
[GlobalCleanup]

4
tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs

@ -21,8 +21,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[GlobalSetup]
public void Setup()
{
this.source = MemoryManager.Current.Allocate<TPixel>(this.Count);
this.destination = MemoryManager.Current.Allocate<Vector4>(this.Count);
this.source = Configuration.Default.MemoryManager.Allocate<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<Vector4>(this.Count);
}
[GlobalCleanup]

4
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs

@ -19,8 +19,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[GlobalSetup]
public void Setup()
{
this.source = MemoryManager.Current.Allocate<TPixel>(this.Count);
this.destination = MemoryManager.Current.Allocate<byte>(this.Count * 3);
this.source = Configuration.Default.MemoryManager.Allocate<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<byte>(this.Count * 3);
}
[GlobalCleanup]

4
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs

@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[GlobalSetup]
public void Setup()
{
this.source = MemoryManager.Current.Allocate<TPixel>(this.Count);
this.destination = MemoryManager.Current.Allocate<byte>(this.Count * 4);
this.source = Configuration.Default.MemoryManager.Allocate<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<byte>(this.Count * 4);
}
[GlobalCleanup]

2
tests/ImageSharp.Benchmarks/General/ClearBuffer.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General
[GlobalSetup]
public void Setup()
{
this.buffer = MemoryManager.Current.Allocate<Rgba32>(this.Count);
this.buffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(this.Count);
}
[GlobalCleanup]

2
tests/ImageSharp.Benchmarks/General/IterateArray.cs

@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General
[GlobalSetup]
public void Setup()
{
this.buffer = MemoryManager.Current.Allocate<Vector4>(this.Length);
this.buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(this.Length);
this.buffer.Pin();
this.array = new Vector4[this.Length];
}

2
tests/ImageSharp.Benchmarks/General/PixelIndexing.cs

@ -149,7 +149,7 @@
public void Setup()
{
this.width = 2048;
this.buffer = MemoryManager.Current.Allocate2D<Vector4>(2048, 2048);
this.buffer = Configuration.Default.MemoryManager.Allocate2D<Vector4>(2048, 2048);
this.pointer = (Vector4*)this.buffer.Buffer.Pin();
this.array = this.buffer.Buffer.Array;
this.pinnable = Unsafe.As<Pinnable<Vector4>>(this.array);

10
tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs

@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream())
{
PngEncoder encoder = new PngEncoder() { Quantizer = new OctreeQuantizer<Rgba32>(), PaletteSize = 256 };
PngEncoder encoder = new PngEncoder(Configuration.Default.MemoryManager) { Quantizer = new OctreeQuantizer<Rgba32>(), PaletteSize = 256 };
this.bmpCore.SaveAsPng(memoryStream, encoder);
}
@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream())
{
PngEncoder options = new PngEncoder { Quantizer = new OctreeQuantizer<Rgba32> { Dither = false }, PaletteSize = 256 };
PngEncoder options = new PngEncoder(Configuration.Default.MemoryManager) { Quantizer = new OctreeQuantizer<Rgba32> { Dither = false }, PaletteSize = 256 };
this.bmpCore.SaveAsPng(memoryStream, options);
}
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream())
{
PngEncoder options = new PngEncoder { Quantizer = new PaletteQuantizer<Rgba32>(), PaletteSize = 256 };
PngEncoder options = new PngEncoder(Configuration.Default.MemoryManager) { Quantizer = new PaletteQuantizer<Rgba32>(), PaletteSize = 256 };
this.bmpCore.SaveAsPng(memoryStream, options);
}
@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream())
{
PngEncoder options = new PngEncoder { Quantizer = new PaletteQuantizer<Rgba32> { Dither = false }, PaletteSize = 256 };
PngEncoder options = new PngEncoder(Configuration.Default.MemoryManager) { Quantizer = new PaletteQuantizer<Rgba32> { Dither = false }, PaletteSize = 256 };
this.bmpCore.SaveAsPng(memoryStream, options);
}
@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream())
{
PngEncoder options = new PngEncoder() { Quantizer = new WuQuantizer<Rgba32>(), PaletteSize = 256 };
PngEncoder options = new PngEncoder(Configuration.Default.MemoryManager) { Quantizer = new WuQuantizer<Rgba32>(), PaletteSize = 256 };
this.bmpCore.SaveAsPng(memoryStream, options);
}

2
tests/ImageSharp.Benchmarks/Image/EncodePng.cs

@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
new OctreeQuantizer<Rgba32>()
: new PaletteQuantizer<Rgba32>();
var options = new PngEncoder { Quantizer = quantizer };
var options = new PngEncoder(Configuration.Default.MemoryManager) { Quantizer = quantizer };
this.bmpCore.SaveAsPng(memoryStream, options);
}
}

2
tests/ImageSharp.Benchmarks/Image/Jpeg/YCbCrColorConversion.cs

@ -76,7 +76,7 @@
}
// no need to dispose when buffer is not array owner
buffers[i] = MemoryManager.Current.Allocate2D<float>(values.Length, 1);
buffers[i] = Configuration.Default.MemoryManager.Allocate2D<float>(values.Length, 1);
}
return buffers;

6
tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Benchmarks
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = MemoryManager.Current.Allocate<Vector4>(destination.Length * 3))
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3))
{
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
Buffer<float> amounts = MemoryManager.Current.Allocate<float>(image.Width);
Buffer<float> amounts = Configuration.Default.MemoryManager.Allocate<float>(image.Width);
for (int x = 0; x < image.Width; x++)
{
@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
Buffer<float> amounts = MemoryManager.Current.Allocate<float>(image.Width);
Buffer<float> amounts = Configuration.Default.MemoryManager.Allocate<float>(image.Width);
for (int x = 0; x < image.Width; x++)
{

4
tests/ImageSharp.Benchmarks/Samplers/Glow.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[GlobalSetup]
public void Setup()
{
this.bulk = new GlowProcessor<Rgba32>(NamedColors<Rgba32>.Beige, 800 * .5f, GraphicsOptions.Default);
this.bulk = new GlowProcessor<Rgba32>(Configuration.Default.MemoryManager, NamedColors<Rgba32>.Beige, 800 * .5f, GraphicsOptions.Default);
this.parallel = new GlowProcessorParallel<Rgba32>(NamedColors<Rgba32>.Beige) { Radius = 800 * .5f, };
}
@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Benchmarks
}
int width = maxX - minX;
using (Buffer<TPixel> rowColors = MemoryManager.Current.Allocate<TPixel>(width))
using (Buffer<TPixel> rowColors = Configuration.Default.MemoryManager.Allocate<TPixel>(width))
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{
for (int i = 0; i < width; i++)

16
tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void ShapeRegionWithPathCallsAsShape()
{
new ShapeRegion(pathMock.Object);
new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
pathMock.Verify(x => x.AsClosedPath());
}
@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void ShapeRegionWithPathRetainsShape()
{
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
Assert.Equal(pathMock.Object, region.Shape);
}
@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void ShapeRegionFromPathConvertsBoundsProxyToShape()
{
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right);
@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void ShapeRegionFromPathMaxIntersectionsProxyToShape()
{
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
int i = region.MaxIntersections;
pathMock.Verify(x => x.MaxIntersections);
@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
public void ShapeRegionFromPathScanYProxyToShape()
{
int yToScan = 10;
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
pathMock.Setup(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()))
.Callback<PointF, PointF, PointF[], int>((s, e, b, o) => {
@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
public void ShapeRegionFromShapeScanYProxyToShape()
{
int yToScan = 10;
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
pathMock.Setup(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()))
.Callback<PointF, PointF, PointF[], int>((s, e, b, o) => {
@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void ShapeRegionFromShapeConvertsBoundsProxyToShape()
{
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right);
@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void ShapeRegionFromShapeMaxIntersectionsProxyToShape()
{
ShapeRegion region = new ShapeRegion(pathMock.Object);
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
int i = region.MaxIntersections;
pathMock.Verify(x => x.MaxIntersections);

4
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs

@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
Block8x8F block = CreateRandomFloatBlock(0, 100);
using (var buffer = MemoryManager.Current.Allocate2D<float>(20, 20))
using (var buffer = Configuration.Default.MemoryManager.Allocate2D<float>(20, 20))
{
BufferArea<float> area = buffer.GetArea(5, 10, 8, 8);
block.CopyTo(area);
@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
var start = new Point(50, 50);
using (var buffer = MemoryManager.Current.Allocate2D<float>(100, 100))
using (var buffer = Configuration.Default.MemoryManager.Allocate2D<float>(100, 100))
{
BufferArea<float> area = buffer.GetArea(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor);
block.CopyTo(area, horizontalFactor, verticalFactor);

6
tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs

@ -55,8 +55,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
string imageFile = provider.SourceFileOrDescription;
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile))
using (var pp = new JpegImagePostProcessor(decoder))
using (var imageFrame = new ImageFrame<Rgba32>(decoder.ImageWidth, decoder.ImageHeight))
using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryManager, decoder))
using (var imageFrame = new ImageFrame<Rgba32>(Configuration.Default.MemoryManager, decoder.ImageWidth, decoder.ImageHeight))
{
pp.DoPostProcessorStep(imageFrame);
@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
string imageFile = provider.SourceFileOrDescription;
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile))
using (var pp = new JpegImagePostProcessor(decoder))
using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryManager, decoder))
using (var image = new Image<Rgba32>(decoder.ImageWidth, decoder.ImageHeight))
{
pp.PostProcess(image.Frames.RootFrame);

2
tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
this.HeightInBlocks = heightInBlocks;
this.WidthInBlocks = widthInBlocks;
this.Index = index;
this.SpectralBlocks = MemoryManager.Current.Allocate2D<Block8x8>(this.WidthInBlocks, this.HeightInBlocks);
this.SpectralBlocks = Configuration.Default.MemoryManager.Allocate2D<Block8x8>(this.WidthInBlocks, this.HeightInBlocks);
}
public Size Size => new Size(this.WidthInBlocks, this.HeightInBlocks);

4
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new PngEncoder()
var options = new PngEncoder(Configuration.Default.MemoryManager)
{
PngColorType = pngColorType
};
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests
using (Image<TPixel> image = provider.GetImage())
using (var ms = new MemoryStream())
{
image.Save(ms, new PngEncoder());
image.Save(ms, new PngEncoder(Configuration.Default.MemoryManager));
byte[] data = ms.ToArray().Take(8).ToArray();
byte[] expected = {

4
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
{
// image.Save(provider.Utility.GetTestOutputFileName("bmp"));
image.Save(ms, new PngEncoder());
image.Save(ms, new PngEncoder(Configuration.Default.MemoryManager));
ms.Position = 0;
using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
{
@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
image.Mutate(x => x.Resize(100, 100));
// image.Save(provider.Utility.GetTestOutputFileName("png", "resize"));
image.Save(ms, new PngEncoder());
image.Save(ms, new PngEncoder(Configuration.Default.MemoryManager));
ms.Position = 0;
using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
{

40
tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs

@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Tests
{
ArgumentException ex = Assert.Throws<ArgumentException>(() =>
{
this.collection.AddFrame(new ImageFrame<Rgba32>(1, 1));
this.collection.AddFrame(new ImageFrame<Rgba32>(Configuration.Default.MemoryManager, 1, 1));
});
Assert.StartsWith("Frame must have the same dimensions as the image.", ex.Message);
@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Tests
ArgumentException ex = Assert.Throws<ArgumentException>(() =>
{
this.collection.InsertFrame(1, new ImageFrame<Rgba32>(1, 1));
this.collection.InsertFrame(1, new ImageFrame<Rgba32>(Configuration.Default.MemoryManager, 1, 1));
});
Assert.StartsWith("Frame must have the same dimensions as the image.", ex.Message);
@ -103,8 +103,8 @@ namespace SixLabors.ImageSharp.Tests
ArgumentException ex = Assert.Throws<ArgumentException>(() =>
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(1,1),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,1,1),
});
});
@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.Tests
public void RemoveAtFrame_ThrowIfRemovingLastFrame()
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10)
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10)
});
InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() =>
@ -130,8 +130,8 @@ namespace SixLabors.ImageSharp.Tests
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
});
collection.RemoveFrame(0);
@ -142,8 +142,8 @@ namespace SixLabors.ImageSharp.Tests
public void RootFrameIsFrameAtIndexZero()
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
});
Assert.Equal(collection.RootFrame, collection[0]);
@ -153,8 +153,8 @@ namespace SixLabors.ImageSharp.Tests
public void ConstructorPopulatesFrames()
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
});
Assert.Equal(2, collection.Count);
@ -164,8 +164,8 @@ namespace SixLabors.ImageSharp.Tests
public void DisposeClearsCollection()
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
});
collection.Dispose();
@ -177,8 +177,8 @@ namespace SixLabors.ImageSharp.Tests
public void Dispose_DisposesAllInnerFrames()
{
var collection = new ImageFrameCollection<Rgba32>(this.image, new[] {
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10,10),
});
IPixelSource<Rgba32>[] framesSnapShot = collection.OfType<IPixelSource<Rgba32>>().ToArray();
@ -198,7 +198,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image<TPixel> img = provider.GetImage())
{
img.Frames.AddFrame(new ImageFrame<TPixel>(10, 10));// add a frame anyway
img.Frames.AddFrame(new ImageFrame<TPixel>(Configuration.Default.MemoryManager,10, 10));// add a frame anyway
using (Image<TPixel> cloned = img.Frames.CloneFrame(0))
{
Assert.Equal(2, img.Frames.Count);
@ -216,7 +216,7 @@ namespace SixLabors.ImageSharp.Tests
{
var sourcePixelData = img.GetPixelSpan().ToArray();
img.Frames.AddFrame(new ImageFrame<TPixel>(10, 10));
img.Frames.AddFrame(new ImageFrame<TPixel>(Configuration.Default.MemoryManager,10, 10));
using (Image<TPixel> cloned = img.Frames.ExportFrame(0))
{
Assert.Equal(1, img.Frames.Count);
@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.Tests
public void AddFrame_clones_sourceFrame()
{
var pixelData = this.image.Frames.RootFrame.GetPixelSpan().ToArray();
var otherFRame = new ImageFrame<Rgba32>(10, 10);
var otherFRame = new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10, 10);
var addedFrame = this.image.Frames.AddFrame(otherFRame);
addedFrame.ComparePixelBufferTo(otherFRame.GetPixelSpan());
Assert.NotEqual(otherFRame, addedFrame);
@ -254,7 +254,7 @@ namespace SixLabors.ImageSharp.Tests
public void InsertFrame_clones_sourceFrame()
{
var pixelData = this.image.Frames.RootFrame.GetPixelSpan().ToArray();
var otherFRame = new ImageFrame<Rgba32>(10, 10);
var otherFRame = new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10, 10);
var addedFrame = this.image.Frames.InsertFrame(0, otherFRame);
addedFrame.ComparePixelBufferTo(otherFRame.GetPixelSpan());
Assert.NotEqual(otherFRame, addedFrame);
@ -308,7 +308,7 @@ namespace SixLabors.ImageSharp.Tests
this.image.Frames.CreateFrame();
}
var frame = new ImageFrame<Rgba32>(10, 10);
var frame = new ImageFrame<Rgba32>(Configuration.Default.MemoryManager,10, 10);
Assert.False(this.image.Frames.Contains(frame));
}

2
tests/ImageSharp.Tests/Image/ImageTests.cs

@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Tests
using (Image<Rgba32> image = new Image<Rgba32>(10, 10))
{
image.Save(file, new PngEncoder());
image.Save(file, new PngEncoder(Configuration.Default.MemoryManager));
}
using (Image<Rgba32> img = Image.Load(file, out var mime))
{

10
tests/ImageSharp.Tests/Memory/Buffer2DTests.cs

@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(1025, 17)]
public void Construct(int width, int height)
{
using (Buffer2D<TestStructs.Foo> buffer = MemoryManager.Current.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
{
Assert.Equal(width, buffer.Width);
Assert.Equal(height, buffer.Height);
@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
for (int i = 0; i < 100; i++)
{
using (Buffer2D<int> buffer = Buffer2D<int>.CreateClean(42, 42))
using (Buffer2D<int> buffer = Configuration.Default.MemoryManager.Allocate2D<int>(42, 42, true))
{
for (int j = 0; j < buffer.Buffer.Length; j++)
{
@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(17, 42, 41)]
public void GetRowSpanY(int width, int height, int y)
{
using (Buffer2D<TestStructs.Foo> buffer = MemoryManager.Current.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
{
Span<TestStructs.Foo> span = buffer.GetRowSpan(y);
@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(17, 42, 0, 41)]
public void GetRowSpanXY(int width, int height, int x, int y)
{
using (Buffer2D<TestStructs.Foo> buffer = MemoryManager.Current.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
{
Span<TestStructs.Foo> span = buffer.GetRowSpan(x, y);
@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(99, 88, 98, 87)]
public void Indexer(int width, int height, int x, int y)
{
using (Buffer2D<TestStructs.Foo> buffer = MemoryManager.Current.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
{
TestStructs.Foo[] array = buffer.Buffer.Array;

4
tests/ImageSharp.Tests/Memory/BufferAreaTests.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void Construct()
{
using (var buffer = MemoryManager.Current.Allocate2D<int>(10, 20))
using (var buffer = Configuration.Default.MemoryManager.Allocate2D<int>(10, 20))
{
var rectangle = new Rectangle(3,2, 5, 6);
var area = new BufferArea<int>(buffer, rectangle);
@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
private static Buffer2D<int> CreateTestBuffer(int w, int h)
{
var buffer = MemoryManager.Current.Allocate2D<int>(w, h);
var buffer = Configuration.Default.MemoryManager.Allocate2D<int>(w, h);
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)

22
tests/ImageSharp.Tests/Memory/BufferTests.cs

@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(1111)]
public void ConstructWithOwnArray(int count)
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(count))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(count))
{
Assert.False(buffer.IsDisposedOrLostArrayOwnership);
Assert.NotNull(buffer.Array);
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
for (int i = 0; i < 100; i++)
{
using (Buffer<int> buffer = MemoryManager.Current.Allocate<int>(42, true))
using (Buffer<int> buffer = Configuration.Default.MemoryManager.Allocate<int>(42, true))
{
for (int j = 0; j < buffer.Length; j++)
{
@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void Dispose()
{
Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(42);
Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(42);
buffer.Dispose();
Assert.True(buffer.IsDisposedOrLostArrayOwnership);
@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(123)]
public void CastToSpan(int bufferLength)
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(bufferLength))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(bufferLength))
{
Span<TestStructs.Foo> span = buffer;
@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void Span()
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(42))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(42))
{
Span<TestStructs.Foo> span = buffer.Span;
@ -173,7 +173,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(123, 17)]
public void WithStartOnly(int bufferLength, int start)
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(bufferLength))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(bufferLength))
{
Span<TestStructs.Foo> span = buffer.Slice(start);
@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(123, 17, 42)]
public void WithStartAndLength(int bufferLength, int start, int spanLength)
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(bufferLength))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(bufferLength))
{
Span<TestStructs.Foo> span = buffer.Slice(start, spanLength);
@ -201,7 +201,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public void UnPinAndTakeArrayOwnership()
{
TestStructs.Foo[] data = null;
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(42))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(42))
{
data = buffer.TakeArrayOwnership();
Assert.True(buffer.IsDisposedOrLostArrayOwnership);
@ -216,7 +216,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void ReturnsPinnedPointerToTheBeginningOfArray()
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(42))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(42))
{
TestStructs.Foo* actual = (TestStructs.Foo*)buffer.Pin();
fixed (TestStructs.Foo* expected = buffer.Array)
@ -229,7 +229,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void SecondCallReturnsTheSamePointer()
{
using (Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(42))
using (Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(42))
{
IntPtr ptr1 = buffer.Pin();
IntPtr ptr2 = buffer.Pin();
@ -241,7 +241,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void WhenCalledOnDisposedBuffer_ThrowsInvalidOperationException()
{
Buffer<TestStructs.Foo> buffer = MemoryManager.Current.Allocate<TestStructs.Foo>(42);
Buffer<TestStructs.Foo> buffer = Configuration.Default.MemoryManager.Allocate<TestStructs.Foo>(42);
buffer.Dispose();
Assert.Throws<InvalidOperationException>(() => buffer.Pin());

2
tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs

@ -424,7 +424,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
Rgba32[] colors = { new Rgba32(0, 1, 2, 3), new Rgba32(4, 5, 6, 7), new Rgba32(8, 9, 10, 11), };
using (Buffer<Rgba32> colorBuf = new Buffer<Rgba32>(colors))
using (Buffer<byte> byteBuf = MemoryManager.Current.Allocate<byte>(colors.Length * 4))
using (Buffer<byte> byteBuf = Configuration.Default.MemoryManager.Allocate<byte>(colors.Length * 4))
{
SpanHelper.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Rgba32));

6
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

@ -50,8 +50,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
int times = 200000;
int count = 1024;
using (Buffer<ImageSharp.Rgba32> source = MemoryManager.Current.Allocate<ImageSharp.Rgba32>(count))
using (Buffer<Vector4> dest = MemoryManager.Current.Allocate<Vector4>(count))
using (Buffer<ImageSharp.Rgba32> source = Configuration.Default.MemoryManager.Allocate<ImageSharp.Rgba32>(count))
using (Buffer<Vector4> dest = Configuration.Default.MemoryManager.Allocate<Vector4>(count))
{
this.Measure(
times,
@ -344,7 +344,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
this.SourceBuffer = new Buffer<TSource>(source);
this.ExpectedDestBuffer = new Buffer<TDest>(expectedDest);
this.ActualDestBuffer = MemoryManager.Current.Allocate<TDest>(expectedDest.Length);
this.ActualDestBuffer = Configuration.Default.MemoryManager.Allocate<TDest>(expectedDest.Length);
}
public void Dispose()

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
// [Fact]
public void PrintWeightsData()
{
var proc = new ResizeProcessor<Rgba32>(new BicubicResampler(), 200, 200);
var proc = new ResizeProcessor<Rgba32>(Configuration.Default.MemoryManager, new BicubicResampler(), 200, 200);
ResamplingWeightedProcessor<Rgba32>.WeightsBuffer weights = proc.PrecomputeWeights(200, 500);

12
tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
int length = source.Length;
Guard.MustBeSizedAtLeast(dest, length, nameof(dest));
using (var rgbaBuffer = MemoryManager.Current.Allocate<Rgba32>(length))
using (var rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(length))
{
PixelOperations<TPixel>.Instance.ToRgba32(source, rgbaBuffer, length);
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
int length = source.Length;
Guard.MustBeSizedAtLeast(dest, length, nameof(dest));
using (var rgbaBuffer = MemoryManager.Current.Allocate<Rgba32>(length))
using (var rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(length))
{
PixelOperations<Argb32>.Instance.ToRgba32(source, rgbaBuffer, length);
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
int length = source.Length;
Guard.MustBeSizedAtLeast(dest, length, nameof(dest));
using (var rgbaBuffer = MemoryManager.Current.Allocate<Rgb24>(length))
using (var rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgb24>(length))
{
PixelOperations<Rgb24>.Instance.ToRgb24(source, rgbaBuffer, length);
@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
var image = new Image<TPixel>(w, h);
using (var workBuffer = MemoryManager.Current.Allocate<Argb32>(w))
using (var workBuffer = Configuration.Default.MemoryManager.Allocate<Argb32>(w))
{
var destPtr = (Argb32*)workBuffer.Pin();
for (int y = 0; y < h; y++)
@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
var image = new Image<TPixel>(w, h);
using (var workBuffer = MemoryManager.Current.Allocate<Rgb24>(w))
using (var workBuffer = Configuration.Default.MemoryManager.Allocate<Rgb24>(w))
{
var destPtr = (Rgb24*)workBuffer.Pin();
for (int y = 0; y < h; y++)
@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
long destRowByteCount = data.Stride;
long sourceRowByteCount = w * sizeof(Argb32);
using (var workBuffer = MemoryManager.Current.Allocate<Argb32>(w))
using (var workBuffer = Configuration.Default.MemoryManager.Allocate<Argb32>(w))
{
var sourcePtr = (Argb32*)workBuffer.Pin();

2
tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs

@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests
sourceImage.Mutate(c => c.Alpha(1));
}
var encoder = new PngEncoder() { PngColorType = pngColorType };
var encoder = new PngEncoder(Configuration.Default.MemoryManager) { PngColorType = pngColorType };
return provider.Utility.SaveTestOutputFile(sourceImage, "png", encoder);
}
}

Loading…
Cancel
Save