Browse Source

fix build after merge

pull/475/head
Anton Firszov 8 years ago
parent
commit
af23153775
  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> where TPixel : struct, IPixel<TPixel>
=> source.Frames.RootFrame.GetPixelRowSpan(row); => 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> /// <summary>
/// Gets the span to the backing buffer. /// Gets the span to the backing buffer.
/// </summary> /// </summary>

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

@ -92,6 +92,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// </summary> /// </summary>
public FrameDecodingMode DecodingMode { get; } public FrameDecodingMode DecodingMode { get; }
private MemoryManager MemoryManager => this.configuration.MemoryManager;
/// <summary> /// <summary>
/// Decodes the stream to the image. /// Decodes the stream to the image.
/// </summary> /// </summary>
@ -148,7 +150,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
{ {
break; break;
} }
this.globalColorTable = this.configuration.MemoryManager.Allocate<byte>(this.globalColorTableLength, true);
this.globalColorTable = this.MemoryManager.Allocate<byte>(this.globalColorTableLength, true);
nextFlag = stream.ReadByte(); nextFlag = stream.ReadByte();
if (nextFlag == -1) if (nextFlag == -1)
@ -334,7 +337,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
continue; 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); this.currentStream.Read(commentsBuffer.Array, 0, length);
string comments = this.TextEncoding.GetString(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) if (this.logicalScreenDescriptor.GlobalColorTableFlag)
{ {
this.globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3; 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 // Read the global color table from the stream
stream.Read(this.globalColorTable.Array, 0, this.globalColorTableLength); 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.textEncoding = options.TextEncoding ?? PngConstants.DefaultEncoding;
this.ignoreMetadata = options.IgnoreMetadata; this.ignoreMetadata = options.IgnoreMetadata;
} }
private MemoryManager MemoryManager => this.configuration.MemoryManager;
/// <summary> /// <summary>
/// Decodes the stream to the image. /// Decodes the stream to the image.
@ -297,17 +299,17 @@ namespace SixLabors.ImageSharp.Formats.Png
switch (currentChunk.Type) switch (currentChunk.Type)
{ {
case PngChunkTypes.Header: case PngChunkTypes.Header:
this.ReadHeaderChunk(currentChunk.Data); this.ReadHeaderChunk(currentChunk.Data.Array);
this.ValidateHeader(); this.ValidateHeader();
break; break;
case PngChunkTypes.Physical: case PngChunkTypes.Physical:
this.ReadPhysicalChunk(metadata, currentChunk.Data); this.ReadPhysicalChunk(metadata, currentChunk.Data.Array);
break; break;
case PngChunkTypes.Data: case PngChunkTypes.Data:
this.SkipChunkDataAndCrc(currentChunk); this.SkipChunkDataAndCrc(currentChunk);
break; break;
case PngChunkTypes.Text: case PngChunkTypes.Text:
this.ReadTextChunk(metadata, currentChunk.Data, currentChunk.Length); this.ReadTextChunk(metadata, currentChunk.Data.Array, currentChunk.Length);
break; break;
case PngChunkTypes.End: case PngChunkTypes.End:
this.isEndChunkReached = true; this.isEndChunkReached = true;
@ -319,7 +321,7 @@ namespace SixLabors.ImageSharp.Formats.Png
// Data is rented in ReadChunkData() // Data is rented in ReadChunkData()
if (currentChunk.Data != null) 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.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); this.scanline = this.configuration.MemoryManager.Allocate<byte>(this.bytesPerScanline, true);
} }
/// <summary> /// <summary>
/// Calculates the correct number of bits per pixel for the given color type. /// Calculates the correct number of bits per pixel for the given color type.
/// </summary> /// </summary>

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

