Browse Source

dropping MemoryManager ctr. argument:

PngEncoder, WuQuantizer, ShapeRegion, ShapePath
pull/475/head
Anton Firszov 8 years ago
parent
commit
3819c756a9
  1. 2
      src/ImageSharp.Drawing/Paths/DrawPath.cs
  2. 4
      src/ImageSharp.Drawing/Paths/FillPaths.cs
  3. 5
      src/ImageSharp.Drawing/Paths/ShapePath.cs
  4. 23
      src/ImageSharp.Drawing/Paths/ShapeRegion.cs
  5. 2
      src/ImageSharp/Formats/Png/PngConfigurationModule.cs
  6. 3
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  7. 15
      src/ImageSharp/Formats/Png/PngEncoder.cs
  8. 2
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  9. 1
      src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs
  10. 2
      src/ImageSharp/Quantizers/Quantize.cs
  11. 52
      src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs
  12. 10
      tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs
  13. 2
      tests/ImageSharp.Benchmarks/Image/EncodePng.cs
  14. 127
      tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs
  15. 9
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  16. 2
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  17. 4
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  18. 2
      tests/ImageSharp.Tests/Image/ImageTests.cs
  19. 4
      tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs
  20. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs

2
src/ImageSharp.Drawing/Paths/DrawPath.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(pen.StrokeFill, new ShapePath(source.GetMemoryManager(), path, pen), options);
return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options);
}
/// <summary>

4
src/ImageSharp.Drawing/Paths/FillPaths.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(source.GetMemoryManager(), path), options);
return source.Fill(brush, new ShapeRegion(path), options);
}
/// <summary>
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(source.GetMemoryManager(), path), GraphicsOptions.Default);
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
}
/// <summary>

5
src/ImageSharp.Drawing/Paths/ShapePath.cs

@ -18,12 +18,11 @@ namespace SixLabors.ImageSharp.Drawing
/// <summary>
/// Initializes a new instance of the <see cref="ShapePath"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="shape">The shape.</param>
/// <param name="pen">The pen to apply to the shape.</param>
// SixLabors.shape willbe moving to a Span/ReadOnlySpan based API shortly use ToArray for now.
public ShapePath(MemoryManager memoryManager, IPath shape, Pens.IPen pen)
: base(memoryManager, shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern.ToArray()))
public ShapePath(IPath shape, Pens.IPen pen)
: base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern.ToArray()))
{
}
}

23
src/ImageSharp.Drawing/Paths/ShapeRegion.cs

@ -15,16 +15,12 @@ namespace SixLabors.ImageSharp.Drawing
/// </summary>
internal class ShapeRegion : Region
{
private readonly MemoryManager memoryManager;
/// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="shape">The shape.</param>
public ShapeRegion(MemoryManager memoryManager, IPath shape)
public ShapeRegion(IPath shape)
{
this.memoryManager = memoryManager;
this.Shape = shape.AsClosedPath();
int left = (int)MathF.Floor(shape.Bounds.Left);
int top = (int)MathF.Floor(shape.Bounds.Top);
@ -50,18 +46,17 @@ namespace SixLabors.ImageSharp.Drawing
{
var start = new PointF(this.Bounds.Left - 1, y);
var end = new PointF(this.Bounds.Right + 1, y);
using (var innerBuffer = this.memoryManager.Allocate<PointF>(buffer.Length))
{
PointF[] array = innerBuffer.Array;
int count = this.Shape.FindIntersections(start, end, array, 0);
for (int i = 0; i < count; i++)
{
buffer[i + offset] = array[i].X;
}
// TODO: This is a temporal workaround because of the lack of Span<T> API-s on IPath. We should use MemoryManager.Allocate() here!
PointF[] innerBuffer = new PointF[buffer.Length];
int count = this.Shape.FindIntersections(start, end, innerBuffer, 0);
return count;
for (int i = 0; i < count; i++)
{
buffer[i + offset] = innerBuffer[i].X;
}
return count;
}
}
}

2
src/ImageSharp/Formats/Png/PngConfigurationModule.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <inheritdoc/>
public void Configure(Configuration config)
{
config.SetEncoder(ImageFormats.Png, new PngEncoder(config.MemoryManager));
config.SetEncoder(ImageFormats.Png, new PngEncoder());
config.SetDecoder(ImageFormats.Png, new PngDecoder());
config.AddImageFormatDetector(new PngImageFormatDetector());
}

3
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.textEncoding = options.TextEncoding ?? PngConstants.DefaultEncoding;
this.ignoreMetadata = options.IgnoreMetadata;
}
private MemoryManager MemoryManager => this.configuration.MemoryManager;
/// <summary>
@ -441,7 +441,6 @@ namespace SixLabors.ImageSharp.Formats.Png
this.scanline = this.configuration.MemoryManager.Allocate<byte>(this.bytesPerScanline, true);
}
/// <summary>
/// Calculates the correct number of bits per pixel for the given color type.
/// </summary>

