Browse Source

fix build after merge

af/merge-core
Anton Firszov 8 years ago
parent
commit
c08b155d2c
  1. 8
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  2. 10
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  3. 13
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  4. 6
      src/ImageSharp/Image/ImageFrame{TPixel}.cs
  5. 8
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
  6. 13
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
  7. 5
      src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs
  8. 2
      src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs
  9. 9
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  10. 3
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs
  11. 2
      tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs

8
src/ImageSharp/Advanced/AdvancedImageExtensions.cs

@ -88,6 +88,14 @@ namespace SixLabors.ImageSharp.Advanced
where TPixel : struct, IPixel<TPixel>
=> source.Frames.RootFrame.GetPixelRowSpan(row);
/// <summary>
/// Gets the <see cref="MemoryManager"/> assigned to 'source'.
/// </summary>
/// <param name="source">The source image</param>
/// <returns>Returns the configuration.</returns>
internal static MemoryManager GetMemoryManager(this IConfigurable source)
=> GetConfiguration(source).MemoryManager;
/// <summary>
/// Gets the span to the backing buffer.
/// </summary>

10
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -92,6 +92,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// </summary>
public FrameDecodingMode DecodingMode { get; }
private MemoryManager MemoryManager => this.configuration.MemoryManager;
/// <summary>
/// Decodes the stream to the image.
/// </summary>
@ -148,7 +150,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
break;
}
this.globalColorTable = this.configuration.MemoryManager.Allocate<byte>(this.globalColorTableLength, true);
this.globalColorTable = this.MemoryManager.Allocate<byte>(this.globalColorTableLength, true);
nextFlag = stream.ReadByte();
if (nextFlag == -1)
@ -334,7 +337,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
continue;
}
using (Buffer<byte> commentsBuffer = this.configuration.MemoryManager.Allocate<byte>(length))
using (Buffer<byte> commentsBuffer = this.MemoryManager.Allocate<byte>(length))
{
this.currentStream.Read(commentsBuffer.Array, 0, length);
string comments = this.TextEncoding.GetString(commentsBuffer.Array, 0, length);
@ -601,7 +604,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
if (this.logicalScreenDescriptor.GlobalColorTableFlag)
{
this.globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3;
this.globalColorTable = Buffer<byte>.CreateClean(this.globalColorTableLength);
this.globalColorTable = this.MemoryManager.Allocate<byte>(this.globalColorTableLength, true);
// Read the global color table from the stream
stream.Read(this.globalColorTable.Array, 0, this.globalColorTableLength);

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

@ -190,6 +190,8 @@ namespace SixLabors.ImageSharp.Formats.Png
this.textEncoding = options.TextEncoding ?? PngConstants.DefaultEncoding;
this.ignoreMetadata = options.IgnoreMetadata;
}
private MemoryManager MemoryManager => this.configuration.MemoryManager;
/// <summary>
/// Decodes the stream to the image.
@ -297,17 +299,17 @@ namespace SixLabors.ImageSharp.Formats.Png
switch (currentChunk.Type)
{
case PngChunkTypes.Header:
this.ReadHeaderChunk(currentChunk.Data);
this.ReadHeaderChunk(currentChunk.Data.Array);
this.ValidateHeader();
break;
case PngChunkTypes.Physical:
this.ReadPhysicalChunk(metadata, currentChunk.Data);
this.ReadPhysicalChunk(metadata, currentChunk.Data.Array);
break;
case PngChunkTypes.Data:
this.SkipChunkDataAndCrc(currentChunk);
break;
case PngChunkTypes.Text:
this.ReadTextChunk(metadata, currentChunk.Data, currentChunk.Length);
this.ReadTextChunk(metadata, currentChunk.Data.Array, currentChunk.Length);
break;
case PngChunkTypes.End:
this.isEndChunkReached = true;
@ -319,7 +321,7 @@ namespace SixLabors.ImageSharp.Formats.Png
// Data is rented in ReadChunkData()
if (currentChunk.Data != null)
{
ArrayPool<byte>.Shared.Return(currentChunk.Data);
ArrayPool<byte>.Shared.Return(currentChunk.Data.Array);
}
}
}
@ -435,10 +437,11 @@ namespace SixLabors.ImageSharp.Formats.Png
this.bytesPerSample = this.header.BitDepth / 8;
}
this.previousScanline = this.configuration.MemoryManager.Allocate<byte>(this.bytesPerScanline, true);
this.previousScanline = this.MemoryManager.Allocate<byte>(this.bytesPerScanline, true);
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>