@ -61,16 +61,18 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class. /// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
/// </summary> /// </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="size">The <see cref="Size"/> of the frame.</param>
/// <param name="metaData">The meta data.</param> /// <param name="metaData">The meta data.</param>
internal ImageFrame(Size size, ImageFrameMetaData metaData) internal ImageFrame(MemoryManager memoryManager, Size size, ImageFrameMetaData metaData)
: this(size.Width, size.Height, metaData) : this(memoryManager, size.Width, size.Height, metaData)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class. /// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
internal ImageFrame(MemoryManager memoryManager, ImageFrame<TPixel> source) 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 // We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = 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 // Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames); 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 xLength = (int)MathF.Ceiling((radius.X * 2) + 2);
int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2); int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2);
using (var yBuffer = new Buffer2D<float>(yLength, height)) MemoryManager memoryManager = configuration.MemoryManager;
using (var xBuffer = new Buffer2D<float>(xLength, height))
using (Buffer2D<float> yBuffer = memoryManager.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryManager.Allocate2D<float>(xLength, height))
{ {
Parallel.For( Parallel.For(
0, 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 // We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable<ImageFrame<TPixel>> frames = IEnumerable<ImageFrame<TPixel>> frames = source.Frames.Select(
source.Frames.Select(x => new ImageFrame<TPixel>(this.targetRectangle.Width, this.targetRectangle.Height, x.MetaData.Clone())); x => new ImageFrame<TPixel>(
source.GetMemoryManager(),
this.targetRectangle.Size,
x.MetaData.Clone()));
// Use the overload to prevent an extra frame being added // Use the overload to prevent an extra frame being added
return new Image<TPixel>(source.GetConfiguration(), source.MetaData.Clone(), frames); 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 xLength = (int)MathF.Ceiling((radius.X * 2) + 2);
int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2); int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2);
using (var yBuffer = new Buffer2D<float>(yLength, height)) MemoryManager memoryManager = configuration.MemoryManager;
using (var xBuffer = new Buffer2D<float>(xLength, height))
using (Buffer2D<float> yBuffer = memoryManager.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryManager.Allocate2D<float>(xLength, height))
{ {
Parallel.For( Parallel.For(
0, 0,

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

@ -17,11 +17,12 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WeightsBuffer"/> class. /// Initializes a new instance of the <see cref="WeightsBuffer"/> class.
/// </summary> /// </summary>
/// <param name="memoryManager">The MemoryManager to use for allocations.</param>
/// <param name="sourceSize">The size of the source window</param> /// <param name="sourceSize">The size of the source window</param>
/// <param name="destinationSize">The size of the destination 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]; 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.flatStartIndex = (index * buffer.Width) + left;
this.Left = left; this.Left = left;
this.buffer = buffer; this.buffer = buffer.Buffer;
this.Length = length; this.Length = length;
} }

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

@ -14,7 +14,8 @@ namespace SixLabors.ImageSharp.Tests
{ {
using System; using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
public class GeneralFormatTests : FileTestBase public class GeneralFormatTests : FileTestBase
{ {
@ -178,7 +179,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
using (var memoryStream = new MemoryStream()) using (var memoryStream = new MemoryStream())
{ {
image.Save(memoryStream, GetEncoder(format)); image.Save(memoryStream, GetEncoder(image.GetMemoryManager(), format));
memoryStream.Position = 0; memoryStream.Position = 0;
var imageInfo = Image.Identify(memoryStream); 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) switch (format)
{ {
case "png": case "png":
return new PngEncoder(); return new PngEncoder(memoryManager);
case "gif": case "gif":
return new GifEncoder(); return new GifEncoder();
case "bmp": 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 namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
using SixLabors.ImageSharp.Memory;
public class ResizeProfilingBenchmarks : MeasureFixture public class ResizeProfilingBenchmarks : MeasureFixture
{ {
public ResizeProfilingBenchmarks(ITestOutputHelper output) public ResizeProfilingBenchmarks(ITestOutputHelper output)
@ -38,7 +40,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
// [Fact] // [Fact]
public void PrintWeightsData() public void PrintWeightsData()
{ {
var proc = new ResizeProcessor<Rgba32>(KnownResamplers.Bicubic, 200, 200);
var proc = new ResizeProcessor<Rgba32>(Configuration.Default.MemoryManager, new BicubicResampler(), 200, 200); var proc = new ResizeProcessor<Rgba32>(Configuration.Default.MemoryManager, new BicubicResampler(), 200, 200);
WeightsBuffer weights = proc.PrecomputeWeights(200, 500); WeightsBuffer weights = proc.PrecomputeWeights(200, 500);

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

@ -12,7 +12,7 @@
{ {
var palette = new PaletteQuantizer<Rgba32>(); var palette = new PaletteQuantizer<Rgba32>();
var octree = new OctreeQuantizer<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(palette.Dither);
Assert.True(octree.Dither); Assert.True(octree.Dither);

Loading…
Cancel
Save