15
src/ImageSharp/Formats/Png/PngEncoder.cs

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
@ -14,17 +14,6 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary>
public sealed class PngEncoder : IImageEncoder, IPngEncoderOptions
{
private readonly MemoryManager memoryManager;
/// <summary>
/// Initializes a new instance of the <see cref="PngEncoder"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
public PngEncoder(MemoryManager memoryManager)
{
this.memoryManager = memoryManager;
}
/// <summary>
/// Gets or sets a value indicating whether the metadata should be ignored when the image is being encoded.
/// </summary>
@ -79,7 +68,7 @@ namespace SixLabors.ImageSharp.Formats.Png
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
using (var encoder = new PngEncoderCore(this.memoryManager, this))
using (var encoder = new PngEncoderCore(image.GetMemoryManager(), this))
{
encoder.Encode(image, stream);
}

2
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -508,7 +508,7 @@ namespace SixLabors.ImageSharp.Formats.Png
if (this.quantizer == null)
{
this.quantizer = new WuQuantizer<TPixel>(this.memoryManager);
this.quantizer = new WuQuantizer<TPixel>();
}
// Quantize the image returning a palette. This boxing is icky.

1
src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;

2
src/ImageSharp/Quantizers/Quantize.cs

@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp
switch (mode)
{
case Quantization.Wu:
quantizer = new WuQuantizer<TPixel>(source.GetMemoryManager());
quantizer = new WuQuantizer<TPixel>();
break;
case Quantization.Palette:

52
src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs

@ -36,8 +36,6 @@ namespace SixLabors.ImageSharp.Quantizers
public class WuQuantizer<TPixel> : QuantizerBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly MemoryManager memoryManager;
/// <summary>
/// The index bits.
/// </summary>
@ -121,15 +119,13 @@ namespace SixLabors.ImageSharp.Quantizers
/// <summary>
/// Initializes a new instance of the <see cref="WuQuantizer{TPixel}"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <remarks>
/// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram,
/// the second pass quantizes a color based on the position in the histogram.
/// </remarks>
public WuQuantizer(MemoryManager memoryManager)
public WuQuantizer()
: base(false)
{
this.memoryManager = memoryManager;
}
/// <inheritdoc/>
@ -141,15 +137,17 @@ namespace SixLabors.ImageSharp.Quantizers
this.palette = null;
this.colorMap.Clear();
MemoryManager memoryManager = image.MemoryManager;
try
{
this.vwt = this.memoryManager.Allocate<long>(TableLength, true);
this.vmr = this.memoryManager.Allocate<long>(TableLength, true);
this.vmg = this.memoryManager.Allocate<long>(TableLength, true);
this.vmb = this.memoryManager.Allocate<long>(TableLength, true);
this.vma = this.memoryManager.Allocate<long>(TableLength, true);
this.m2 = this.memoryManager.Allocate<float>(TableLength, true);
this.tag = this.memoryManager.Allocate<byte>(TableLength, true);
this.vwt = memoryManager.AllocateClean<long>(TableLength);
this.vmr = memoryManager.AllocateClean<long>(TableLength);
this.vmg = memoryManager.AllocateClean<long>(TableLength);
this.vmb = memoryManager.AllocateClean<long>(TableLength);
this.vma = memoryManager.AllocateClean<long>(TableLength);
this.m2 = memoryManager.AllocateClean<float>(TableLength);
this.tag = memoryManager.AllocateClean<byte>(TableLength);
return base.Quantize(image, this.colors);
}
@ -240,7 +238,7 @@ namespace SixLabors.ImageSharp.Quantizers
}
}
this.Get3DMoments();
this.Get3DMoments(source.MemoryManager);
this.BuildCube();
}
@ -458,21 +456,21 @@ namespace SixLabors.ImageSharp.Quantizers
/// <summary>
/// Converts the histogram into moments so that we can rapidly calculate the sums of the above quantities over any desired box.
/// </summary>
private void Get3DMoments()
private void Get3DMoments(MemoryManager memoryManager)
{
using (Buffer<long> volume = this.memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeR = this.memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeG = this.memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeB = this.memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeA = this.memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<float> volume2 = this.memoryManager.Allocate<float>(IndexCount * IndexAlphaCount))
using (Buffer<long> area = this.memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaR = this.memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaG = this.memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaB = this.memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaA = this.memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<float> area2 = this.memoryManager.Allocate<float>(IndexAlphaCount))
using (Buffer<long> volume = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeR = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeG = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeB = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeA = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<float> volume2 = memoryManager.Allocate<float>(IndexCount * IndexAlphaCount))
using (Buffer<long> area = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaR = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaG = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaB = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaA = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<float> area2 = memoryManager.Allocate<float>(IndexAlphaCount))
{
for (int r = 1; r < IndexCount; r++)
{

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(Configuration.Default.MemoryManager) { Quantizer = new OctreeQuantizer<Rgba32>(), PaletteSize = 256 };
PngEncoder encoder = new PngEncoder() { 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(Configuration.Default.MemoryManager) { Quantizer = new OctreeQuantizer<Rgba32> { Dither = false }, PaletteSize = 256 };
PngEncoder options = new PngEncoder() { 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(Configuration.Default.MemoryManager) { Quantizer = new PaletteQuantizer<Rgba32>(), PaletteSize = 256 };
PngEncoder options = new PngEncoder() { 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(Configuration.Default.MemoryManager) { Quantizer = new PaletteQuantizer<Rgba32> { Dither = false }, PaletteSize = 256 };
PngEncoder options = new PngEncoder() { 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(Configuration.Default.MemoryManager) { Quantizer = new WuQuantizer<Rgba32>(Configuration.Default.MemoryManager), PaletteSize = 256 };
PngEncoder options = new PngEncoder() { 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(Configuration.Default.MemoryManager) { Quantizer = quantizer };
var options = new PngEncoder() { Quantizer = quantizer };
this.bmpCore.SaveAsPng(memoryStream, options);
}
}

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

@ -1,131 +1,144 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.Processing;
using Moq;
using SixLabors.Primitives;
using SixLabors.Shapes;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
public class ShapeRegionTests
using System;
using Moq;
using SixLabors.ImageSharp.Drawing;
using SixLabors.Primitives;
using SixLabors.Shapes;
using Xunit;
public class ShapeRegionTests
{
private readonly Mock<IPath> pathMock;
private readonly SixLabors.Primitives.RectangleF bounds;
private readonly RectangleF bounds;
public ShapeRegionTests()
{
this.pathMock = new Mock<IPath>();
this.bounds = new RectangleF(10.5f, 10, 10, 10);
pathMock.Setup(x => x.Bounds).Returns(this.bounds);
this.pathMock.Setup(x => x.Bounds).Returns(this.bounds);
// wire up the 2 mocks to reference eachother
pathMock.Setup(x => x.AsClosedPath()).Returns(() => pathMock.Object);
this.pathMock.Setup(x => x.AsClosedPath()).Returns(() => this.pathMock.Object);
}
[Fact]
public void ShapeRegionWithPathCallsAsShape()
{
new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
new ShapeRegion(this.pathMock.Object);
pathMock.Verify(x => x.AsClosedPath());
this.pathMock.Verify(x => x.AsClosedPath());
}
[Fact]
public void ShapeRegionWithPathRetainsShape()
{
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
Assert.Equal(pathMock.Object, region.Shape);
Assert.Equal(this.pathMock.Object, region.Shape);
}
[Fact]
public void ShapeRegionFromPathConvertsBoundsProxyToShape()
{
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right);
Assert.Equal(Math.Floor(this.bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(this.bounds.Right), region.Bounds.Right);
pathMock.Verify(x => x.Bounds);
this.pathMock.Verify(x => x.Bounds);
}
[Fact]
public void ShapeRegionFromPathMaxIntersectionsProxyToShape()
{
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
int i = region.MaxIntersections;
pathMock.Verify(x => x.MaxIntersections);
this.pathMock.Verify(x => x.MaxIntersections);
}
[Fact]
public void ShapeRegionFromPathScanYProxyToShape()
{
int yToScan = 10;
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) => {
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
Assert.True(s.X < bounds.Left);
Assert.True(e.X > bounds.Right);
}).Returns(0);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
this.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) =>
{
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
Assert.True(s.X < this.bounds.Left);
Assert.True(e.X > this.bounds.Right);
}).Returns(0);
int i = region.Scan(yToScan, new float[0], 0);
pathMock.Verify(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()), Times.Once);
this.pathMock.Verify(
x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()),
Times.Once);
}
[Fact]
public void ShapeRegionFromShapeScanYProxyToShape()
{
int yToScan = 10;
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) => {
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
Assert.True(s.X < bounds.Left);
Assert.True(e.X > bounds.Right);
}).Returns(0);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
this.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) =>
{
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
Assert.True(s.X < this.bounds.Left);
Assert.True(e.X > this.bounds.Right);
}).Returns(0);
int i = region.Scan(yToScan, new float[0], 0);
pathMock.Verify(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()), Times.Once);
this.pathMock.Verify(
x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()),
Times.Once);
}
[Fact]
public void ShapeRegionFromShapeConvertsBoundsProxyToShape()
{
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right);
Assert.Equal(Math.Floor(this.bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(this.bounds.Right), region.Bounds.Right);
pathMock.Verify(x => x.Bounds);
this.pathMock.Verify(x => x.Bounds);
}
[Fact]
public void ShapeRegionFromShapeMaxIntersectionsProxyToShape()
{
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object);
ShapeRegion region = new ShapeRegion(this.pathMock.Object);
int i = region.MaxIntersections;
pathMock.Verify(x => x.MaxIntersections);
this.pathMock.Verify(x => x.MaxIntersections);
}
}
}
}