6
src/ImageSharp/Image/ImageFrame{TPixel}.cs

@ -61,16 +61,18 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="size">The <see cref="Size"/> of the frame.</param>
/// <param name="metaData">The meta data.</param>
internal ImageFrame(Size size, ImageFrameMetaData metaData)
: this(size.Width, size.Height, metaData)
internal ImageFrame(MemoryManager memoryManager, Size size, ImageFrameMetaData metaData)
: this(memoryManager, size.Width, size.Height, metaData)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="source">The source.</param>
internal ImageFrame(MemoryManager memoryManager, ImageFrame<TPixel> source)
{

8
src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs

@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames =
source.Frames.Select(x => new ImageFrame<TPixel>(this.targetDimensions, x.MetaData.Clone()));
source.Frames.Select(x => new ImageFrame<TPixel>(source.GetMemoryManager(), this.targetDimensions, x.MetaData.Clone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
@ -130,8 +130,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
int xLength = (int)MathF.Ceiling((radius.X * 2) + 2);
int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2);
using (var yBuffer = new Buffer2D<float>(yLength, height))
using (var xBuffer = new Buffer2D<float>(xLength, height))
MemoryManager memoryManager = configuration.MemoryManager;
using (Buffer2D<float> yBuffer = memoryManager.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryManager.Allocate2D<float>(xLength, height))
{
Parallel.For(
0,

13
src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs

@ -73,8 +73,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames =
source.Frames.Select(x => new ImageFrame<TPixel>(this.targetRectangle.Width, this.targetRectangle.Height, x.MetaData.Clone()));
IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(
x => new ImageFrame<TPixel>(
source.GetMemoryManager(),
this.targetRectangle.Size,
x.MetaData.Clone()));
// Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames);
@ -125,8 +128,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
int xLength = (int)MathF.Ceiling((radius.X * 2) + 2);
int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2);
using (var yBuffer = new Buffer2D<float>(yLength, height))
using (var xBuffer = new Buffer2D<float>(xLength, height))
MemoryManager memoryManager = configuration.MemoryManager;
using (Buffer2D<float> yBuffer = memoryManager.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryManager.Allocate2D<float>(xLength, height))
{
Parallel.For(
0,

5
src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs

@ -17,11 +17,12 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <summary>
/// Initializes a new instance of the <see cref="WeightsBuffer"/> class.
/// </summary>
/// <param name="memoryManager">The MemoryManager to use for allocations.</param>
/// <param name="sourceSize">The size of the source window</param>
/// <param name="destinationSize">The size of the destination window</param>
public WeightsBuffer(int sourceSize, int destinationSize)
public WeightsBuffer(MemoryManager memoryManager, int sourceSize, int destinationSize)
{
this.dataBuffer = Buffer2D<float>.CreateClean(sourceSize, destinationSize);
this.dataBuffer = memoryManager.Allocate2D<float>(sourceSize, destinationSize, true);
this.Weights = new WeightsWindow[destinationSize];
}

2
src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs

@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
this.flatStartIndex = (index * buffer.Width) + left;
this.Left = left;
this.buffer = buffer;
this.buffer = buffer.Buffer;
this.Length = length;
}

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

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

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

@ -11,6 +11,8 @@ using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
using SixLabors.ImageSharp.Memory;
public class ResizeProfilingBenchmarks : MeasureFixture
{
public ResizeProfilingBenchmarks(ITestOutputHelper output)
@ -38,7 +40,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
// [Fact]
public void PrintWeightsData()
{
var proc = new ResizeProcessor<Rgba32>(KnownResamplers.Bicubic, 200, 200);
var proc = new ResizeProcessor<Rgba32>(Configuration.Default.MemoryManager, new BicubicResampler(), 200, 200);
WeightsBuffer weights = proc.PrecomputeWeights(200, 500);

2
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>();
var wu = new WuQuantizer<Rgba32>(Configuration.Default.MemoryManager);
Assert.True(palette.Dither);
Assert.True(octree.Dither);

Loading…
Cancel
Save