9
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -14,9 +14,6 @@ namespace SixLabors.ImageSharp.Tests
{
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
public class GeneralFormatTests : FileTestBase
{
[Theory]
@ -179,7 +176,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (var memoryStream = new MemoryStream())
{
image.Save(memoryStream, GetEncoder(image.GetMemoryManager(), format));
image.Save(memoryStream, GetEncoder(format));
memoryStream.Position = 0;
var imageInfo = Image.Identify(memoryStream);
@ -190,12 +187,12 @@ namespace SixLabors.ImageSharp.Tests
}
}
private static IImageEncoder GetEncoder(MemoryManager memoryManager, string format)
private static IImageEncoder GetEncoder(string format)
{
switch (format)
{
case "png":
return new PngEncoder(memoryManager);
return new PngEncoder();
case "gif":
return new GifEncoder();
case "bmp":

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

@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.Tests
using (Image<TPixel> image = provider.GetImage())
using (var ms = new MemoryStream())
{
image.Save(ms, new PngEncoder(Configuration.Default.MemoryManager));
image.Save(ms, new PngEncoder());
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(Configuration.Default.MemoryManager));
image.Save(ms, new PngEncoder());
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(Configuration.Default.MemoryManager));
image.Save(ms, new PngEncoder());
ms.Position = 0;
using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
{

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(Configuration.Default.MemoryManager));
image.Save(file, new PngEncoder());
}
using (Image<Rgba32> img = Image.Load(file, out var mime))
{

4
tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs

@ -12,7 +12,7 @@
{
var palette = new PaletteQuantizer<Rgba32>();
var octree = new OctreeQuantizer<Rgba32>();
var wu = new WuQuantizer<Rgba32>(Configuration.Default.MemoryManager);
var wu = new WuQuantizer<Rgba32>();
Assert.True(palette.Dither);
Assert.True(octree.Dither);
@ -73,7 +73,7 @@
{
Assert.True(image[0, 0].Equals(default(TPixel)));
IQuantizer<TPixel> quantizer = new WuQuantizer<TPixel>(Configuration.Default.MemoryManager) { Dither = dither };
IQuantizer<TPixel> quantizer = new WuQuantizer<TPixel>() { Dither = dither };
foreach (ImageFrame<TPixel> frame in image.Frames)
{

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

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

Loading…
Cancel
Save