From e610fd0f7a327a9dbe177c528757f4f00327c031 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 8 Jun 2018 00:43:43 +0200 Subject: [PATCH 01/17] Change IBuffer.Span to IBuffer.GetSpan() to match System.Buffers.MemoryManager API --- .../Drawing/Brushes/BrushApplicator.cs | 4 +- .../Drawing/Brushes/ImageBrush{TPixel}.cs | 4 +- .../Drawing/Brushes/PatternBrush{TPixel}.cs | 4 +- .../Drawing/Brushes/RecolorBrush{TPixel}.cs | 4 +- .../Drawing/Brushes/SolidBrush{TPixel}.cs | 10 +- .../Drawing/Processors/DrawImageProcessor.cs | 4 +- .../Drawing/Processors/FillProcessor.cs | 4 +- .../Drawing/Processors/FillRegionProcessor.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 6 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 4 +- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 6 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/LzwDecoder.cs | 6 +- src/ImageSharp/Formats/Gif/LzwEncoder.cs | 6 +- .../Decoder/JpegImagePostProcessor.cs | 4 +- .../PdfJsPort/Components/PdfJsHuffmanTable.cs | 4 +- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 8 +- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 28 ++--- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 32 +++--- src/ImageSharp/Image.Decode.cs | 2 +- src/ImageSharp/ImageFrame{TPixel}.cs | 2 +- .../ArrayPoolMemoryManager.Buffer{T}.cs | 2 +- src/ImageSharp/Memory/BasicArrayBuffer.cs | 7 +- src/ImageSharp/Memory/Buffer2D{T}.cs | 4 +- src/ImageSharp/Memory/BufferExtensions.cs | 10 +- src/ImageSharp/Memory/IBuffer{T}.cs | 3 +- .../Processors/BackgroundColorProcessor.cs | 6 +- .../Overlays/Processors/GlowProcessor.cs | 6 +- .../Overlays/Processors/VignetteProcessor.cs | 6 +- .../WuFrameQuantizer{TPixel}.cs | 106 +++++++++--------- .../Transforms/Processors/ResizeProcessor.cs | 2 +- .../Transforms/Processors/WeightsWindow.cs | 2 +- .../Color/Bulk/PackFromVector4.cs | 8 +- .../Color/Bulk/PackFromXyzw.cs | 8 +- .../Formats/Jpg/SpectralJpegTests.cs | 2 +- .../Memory/ArrayPoolMemoryManagerTests.cs | 6 +- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 2 +- .../Memory/BufferTestSuite.cs | 22 ++-- .../PixelFormats/PixelOperationsTests.cs | 36 +++--- .../ReferenceCodecs/SystemDrawingBridge.cs | 8 +- 40 files changed, 197 insertions(+), 195 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs index c54666335..83bff9c47 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs @@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs index c2e3a16ef..dfdc1721d 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs @@ -121,8 +121,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); int sourceY = (y - this.offsetY) % this.yLength; int offsetX = x - this.offsetX; diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs index 765f2a132..b5bc5a7ef 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs @@ -156,8 +156,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs index 324c54e18..05607472e 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -141,8 +141,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs index f2054ee0d..a32152ba0 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes : base(source, options) { this.Colors = source.MemoryManager.Allocate(source.Width); - this.Colors.Span.Fill(color); + this.Colors.GetSpan().Fill(color); } /// @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes /// /// The color /// - internal override TPixel this[int x, int y] => this.Colors.Span[x]; + internal override TPixel this[int x, int y] => this.Colors.GetSpan()[x]; /// public override void Dispose() @@ -92,20 +92,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes if (this.Options.BlendPercentage == 1f) { - this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, scanline); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.GetSpan(), scanline); } else { using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; + Span amountSpan = amountBuffer.GetSpan(); for (int i = 0; i < scanline.Length; i++) { amountSpan[i] = scanline[i] * this.Options.BlendPercentage; } - this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs index 7b6e36d9d..c5691aa64 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors using (IBuffer amount = memoryManager.Allocate(width)) { - amount.Span.Fill(this.Opacity); + amount.GetSpan().Fill(this.Opacity); Parallel.For( minY, @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors { Span background = source.GetPixelRowSpan(y).Slice(minX, width); Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); - blender.Blend(memoryManager, background, background, foreground, amount.Span); + blender.Blend(memoryManager, background, background, foreground, amount.GetSpan()); }); } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs index 645ff0353..3cf2f7d63 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors sourceRectangle, this.options)) { - amount.Span.Fill(1f); + amount.GetSpan().Fill(1f); Parallel.For( minY, @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors int offsetY = y - startY; int offsetX = minX - startX; - applicator.Apply(amount.Span, offsetX, offsetY); + applicator.Apply(amount.GetSpan(), offsetX, offsetY); }); } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 95ac3fe29..0bb3abc50 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors } } - applicator.Apply(scanline.Span, minX, y); + applicator.Apply(scanline.GetSpan(), minX, y); } } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 26bd97b81..a3df87ff4 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp TPixel color = default; var rgba = new Rgba32(0, 0, 0, 255); - Span rowSpan = row.Span; + Span rowSpan = row.GetSpan(); for (int y = 0; y < height; y++) { @@ -434,7 +434,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp this.stream.Read(row); int newY = Invert(y, height, inverted); Span pixelSpan = pixels.GetRowSpan(newY); - PixelOperations.Instance.PackFromBgr24Bytes(row.Span, pixelSpan, width); + PixelOperations.Instance.PackFromBgr24Bytes(row.GetSpan(), pixelSpan, width); } } } @@ -459,7 +459,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp this.stream.Read(row); int newY = Invert(y, height, inverted); Span pixelSpan = pixels.GetRowSpan(newY); - PixelOperations.Instance.PackFromBgra32Bytes(row.Span, pixelSpan, width); + PixelOperations.Instance.PackFromBgra32Bytes(row.GetSpan(), pixelSpan, width); } } } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 2b0c90733..aefcda402 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp for (int y = pixels.Height - 1; y >= 0; y--) { Span pixelSpan = pixels.GetRowSpan(y); - PixelOperations.Instance.ToBgra32Bytes(pixelSpan, row.Span, pixelSpan.Length); + PixelOperations.Instance.ToBgra32Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length); stream.Write(row.Array, 0, row.Length()); } } @@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp for (int y = pixels.Height - 1; y >= 0; y--) { Span pixelSpan = pixels.GetRowSpan(y); - PixelOperations.Instance.ToBgr24Bytes(pixelSpan, row.Span, pixelSpan.Length); + PixelOperations.Instance.ToBgr24Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length); stream.Write(row.Array, 0, row.Length()); } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 4fbd4baf5..d37682a3d 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -327,9 +327,9 @@ namespace SixLabors.ImageSharp.Formats.Gif indices = this.configuration.MemoryManager.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, true); - this.ReadFrameIndices(imageDescriptor, indices.Span); - ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).Span); - this.ReadFrameColors(ref image, ref previousFrame, indices.Span, colorTable, imageDescriptor); + this.ReadFrameIndices(imageDescriptor, indices.GetSpan()); + ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).GetSpan()); + this.ReadFrameColors(ref image, ref previousFrame, indices.GetSpan(), colorTable, imageDescriptor); // Skip any remaining blocks this.Skip(0); diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 747867c80..6f134c4bd 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -320,7 +320,7 @@ namespace SixLabors.ImageSharp.Formats.Gif using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) { ref TPixel paletteRef = ref MemoryMarshal.GetReference(image.Palette.AsSpan()); - ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.Span)); + ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.GetSpan())); for (int i = 0; i < pixelCount; i++) { ref TPixel entry = ref Unsafe.Add(ref paletteRef, i); diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 9f9e070e2..f52a8b240 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -102,9 +102,9 @@ namespace SixLabors.ImageSharp.Formats.Gif int data = 0; int first = 0; - ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.Span); - ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.Span); - ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.Span); + ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.GetSpan()); + ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.GetSpan()); + ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.GetSpan()); ref byte pixelsRef = ref MemoryMarshal.GetReference(pixels); for (code = 0; code < clearCode; code++) diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index 1dc7e99e8..a23d2f4e2 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Gif [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ResetCodeTable() { - this.hashTable.Span.Fill(-1); + this.hashTable.GetSpan().Fill(-1); } /// @@ -293,8 +293,8 @@ namespace SixLabors.ImageSharp.Formats.Gif this.Output(this.clearCode, stream); - ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.Span); - ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.Span); + ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.GetSpan()); + ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.GetSpan()); while (this.position < this.pixelArray.Length) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index 38340b238..a8def1e19 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -155,11 +155,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder int y = yy - this.PixelRowCounter; var values = new JpegColorConverter.ComponentValues(buffers, y); - this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.Span); + this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan()); Span destRow = destination.GetPixelRowSpan(yy); - PixelOperations.Instance.PackFromVector4(this.rgbaBuffer.Span, destRow, destination.Width); + PixelOperations.Instance.PackFromVector4(this.rgbaBuffer.GetSpan(), destRow, destination.Width); } } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs index 875a86263..e8e0054f2 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs @@ -46,8 +46,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components using (IBuffer huffsize = memoryManager.Allocate(length)) using (IBuffer huffcode = memoryManager.Allocate(length)) { - ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.Span); - ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.Span); + ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan()); + ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan()); GenerateSizeTable(lengths, ref huffsizeRef); GenerateCodeTable(ref huffsizeRef, ref huffcodeRef, length); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index 752e72dd2..69994ee59 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -705,7 +705,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort using (IManagedByteBuffer huffmanData = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(256)) { - ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.Span); + ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.GetSpan()); for (int i = 2; i < remaining;) { byte huffmanTableSpec = (byte)this.InputStream.ReadByte(); @@ -713,7 +713,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort using (IManagedByteBuffer codeLengths = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(17)) { - ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.Span); + ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.GetSpan()); int codeLengthSum = 0; for (int j = 1; j < 17; j++) @@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort this.BuildHuffmanTable( huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables, huffmanTableSpec & 15, - codeLengths.Span, - huffmanValues.Span); + codeLengths.GetSpan(), + huffmanValues.GetSpan()); } } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index cc98b8450..15edf2ad3 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -531,7 +531,7 @@ namespace SixLabors.ImageSharp.Formats.Png } this.currentRowBytesRead = 0; - Span scanlineSpan = this.scanline.Span; + Span scanlineSpan = this.scanline.GetSpan(); var filterType = (FilterType)scanlineSpan[0]; switch (filterType) @@ -546,17 +546,17 @@ namespace SixLabors.ImageSharp.Formats.Png case FilterType.Up: - UpFilter.Decode(scanlineSpan, this.previousScanline.Span); + UpFilter.Decode(scanlineSpan, this.previousScanline.GetSpan()); break; case FilterType.Average: - AverageFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel); + AverageFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel); break; case FilterType.Paeth: - PaethFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel); + PaethFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel); break; default: @@ -639,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Png } Span rowSpan = image.GetPixelRowSpan(this.currentRow); - this.ProcessInterlacedDefilteredScanline(this.scanline.Span, rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); + this.ProcessInterlacedDefilteredScanline(this.scanline.GetSpan(), rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); this.SwapBuffers(); @@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Png using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { // TODO: Should we use pack from vector here instead? - this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); - PixelOperations.Instance.PackFromRgb24Bytes(compressed.Span, rowSpan, this.header.Width); + this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); + PixelOperations.Instance.PackFromRgb24Bytes(compressed.GetSpan(), rowSpan, this.header.Width); } } else @@ -747,9 +747,9 @@ namespace SixLabors.ImageSharp.Formats.Png using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { // TODO: Should we use pack from vector here instead? - this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); + this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); - Span rgb24Span = MemoryMarshal.Cast(compressed.Span); + Span rgb24Span = MemoryMarshal.Cast(compressed.GetSpan()); for (int x = 0; x < this.header.Width; x++) { ref Rgb24 rgb24 = ref rgb24Span[x]; @@ -788,8 +788,8 @@ namespace SixLabors.ImageSharp.Formats.Png using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { // TODO: Should we use pack from vector here instead? - this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); - PixelOperations.Instance.PackFromRgba32Bytes(compressed.Span, rowSpan, this.header.Width); + this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); + PixelOperations.Instance.PackFromRgba32Bytes(compressed.GetSpan(), rowSpan, this.header.Width); } } else @@ -986,7 +986,7 @@ namespace SixLabors.ImageSharp.Formats.Png int length = this.header.Width * 3; using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { - Span compressedSpan = compressed.Span; + Span compressedSpan = compressed.GetSpan(); // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length); @@ -1056,7 +1056,7 @@ namespace SixLabors.ImageSharp.Formats.Png int length = this.header.Width * 4; using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { - Span compressedSpan = compressed.Span; + Span compressedSpan = compressed.GetSpan(); // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length); @@ -1229,7 +1229,7 @@ namespace SixLabors.ImageSharp.Formats.Png { this.crc.Reset(); this.crc.Update(this.chunkTypeBuffer); - this.crc.Update(chunk.Data.Span); + this.crc.Update(chunk.Data.GetSpan()); if (this.crc.Value != chunk.Crc) { diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index f17c9009a..b9e09070e 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -283,11 +283,11 @@ namespace SixLabors.ImageSharp.Formats.Png { if (this.bytesPerPixel == 4) { - PixelOperations.Instance.ToRgba32Bytes(rowSpan, this.rawScanline.Span, this.width); + PixelOperations.Instance.ToRgba32Bytes(rowSpan, this.rawScanline.GetSpan(), this.width); } else { - PixelOperations.Instance.ToRgb24Bytes(rowSpan, this.rawScanline.Span, this.width); + PixelOperations.Instance.ToRgb24Bytes(rowSpan, this.rawScanline.GetSpan(), this.width); } } @@ -320,23 +320,23 @@ namespace SixLabors.ImageSharp.Formats.Png switch (this.pngFilterMethod) { case PngFilterMethod.None: - NoneFilter.Encode(this.rawScanline.Span, this.result.Span); + NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan()); return this.result; case PngFilterMethod.Sub: - SubFilter.Encode(this.rawScanline.Span, this.sub.Span, this.bytesPerPixel, out int _); + SubFilter.Encode(this.rawScanline.GetSpan(), this.sub.GetSpan(), this.bytesPerPixel, out int _); return this.sub; case PngFilterMethod.Up: - UpFilter.Encode(this.rawScanline.Span, this.previousScanline.Span, this.up.Span, out int _); + UpFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.up.GetSpan(), out int _); return this.up; case PngFilterMethod.Average: - AverageFilter.Encode(this.rawScanline.Span, this.previousScanline.Span, this.average.Span, this.bytesPerPixel, out int _); + AverageFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.average.GetSpan(), this.bytesPerPixel, out int _); return this.average; case PngFilterMethod.Paeth: - PaethFilter.Encode(this.rawScanline.Span, this.previousScanline.Span, this.paeth.Span, this.bytesPerPixel, out int _); + PaethFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.paeth.GetSpan(), this.bytesPerPixel, out int _); return this.paeth; default: @@ -354,21 +354,21 @@ namespace SixLabors.ImageSharp.Formats.Png // Palette images don't compress well with adaptive filtering. if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8) { - NoneFilter.Encode(this.rawScanline.Span, this.result.Span); + NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan()); return this.result; } - Span scanSpan = this.rawScanline.Span; - Span prevSpan = this.previousScanline.Span; + Span scanSpan = this.rawScanline.GetSpan(); + Span prevSpan = this.previousScanline.GetSpan(); // This order, while different to the enumerated order is more likely to produce a smaller sum // early on which shaves a couple of milliseconds off the processing time. - UpFilter.Encode(scanSpan, prevSpan, this.up.Span, out int currentSum); + UpFilter.Encode(scanSpan, prevSpan, this.up.GetSpan(), out int currentSum); int lowestSum = currentSum; IManagedByteBuffer actualResult = this.up; - PaethFilter.Encode(scanSpan, prevSpan, this.paeth.Span, this.bytesPerPixel, out currentSum); + PaethFilter.Encode(scanSpan, prevSpan, this.paeth.GetSpan(), this.bytesPerPixel, out currentSum); if (currentSum < lowestSum) { @@ -376,7 +376,7 @@ namespace SixLabors.ImageSharp.Formats.Png actualResult = this.paeth; } - SubFilter.Encode(scanSpan, this.sub.Span, this.bytesPerPixel, out currentSum); + SubFilter.Encode(scanSpan, this.sub.GetSpan(), this.bytesPerPixel, out currentSum); if (currentSum < lowestSum) { @@ -384,7 +384,7 @@ namespace SixLabors.ImageSharp.Formats.Png actualResult = this.sub; } - AverageFilter.Encode(scanSpan, prevSpan, this.average.Span, this.bytesPerPixel, out currentSum); + AverageFilter.Encode(scanSpan, prevSpan, this.average.GetSpan(), this.bytesPerPixel, out currentSum); if (currentSum < lowestSum) { @@ -463,8 +463,8 @@ namespace SixLabors.ImageSharp.Formats.Png using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) using (IManagedByteBuffer alphaTable = this.memoryManager.AllocateManagedByteBuffer(pixelCount)) { - Span colorTableSpan = colorTable.Span; - Span alphaTableSpan = alphaTable.Span; + Span colorTableSpan = colorTable.GetSpan(); + Span alphaTableSpan = alphaTable.GetSpan(); for (byte i = 0; i < pixelCount; i++) { diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index 6b44c893b..3f3dbb7e2 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp long startPosition = stream.Position; stream.Read(buffer.Array, 0, maxHeaderSize); stream.Position = startPosition; - return config.ImageFormatsManager.FormatDetectors.Select(x => x.DetectFormat(buffer.Span)).LastOrDefault(x => x != null); + return config.ImageFormatsManager.FormatDetectors.Select(x => x.DetectFormat(buffer.GetSpan())).LastOrDefault(x => x != null); } } diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 0caacd8a8..5886ca6fd 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -289,7 +289,7 @@ namespace SixLabors.ImageSharp { Span sourceRow = this.GetPixelRowSpan(y); Span targetRow = target.GetPixelRowSpan(y); - Span tempRowSpan = tempRowBuffer.Span; + Span tempRowSpan = tempRowBuffer.GetSpan(); PixelOperations.Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length); PixelOperations.Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length); diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs index 5ca81b5ec..ecf064339 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Memory protected byte[] Data { get; private set; } /// - public Span Span => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length); + public Span GetSpan() => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length); /// public void Dispose() diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index dd2f7ef86..757488755 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -25,8 +25,6 @@ namespace SixLabors.ImageSharp.Memory public int Length { get; } - public Span Span => this.Array.AsSpan(0, this.Length); - /// /// Returns a reference to specified element of the buffer. /// @@ -39,11 +37,14 @@ namespace SixLabors.ImageSharp.Memory { DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); - Span span = this.Span; + Span span = this.GetSpan(); return ref span[index]; } } + /// + public Span GetSpan() => this.Array.AsSpan(0, this.Length); + public void Dispose() { } diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index dc992368c..0c780426d 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Gets the span to the whole area. /// - public Span Span => this.Buffer.Span; + public Span Span => this.Buffer.GetSpan(); /// /// Gets the backing @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Memory { DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); - Span span = this.Buffer.Span; + Span span = this.Buffer.GetSpan(); return ref span[(this.Width * y) + x]; } } diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index dd3114c21..0f04f34f2 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Memory { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Length(this IBuffer buffer) - where T : struct => buffer.Span.Length; + where T : struct => buffer.GetSpan().Length; /// /// Gets a to an offseted position inside the buffer. @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Memory public static Span Slice(this IBuffer buffer, int start) where T : struct { - return buffer.Span.Slice(start); + return buffer.GetSpan().Slice(start); } /// @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Memory public static Span Slice(this IBuffer buffer, int start, int length) where T : struct { - return buffer.Span.Slice(start, length); + return buffer.GetSpan().Slice(start, length); } /// @@ -49,12 +49,12 @@ namespace SixLabors.ImageSharp.Memory public static void Clear(this IBuffer buffer) where T : struct { - buffer.Span.Clear(); + buffer.GetSpan().Clear(); } public static ref T DangerousGetPinnableReference(this IBuffer buffer) where T : struct => - ref MemoryMarshal.GetReference(buffer.Span); + ref MemoryMarshal.GetReference(buffer.GetSpan()); public static void Read(this Stream stream, IManagedByteBuffer buffer) { diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index db6bf5b38..9943134f5 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -16,6 +16,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Gets the span to the memory "promised" by this buffer /// - Span Span { get; } + /// The + Span GetSpan(); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs index b676f6a12..5b8772790 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs @@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors using (IBuffer amount = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture colorSpan & amountSpan in the lambda below! - Span colorSpan = colors.Span; - Span amountSpan = amount.Span; + Span colorSpan = colors.GetSpan(); + Span amountSpan = amount.GetSpan(); // TODO: Use Span.Fill? for (int i = 0; i < width; i++) @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width); // This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one - blender.Blend(source.MemoryManager, destination, colors.Span, destination, amount.Span); + blender.Blend(source.MemoryManager, destination, colors.GetSpan(), destination, amount.GetSpan()); }); } } diff --git a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs index ac5d3dc82..b5571ffd0 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors using (IBuffer rowColors = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! - Span rowColorsSpan = rowColors.Span; + Span rowColorsSpan = rowColors.GetSpan(); for (int i = 0; i < width; i++) { @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors { using (IBuffer amounts = source.MemoryManager.Allocate(width)) { - Span amountsSpan = amounts.Span; + Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; int offsetX = minX - startX; for (int i = 0; i < width; i++) @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(source.MemoryManager, destination, destination, rowColors.Span, amountsSpan); + this.blender.Blend(source.MemoryManager, destination, destination, rowColors.GetSpan(), amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs index ec286db62..06bf668d4 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors using (IBuffer rowColors = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! - Span rowColorsSpan = rowColors.Span; + Span rowColorsSpan = rowColors.GetSpan(); for (int i = 0; i < width; i++) { @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors { using (IBuffer amounts = source.MemoryManager.Allocate(width)) { - Span amountsSpan = amounts.Span; + Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; int offsetX = minX - startX; for (int i = 0; i < width; i++) @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(source.MemoryManager, destination, destination, rowColors.Span, amountsSpan); + this.blender.Blend(source.MemoryManager, destination, destination, rowColors.GetSpan(), amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs index bc7a2df71..7887b1b2e 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs @@ -177,14 +177,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { this.Mark(ref this.colorCube[k], (byte)k); - float weight = Volume(ref this.colorCube[k], this.vwt.Span); + float weight = Volume(ref this.colorCube[k], this.vwt.GetSpan()); if (MathF.Abs(weight) > Constants.Epsilon) { - float r = Volume(ref this.colorCube[k], this.vmr.Span); - float g = Volume(ref this.colorCube[k], this.vmg.Span); - float b = Volume(ref this.colorCube[k], this.vmb.Span); - float a = Volume(ref this.colorCube[k], this.vma.Span); + float r = Volume(ref this.colorCube[k], this.vmr.GetSpan()); + float g = Volume(ref this.colorCube[k], this.vmg.GetSpan()); + float b = Volume(ref this.colorCube[k], this.vmb.GetSpan()); + float a = Volume(ref this.colorCube[k], this.vma.GetSpan()); ref TPixel color = ref this.palette[k]; color.PackFromVector4(new Vector4(r, g, b, a) / weight / 255F); @@ -209,12 +209,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers int index = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1); - Span vwtSpan = this.vwt.Span; - Span vmrSpan = this.vmr.Span; - Span vmgSpan = this.vmg.Span; - Span vmbSpan = this.vmb.Span; - Span vmaSpan = this.vma.Span; - Span m2Span = this.m2.Span; + Span vwtSpan = this.vwt.GetSpan(); + Span vmrSpan = this.vmr.GetSpan(); + Span vmgSpan = this.vmg.GetSpan(); + Span vmbSpan = this.vmb.GetSpan(); + Span vmaSpan = this.vma.GetSpan(); + Span m2Span = this.m2.GetSpan(); vwtSpan[index]++; vmrSpan[index] += rgba.R; @@ -466,12 +466,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// private void Get3DMoments(MemoryManager memoryManager) { - Span vwtSpan = this.vwt.Span; - Span vmrSpan = this.vmr.Span; - Span vmgSpan = this.vmg.Span; - Span vmbSpan = this.vmb.Span; - Span vmaSpan = this.vma.Span; - Span m2Span = this.m2.Span; + Span vwtSpan = this.vwt.GetSpan(); + Span vmrSpan = this.vmr.GetSpan(); + Span vmgSpan = this.vmg.GetSpan(); + Span vmbSpan = this.vmb.GetSpan(); + Span vmaSpan = this.vma.GetSpan(); + Span m2Span = this.m2.GetSpan(); using (IBuffer volume = memoryManager.Allocate(IndexCount * IndexAlphaCount)) using (IBuffer volumeR = memoryManager.Allocate(IndexCount * IndexAlphaCount)) @@ -487,19 +487,19 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers using (IBuffer areaA = memoryManager.Allocate(IndexAlphaCount)) using (IBuffer area2 = memoryManager.Allocate(IndexAlphaCount)) { - Span volumeSpan = volume.Span; - Span volumeRSpan = volumeR.Span; - Span volumeGSpan = volumeG.Span; - Span volumeBSpan = volumeB.Span; - Span volumeASpan = volumeA.Span; - Span volume2Span = volume2.Span; - - Span areaSpan = area.Span; - Span areaRSpan = areaR.Span; - Span areaGSpan = areaG.Span; - Span areaBSpan = areaB.Span; - Span areaASpan = areaA.Span; - Span area2Span = area2.Span; + Span volumeSpan = volume.GetSpan(); + Span volumeRSpan = volumeR.GetSpan(); + Span volumeGSpan = volumeG.GetSpan(); + Span volumeBSpan = volumeB.GetSpan(); + Span volumeASpan = volumeA.GetSpan(); + Span volume2Span = volume2.GetSpan(); + + Span areaSpan = area.GetSpan(); + Span areaRSpan = areaR.GetSpan(); + Span areaGSpan = areaG.GetSpan(); + Span areaBSpan = areaB.GetSpan(); + Span areaASpan = areaA.GetSpan(); + Span area2Span = area2.GetSpan(); for (int r = 1; r < IndexCount; r++) { @@ -577,12 +577,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// The . private float Variance(ref Box cube) { - float dr = Volume(ref cube, this.vmr.Span); - float dg = Volume(ref cube, this.vmg.Span); - float db = Volume(ref cube, this.vmb.Span); - float da = Volume(ref cube, this.vma.Span); + float dr = Volume(ref cube, this.vmr.GetSpan()); + float dg = Volume(ref cube, this.vmg.GetSpan()); + float db = Volume(ref cube, this.vmb.GetSpan()); + float da = Volume(ref cube, this.vma.GetSpan()); - Span m2Span = this.m2.Span; + Span m2Span = this.m2.GetSpan(); float xx = m2Span[GetPaletteIndex(cube.R1, cube.G1, cube.B1, cube.A1)] @@ -603,7 +603,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers + m2Span[GetPaletteIndex(cube.R0, cube.G0, cube.B0, cube.A0)]; var vector = new Vector4(dr, dg, db, da); - return xx - (Vector4.Dot(vector, vector) / Volume(ref cube, this.vwt.Span)); + return xx - (Vector4.Dot(vector, vector) / Volume(ref cube, this.vwt.GetSpan())); } /// @@ -626,22 +626,22 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// The . private float Maximize(ref Box cube, int direction, int first, int last, out int cut, float wholeR, float wholeG, float wholeB, float wholeA, float wholeW) { - long baseR = Bottom(ref cube, direction, this.vmr.Span); - long baseG = Bottom(ref cube, direction, this.vmg.Span); - long baseB = Bottom(ref cube, direction, this.vmb.Span); - long baseA = Bottom(ref cube, direction, this.vma.Span); - long baseW = Bottom(ref cube, direction, this.vwt.Span); + long baseR = Bottom(ref cube, direction, this.vmr.GetSpan()); + long baseG = Bottom(ref cube, direction, this.vmg.GetSpan()); + long baseB = Bottom(ref cube, direction, this.vmb.GetSpan()); + long baseA = Bottom(ref cube, direction, this.vma.GetSpan()); + long baseW = Bottom(ref cube, direction, this.vwt.GetSpan()); float max = 0F; cut = -1; for (int i = first; i < last; i++) { - float halfR = baseR + Top(ref cube, direction, i, this.vmr.Span); - float halfG = baseG + Top(ref cube, direction, i, this.vmg.Span); - float halfB = baseB + Top(ref cube, direction, i, this.vmb.Span); - float halfA = baseA + Top(ref cube, direction, i, this.vma.Span); - float halfW = baseW + Top(ref cube, direction, i, this.vwt.Span); + float halfR = baseR + Top(ref cube, direction, i, this.vmr.GetSpan()); + float halfG = baseG + Top(ref cube, direction, i, this.vmg.GetSpan()); + float halfB = baseB + Top(ref cube, direction, i, this.vmb.GetSpan()); + float halfA = baseA + Top(ref cube, direction, i, this.vma.GetSpan()); + float halfW = baseW + Top(ref cube, direction, i, this.vwt.GetSpan()); if (MathF.Abs(halfW) < Constants.Epsilon) { @@ -685,11 +685,11 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// Returns a value indicating whether the box has been split. private bool Cut(ref Box set1, ref Box set2) { - float wholeR = Volume(ref set1, this.vmr.Span); - float wholeG = Volume(ref set1, this.vmg.Span); - float wholeB = Volume(ref set1, this.vmb.Span); - float wholeA = Volume(ref set1, this.vma.Span); - float wholeW = Volume(ref set1, this.vwt.Span); + float wholeR = Volume(ref set1, this.vmr.GetSpan()); + float wholeG = Volume(ref set1, this.vmg.GetSpan()); + float wholeB = Volume(ref set1, this.vmb.GetSpan()); + float wholeA = Volume(ref set1, this.vma.GetSpan()); + float wholeW = Volume(ref set1, this.vwt.GetSpan()); float maxr = this.Maximize(ref set1, 3, set1.R0 + 1, set1.R1, out int cutr, wholeR, wholeG, wholeB, wholeA, wholeW); float maxg = this.Maximize(ref set1, 2, set1.G0 + 1, set1.G1, out int cutg, wholeR, wholeG, wholeB, wholeA, wholeW); @@ -773,7 +773,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// A label. private void Mark(ref Box cube, byte label) { - Span tagSpan = this.tag.Span; + Span tagSpan = this.tag.GetSpan(); for (int r = cube.R0 + 1; r <= cube.R1; r++) { @@ -866,7 +866,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers int b = rgba.B >> (8 - IndexBits); int a = rgba.A >> (8 - IndexAlphaBits); - Span tagSpan = this.tag.Span; + Span tagSpan = this.tag.GetSpan(); return tagSpan[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)]; } diff --git a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs index 773b16e73..fc8d94362 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs @@ -308,7 +308,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors { ref Vector4 firstPassRow = ref MemoryMarshal.GetReference(firstPassPixels.GetRowSpan(y)); Span sourceRow = source.GetPixelRowSpan(y); - Span tempRowSpan = tempRowBuffer.Span; + Span tempRowSpan = tempRowBuffer.GetSpan(); PixelOperations.Instance.ToVector4(sourceRow, tempRowSpan, sourceRow.Length); diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs index a21105272..0eac88fd3 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref float GetStartReference() { - Span span = this.buffer.Span; + Span span = this.buffer.GetSpan(); return ref span[this.flatStartIndex]; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs index af754ba34..329fcbe67 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs @@ -37,8 +37,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - ref Vector4 s = ref MemoryMarshal.GetReference(this.source.Span); - ref TPixel d = ref MemoryMarshal.GetReference(this.destination.Span); + ref Vector4 s = ref MemoryMarshal.GetReference(this.source.GetSpan()); + ref TPixel d = ref MemoryMarshal.GetReference(this.destination.GetSpan()); for (int i = 0; i < this.Count; i++) { @@ -49,13 +49,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().PackFromVector4(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().PackFromVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.PackFromVector4(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.PackFromVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 64327d378..31583bfe2 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -35,8 +35,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - Span s = this.source.Span; - Span d = this.destination.Span; + Span s = this.source.GetSpan(); + Span d = this.destination.GetSpan(); for (int i = 0; i < this.Count; i++) { @@ -50,13 +50,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().PackFromRgba32Bytes(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().PackFromRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.PackFromRgba32Bytes(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.PackFromRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs index 811af9675..46a688b49 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg this.Output.WriteLine($"Component{i}: {diff}"); averageDifference += diff.average; totalDifference += diff.total; - tolerance += libJpegComponent.SpectralBlocks.Buffer.Span.Length; + tolerance += libJpegComponent.SpectralBlocks.Buffer.GetSpan().Length; } averageDifference /= componentCount; diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index bacdfb504..c3d59b039 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -132,13 +132,13 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer firstAlloc = this.MemoryManager.Allocate(42)) { - firstAlloc.Span.Fill(666); + firstAlloc.GetSpan().Fill(666); } using (IBuffer secondAlloc = this.MemoryManager.Allocate(42, clean)) { int expected = clean ? 0 : 666; - Assert.Equal(expected, secondAlloc.Span[0]); + Assert.Equal(expected, secondAlloc.GetSpan()[0]); } } @@ -148,7 +148,7 @@ namespace SixLabors.ImageSharp.Tests.Memory public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive) { IBuffer buffer = this.MemoryManager.Allocate(32); - ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.Span); + ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan()); if (!keepBufferAlive) { diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index d092df45a..896bde035 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (Buffer2D buffer = this.MemoryManager.Allocate2D(width, height)) { - Span span = buffer.Buffer.Span; + Span span = buffer.Buffer.GetSpan(); ref TestStructs.Foo actual = ref buffer[x, y]; diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index eff1f197a..68c6632b9 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer buffer = this.MemoryManager.Allocate(desiredLength)) { - Assert.Equal(desiredLength, buffer.Span.Length); + Assert.Equal(desiredLength, buffer.GetSpan().Length); } } @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer buffer = this.Allocate(desiredLength, true, testManagedByteBuffer)) { - Assert.True(buffer.Span.SequenceEqual(expected)); + Assert.True(buffer.GetSpan().SequenceEqual(expected)); } } } @@ -166,9 +166,9 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer buffer = this.Allocate(desiredLength, false, testManagedByteBuffer)) { - ref T a = ref MemoryMarshal.GetReference(buffer.Span); - ref T b = ref MemoryMarshal.GetReference(buffer.Span); - ref T c = ref MemoryMarshal.GetReference(buffer.Span); + ref T a = ref MemoryMarshal.GetReference(buffer.GetSpan()); + ref T b = ref MemoryMarshal.GetReference(buffer.GetSpan()); + ref T c = ref MemoryMarshal.GetReference(buffer.GetSpan()); Assert.True(Unsafe.AreSame(ref a, ref b)); Assert.True(Unsafe.AreSame(ref b, ref c)); @@ -199,14 +199,14 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int i = 0; i < buffer.Length(); i++) { - Span span = buffer.Span; + Span span = buffer.GetSpan(); expectedVals[i] = getExpectedValue(i); span[i] = expectedVals[i]; } for (int i = 0; i < buffer.Length(); i++) { - Span span = buffer.Span; + Span span = buffer.GetSpan(); Assert.Equal(expectedVals[i], span[i]); } } @@ -244,21 +244,21 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.ThrowsAny( () => { - Span span = buffer.Span; + Span span = buffer.GetSpan(); dummy = span[desiredLength]; }); Assert.ThrowsAny( () => { - Span span = buffer.Span; + Span span = buffer.GetSpan(); dummy = span[desiredLength + 1]; }); Assert.ThrowsAny( () => { - Span span = buffer.Span; + Span span = buffer.GetSpan(); dummy = span[desiredLength + 42]; }); } @@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.Tests.Memory ref byte span0 = ref buffer.DangerousGetPinnableReference(); Assert.True(Unsafe.AreSame(ref span0, ref array0)); - Assert.True(buffer.Array.Length >= buffer.Span.Length); + Assert.True(buffer.Array.Length >= buffer.GetSpan().Length); } } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index 4ae11301d..97e4615c0 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => ImageSharp.PixelFormats.Rgba32.PixelOperations.ToVector4SimdAligned(s, d.Span, 64) + (s, d) => ImageSharp.PixelFormats.Rgba32.PixelOperations.ToVector4SimdAligned(s, d.GetSpan(), 64) ); } @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats times, () => { - PixelOperations.Instance.ToVector4(source.Span, dest.Span, count); + PixelOperations.Instance.ToVector4(source.GetSpan(), dest.GetSpan(), count); }); } } @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromVector4(s, d.Span, count) + (s, d) => Operations.PackFromVector4(s, d.GetSpan(), count) ); } @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromScaledVector4(s, d.Span, count) + (s, d) => Operations.PackFromScaledVector4(s, d.GetSpan(), count) ); } @@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToVector4(s, d.Span, count) + (s, d) => Operations.ToVector4(s, d.GetSpan(), count) ); } @@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToScaledVector4(s, d.Span, count) + (s, d) => Operations.ToScaledVector4(s, d.GetSpan(), count) ); } @@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromRgb24Bytes(s, d.Span, count) + (s, d) => Operations.PackFromRgb24Bytes(s, d.GetSpan(), count) ); } @@ -242,7 +242,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToRgb24Bytes(s, d.Span, count) + (s, d) => Operations.ToRgb24Bytes(s, d.GetSpan(), count) ); } @@ -263,7 +263,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromRgba32Bytes(s, d.Span, count) + (s, d) => Operations.PackFromRgba32Bytes(s, d.GetSpan(), count) ); } @@ -288,7 +288,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToRgba32Bytes(s, d.Span, count) + (s, d) => Operations.ToRgba32Bytes(s, d.GetSpan(), count) ); } @@ -309,7 +309,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromBgr24Bytes(s, d.Span, count) + (s, d) => Operations.PackFromBgr24Bytes(s, d.GetSpan(), count) ); } @@ -333,7 +333,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToBgr24Bytes(s, d.Span, count) + (s, d) => Operations.ToBgr24Bytes(s, d.GetSpan(), count) ); } @@ -354,7 +354,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromBgra32Bytes(s, d.Span, count) + (s, d) => Operations.PackFromBgra32Bytes(s, d.GetSpan(), count) ); } @@ -379,7 +379,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToBgra32Bytes(s, d.Span, count) + (s, d) => Operations.ToBgra32Bytes(s, d.GetSpan(), count) ); } @@ -400,7 +400,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.PackFromArgb32Bytes(s, d.Span, count) + (s, d) => Operations.PackFromArgb32Bytes(s, d.GetSpan(), count) ); } @@ -425,7 +425,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, expected, - (s, d) => Operations.ToArgb32Bytes(s, d.Span, count) + (s, d) => Operations.ToArgb32Bytes(s, d.GetSpan(), count) ); } @@ -459,7 +459,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { Span expected = MemoryMarshal.Cast(this.ExpectedDestBuffer.AsSpan()); - Span actual = MemoryMarshal.Cast(this.ActualDestBuffer.Span); + Span actual = MemoryMarshal.Cast(this.ActualDestBuffer.GetSpan()); for (int i = 0; i < count; i++) { @@ -471,7 +471,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats else { Span expected = this.ExpectedDestBuffer.AsSpan(); - Span actual = this.ActualDestBuffer.Span; + Span actual = this.ActualDestBuffer.GetSpan(); for (int i = 0; i < count; i++) { Assert.Equal(expected[i], actual[i]); diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index d04d2343f..650b1a053 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs byte* sourcePtr = sourcePtrBase + data.Stride * y; Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); - PixelOperations.Instance.PackFromBgra32(workBuffer.Span, row, row.Length); + PixelOperations.Instance.PackFromBgra32(workBuffer.GetSpan(), row, row.Length); } } } @@ -87,9 +87,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs byte* sourcePtr = sourcePtrBase + data.Stride * y; Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); - PixelOperations.Instance.PackFromBgr24(workBuffer.Span, row, row.Length); + PixelOperations.Instance.PackFromBgr24(workBuffer.GetSpan(), row, row.Length); - // FromRgb24(workBuffer.Span, row); + // FromRgb24(workBuffer.GetSpan(), row); } } } @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs for (int y = 0; y < h; y++) { Span row = image.Frames.RootFrame.GetPixelRowSpan(y); - PixelOperations.Instance.ToBgra32(row, workBuffer.Span, row.Length); + PixelOperations.Instance.ToBgra32(row, workBuffer.GetSpan(), row.Length); byte* destPtr = destPtrBase + data.Stride * y; Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); From 977eab6f2b569f312b600c9fd95dc01440363abc Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 8 Jun 2018 01:22:04 +0200 Subject: [PATCH 02/17] System.Buffers.MemoryManager is adapted --- .../ArrayPoolMemoryManager.Buffer{T}.cs | 13 +++--- src/ImageSharp/Memory/BasicArrayBuffer.cs | 13 ++++-- src/ImageSharp/Memory/BufferExtensions.cs | 16 ++++++++ src/ImageSharp/Memory/IBuffer{T}.cs | 1 + src/ImageSharp/Memory/ManagedBufferBase.cs | 40 +++++++++++++++++++ .../Memory/BufferTestSuite.cs | 37 ++++++++++++++++- 6 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 src/ImageSharp/Memory/ManagedBufferBase.cs diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs index ecf064339..1f52e4bfd 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Memory /// /// The buffer implementation of /// - private class Buffer : IBuffer + private class Buffer : ManagedBufferBase, IBuffer where T : struct { /// @@ -45,12 +45,9 @@ namespace SixLabors.ImageSharp.Memory protected byte[] Data { get; private set; } /// - public Span GetSpan() => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length); - - /// - public void Dispose() + protected override void Dispose(bool disposing) { - if (this.Data == null || this.sourcePoolReference == null) + if (!disposing || this.Data == null || this.sourcePoolReference == null) { return; } @@ -63,6 +60,10 @@ namespace SixLabors.ImageSharp.Memory this.sourcePoolReference = null; this.Data = null; } + + public override Span GetSpan() => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length); + + protected override object GetPinnableObject() => this.Data; } /// diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index 757488755..2fc62b11e 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Memory @@ -6,7 +7,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Exposes an array through the interface. /// - internal class BasicArrayBuffer : IBuffer + internal class BasicArrayBuffer : ManagedBufferBase, IBuffer where T : struct { public BasicArrayBuffer(T[] array, int length) @@ -42,11 +43,15 @@ namespace SixLabors.ImageSharp.Memory } } - /// - public Span GetSpan() => this.Array.AsSpan(0, this.Length); + protected override void Dispose(bool disposing) + { + } + + public override Span GetSpan() => this.Array.AsSpan(0, this.Length); - public void Dispose() + protected override object GetPinnableObject() { + return this.Array; } } } \ No newline at end of file diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index 0f04f34f2..8da9157f4 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -10,6 +10,22 @@ namespace SixLabors.ImageSharp.Memory { internal static class BufferExtensions { + public static Memory GetMemory(this IBuffer buffer) + where T : struct + { + System.Buffers.MemoryManager bufferManager = buffer as System.Buffers.MemoryManager; + + if (bufferManager == null) + { + // TODO: We need a better way to integrate IBuffer with MemoryManager. The prior should probably entirely replace the latter! + throw new ArgumentException( + "BufferExtensions.GetMemory(buffer): buffer should be convertable to System.Buffers.MemoryManager!", + nameof(buffer)); + } + + return bufferManager.Memory; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Length(this IBuffer buffer) where T : struct => buffer.GetSpan().Length; diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index 9943134f5..ab139e175 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -8,6 +8,7 @@ namespace SixLabors.ImageSharp.Memory /// /// /// Represents a contigous memory buffer of value-type items "promising" a + /// A proper im /// /// The value type internal interface IBuffer : IDisposable diff --git a/src/ImageSharp/Memory/ManagedBufferBase.cs b/src/ImageSharp/Memory/ManagedBufferBase.cs new file mode 100644 index 000000000..1291bcbb1 --- /dev/null +++ b/src/ImageSharp/Memory/ManagedBufferBase.cs @@ -0,0 +1,40 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Buffers; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp.Memory +{ + /// + /// Provides a base class for implementations by implementing pinning logic for adaption. + /// + internal abstract class ManagedBufferBase : System.Buffers.MemoryManager + { + private GCHandle pinHandle; + + /// + /// Gets the object that should be pinned. + /// + protected abstract object GetPinnableObject(); + + public override unsafe MemoryHandle Pin(int elementIndex = 0) + { + if (!this.pinHandle.IsAllocated) + { + this.pinHandle = GCHandle.Alloc(this.GetPinnableObject(), GCHandleType.Pinned); + } + + void* ptr = (void*)this.pinHandle.AddrOfPinnedObject(); + return new MemoryHandle(ptr, this.pinHandle); + } + + public override void Unpin() + { + if (this.pinHandle.IsAllocated) + { + this.pinHandle.Free(); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index 68c6632b9..fe2b1b8bf 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -10,7 +10,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Memory { - + using System.Buffers; /// /// Inherit this class to test an implementation (provided by ). @@ -282,5 +282,40 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.True(buffer.Array.Length >= buffer.GetSpan().Length); } } + + [Fact] + public void GetMemory_ReturnsValidMemory() + { + using (IBuffer buffer = this.MemoryManager.Allocate(42)) + { + Span span0 = buffer.GetSpan(); + span0[10].A = 30; + Memory memory = buffer.GetMemory(); + + Assert.Equal(42, memory.Length); + Span span1 = memory.Span; + + Assert.Equal(42, span1.Length); + Assert.Equal(30, span1[10].A); + } + } + + [Fact] + public unsafe void GetMemory_ResultIsPinnable() + { + using (IBuffer buffer = this.MemoryManager.Allocate(42)) + { + Span span0 = buffer.GetSpan(); + span0[10] = 30; + + Memory memory = buffer.GetMemory(); + + using (MemoryHandle h = memory.Pin()) + { + int* ptr = (int*) h.Pointer; + Assert.Equal(30, ptr[10]); + } + } + } } } \ No newline at end of file From b32c7849f321fffc9dadac8d5a7c05207e90501c Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 9 Jun 2018 13:54:32 +0200 Subject: [PATCH 03/17] introduce .GetPixelMemory(), get rid of BufferExtensions.GetMemory() --- .../Advanced/AdvancedImageExtensions.cs | 12 ++++++++++++ src/ImageSharp/Memory/BufferExtensions.cs | 16 ---------------- src/ImageSharp/Memory/IBuffer{T}.cs | 7 ++++++- src/ImageSharp/PixelAccessor{TPixel}.cs | 2 -- tests/ImageSharp.Tests/Memory/BufferTestSuite.cs | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index cbd8db748..5060f5f37 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -23,6 +23,18 @@ namespace SixLabors.ImageSharp.Advanced where TPixel : struct, IPixel => GetConfiguration((IConfigurable)source); + /// + /// Gets the storing the whole pixel buffer in row major order. + /// + /// The Pixel format. + /// The source + /// The + public static Memory GetPixelMemory(this ImageFrame source) + where TPixel : struct, IPixel + { + return source.PixelBuffer.Buffer.Memory; + } + /// /// Returns a reference to the 0th element of the Pixel buffer, /// allowing direct manipulation of pixel data through unsafe operations. diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index 8da9157f4..0f04f34f2 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -10,22 +10,6 @@ namespace SixLabors.ImageSharp.Memory { internal static class BufferExtensions { - public static Memory GetMemory(this IBuffer buffer) - where T : struct - { - System.Buffers.MemoryManager bufferManager = buffer as System.Buffers.MemoryManager; - - if (bufferManager == null) - { - // TODO: We need a better way to integrate IBuffer with MemoryManager. The prior should probably entirely replace the latter! - throw new ArgumentException( - "BufferExtensions.GetMemory(buffer): buffer should be convertable to System.Buffers.MemoryManager!", - nameof(buffer)); - } - - return bufferManager.Memory; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Length(this IBuffer buffer) where T : struct => buffer.GetSpan().Length; diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index ab139e175..c23a46e6a 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -15,9 +15,14 @@ namespace SixLabors.ImageSharp.Memory where T : struct { /// - /// Gets the span to the memory "promised" by this buffer + /// Gets the span to the memory "promised" by this buffer. /// /// The Span GetSpan(); + + /// + /// Gets the ownerd by this buffer. + /// + Memory Memory { get; } } } \ No newline at end of file diff --git a/src/ImageSharp/PixelAccessor{TPixel}.cs b/src/ImageSharp/PixelAccessor{TPixel}.cs index 1e789f0a6..757983270 100644 --- a/src/ImageSharp/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/PixelAccessor{TPixel}.cs @@ -54,8 +54,6 @@ namespace SixLabors.ImageSharp /// public Span Span => this.PixelBuffer.Span; - private static PixelOperations Operations => PixelOperations.Instance; - /// /// Gets or sets the pixel at the specified position. /// diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index fe2b1b8bf..b6385a424 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -290,7 +290,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { Span span0 = buffer.GetSpan(); span0[10].A = 30; - Memory memory = buffer.GetMemory(); + Memory memory = buffer.Memory; Assert.Equal(42, memory.Length); Span span1 = memory.Span; @@ -308,7 +308,7 @@ namespace SixLabors.ImageSharp.Tests.Memory Span span0 = buffer.GetSpan(); span0[10] = 30; - Memory memory = buffer.GetMemory(); + Memory memory = buffer.Memory; using (MemoryHandle h = memory.Pin()) { From 5847c5f949e88bc6a44f6f615a04b3ed18f1b77e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 9 Jun 2018 14:23:11 +0200 Subject: [PATCH 04/17] normalize IBuffer2D API --- src/ImageSharp/Advanced/AdvancedImageExtensions.cs | 6 +++--- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 2 +- .../PdfJsPort/Components/PdfJsFrameComponent.cs | 2 +- .../Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs | 11 ++++++----- src/ImageSharp/ImageFrame{TPixel}.cs | 4 ++-- src/ImageSharp/Memory/Buffer2DExtensions.cs | 13 +++++++++++-- src/ImageSharp/Memory/Buffer2D{T}.cs | 5 ----- src/ImageSharp/Memory/BufferArea{T}.cs | 8 ++++---- src/ImageSharp/Memory/BufferExtensions.cs | 2 +- src/ImageSharp/Memory/IBuffer2D{T}.cs | 6 +++--- src/ImageSharp/Memory/IBuffer{T}.cs | 10 +++++----- src/ImageSharp/PixelAccessor{TPixel}.cs | 9 ++++----- .../Memory/ArrayPoolMemoryManagerTests.cs | 10 +++++----- tests/ImageSharp.Tests/Memory/Buffer2DTests.cs | 4 ++-- tests/ImageSharp.Tests/Memory/BufferAreaTests.cs | 2 +- tests/ImageSharp.Tests/Memory/BufferTestSuite.cs | 2 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 6 +++--- .../TestUtilities/TestImageExtensions.cs | 4 ++-- 18 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 5060f5f37..1f77b93f7 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Advanced /// The span retuned from Pixel source private static Span GetSpan(IPixelSource source) where TPixel : struct, IPixel - => source.PixelBuffer.Span; + => source.PixelBuffer.GetSpan(); /// /// Gets the span to the backing buffer at the given row. @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Advanced /// private static Span GetSpan(Buffer2D source, int row) where TPixel : struct, IPixel - => source.Span.Slice(row * source.Width, source.Width); + => source.GetSpan().Slice(row * source.Width, source.Width); /// /// Gets the configuration. @@ -161,6 +161,6 @@ namespace SixLabors.ImageSharp.Advanced /// A reference to the element. private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(IPixelSource source) where TPixel : struct, IPixel - => ref MemoryMarshal.GetReference(source.PixelBuffer.Span); + => ref MemoryMarshal.GetReference(source.PixelBuffer.GetSpan()); } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index a3df87ff4..43be0004e 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -215,7 +215,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp using (Buffer2D buffer = this.memoryManager.AllocateClean2D(width, height)) { - this.UncompressRle8(width, buffer.Span); + this.UncompressRle8(width, buffer.GetSpan()); for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index ccbb5c6c0..70ac760e6 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components public ref Block8x8 GetBlockReference(int column, int row) { int offset = ((this.WidthInBlocks + 1) * row) + column; - return ref Unsafe.Add(ref MemoryMarshal.GetReference(this.SpectralBlocks.Span), offset); + return ref Unsafe.Add(ref MemoryMarshal.GetReference(this.SpectralBlocks.GetSpan()), offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs index 49bc10539..0a780dfe2 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs @@ -2,13 +2,14 @@ // Licensed under the Apache License, Version 2.0. using System; + #if DEBUG using System.Diagnostics; #endif using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.Formats.Jpeg.Components; +using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { @@ -166,7 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components if (componentsLength == 1) { PdfJsFrameComponent component = components[this.compIndex]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span)); + ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; @@ -188,7 +189,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components for (int i = 0; i < componentsLength; i++) { PdfJsFrameComponent component = components[i]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span)); + ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; int h = component.HorizontalSamplingFactor; @@ -224,7 +225,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components if (componentsLength == 1) { PdfJsFrameComponent component = components[this.compIndex]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span)); + ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); ref PdfJsHuffmanTable huffmanTable = ref huffmanTables[isAC ? component.ACHuffmanTableId : component.DCHuffmanTableId]; for (int n = 0; n < this.mcuToRead; n++) @@ -267,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components for (int i = 0; i < componentsLength; i++) { PdfJsFrameComponent component = components[i]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span)); + ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); ref PdfJsHuffmanTable huffmanTable = ref huffmanTables[isAC ? component.ACHuffmanTableId : component.DCHuffmanTableId]; int h = component.HorizontalSamplingFactor; int v = component.VerticalSamplingFactor; diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 5886ca6fd..328252344 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp this.configuration = configuration; this.MemoryManager = configuration.MemoryManager; this.PixelBuffer = this.MemoryManager.Allocate2D(source.PixelBuffer.Width, source.PixelBuffer.Height); - source.PixelBuffer.Span.CopyTo(this.PixelBuffer.Span); + source.PixelBuffer.GetSpan().CopyTo(this.PixelBuffer.GetSpan()); this.MetaData = source.MetaData.Clone(); } @@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp throw new ArgumentException("ImageFrame.CopyTo(): target must be of the same size!", nameof(target)); } - this.GetPixelSpan().CopyTo(target.Span); + this.GetPixelSpan().CopyTo(target.GetSpan()); } /// diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index ac5ab09db..6c07a20d3 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -12,6 +12,15 @@ namespace SixLabors.ImageSharp.Memory /// internal static class Buffer2DExtensions { + /// + /// Gets a to the backing buffer of . + /// + internal static Span GetSpan(this IBuffer2D buffer) + where T : struct + { + return buffer.Buffer.GetSpan(); + } + /// /// Gets a to the row 'y' beginning from the pixel at 'x'. /// @@ -24,7 +33,7 @@ namespace SixLabors.ImageSharp.Memory public static Span GetRowSpan(this IBuffer2D buffer, int x, int y) where T : struct { - return buffer.Span.Slice((y * buffer.Width) + x, buffer.Width - x); + return buffer.GetSpan().Slice((y * buffer.Width) + x, buffer.Width - x); } /// @@ -38,7 +47,7 @@ namespace SixLabors.ImageSharp.Memory public static Span GetRowSpan(this IBuffer2D buffer, int y) where T : struct { - return buffer.Span.Slice(y * buffer.Width, buffer.Width); + return buffer.GetSpan().Slice(y * buffer.Width, buffer.Width); } /// diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index 0c780426d..7689ecdb2 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -34,11 +34,6 @@ namespace SixLabors.ImageSharp.Memory /// public int Height { get; private set; } - /// - /// Gets the span to the whole area. - /// - public Span Span => this.Buffer.GetSpan(); - /// /// Gets the backing /// diff --git a/src/ImageSharp/Memory/BufferArea{T}.cs b/src/ImageSharp/Memory/BufferArea{T}.cs index 990b494fc..315e57d1b 100644 --- a/src/ImageSharp/Memory/BufferArea{T}.cs +++ b/src/ImageSharp/Memory/BufferArea{T}.cs @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Memory /// The position inside a row /// The row index /// The reference to the value - public ref T this[int x, int y] => ref this.DestinationBuffer.Span[this.GetIndexOf(x, y)]; + public ref T this[int x, int y] => ref this.DestinationBuffer.GetSpan()[this.GetIndexOf(x, y)]; /// /// Gets a reference to the [0,0] element. @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Memory /// The reference to the [0,0] element [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T GetReferenceToOrigin() => - ref this.DestinationBuffer.Span[(this.Rectangle.Y * this.DestinationBuffer.Width) + this.Rectangle.X]; + ref this.DestinationBuffer.GetSpan()[(this.Rectangle.Y * this.DestinationBuffer.Width) + this.Rectangle.X]; /// /// Gets a span to row 'y' inside this area. @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Memory int xx = this.Rectangle.X; int width = this.Rectangle.Width; - return this.DestinationBuffer.Span.Slice(yy + xx, width); + return this.DestinationBuffer.GetSpan().Slice(yy + xx, width); } /// @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Memory // Optimization for when the size of the area is the same as the buffer size. if (this.IsFullBufferArea) { - this.DestinationBuffer.Span.Clear(); + this.DestinationBuffer.GetSpan().Clear(); return; } diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index 0f04f34f2..3e7ebcdc8 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Memory buffer.GetSpan().Clear(); } - public static ref T DangerousGetPinnableReference(this IBuffer buffer) + public static ref T GetReference(this IBuffer buffer) where T : struct => ref MemoryMarshal.GetReference(buffer.GetSpan()); diff --git a/src/ImageSharp/Memory/IBuffer2D{T}.cs b/src/ImageSharp/Memory/IBuffer2D{T}.cs index 2f60fd02a..0fc8867a6 100644 --- a/src/ImageSharp/Memory/IBuffer2D{T}.cs +++ b/src/ImageSharp/Memory/IBuffer2D{T}.cs @@ -6,7 +6,7 @@ using System; namespace SixLabors.ImageSharp.Memory { /// - /// An interface that represents a pinned buffer of value type objects + /// An interface that represents a contigous buffer of value type objects /// interpreted as a 2D region of x elements. /// /// The value type. @@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp.Memory int Height { get; } /// - /// Gets a to the backing buffer. + /// Gets the contigous buffer being wrapped. /// - Span Span { get; } + IBuffer Buffer { get; } } } \ No newline at end of file diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index c23a46e6a..838c785bf 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -15,14 +15,14 @@ namespace SixLabors.ImageSharp.Memory where T : struct { /// - /// Gets the span to the memory "promised" by this buffer. + /// Gets the ownerd by this buffer. /// - /// The - Span GetSpan(); + Memory Memory { get; } /// - /// Gets the ownerd by this buffer. + /// Gets the span to the memory "promised" by this buffer. /// - Memory Memory { get; } + /// The + Span GetSpan(); } } \ No newline at end of file diff --git a/src/ImageSharp/PixelAccessor{TPixel}.cs b/src/ImageSharp/PixelAccessor{TPixel}.cs index 757983270..bcc758e9e 100644 --- a/src/ImageSharp/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/PixelAccessor{TPixel}.cs @@ -51,8 +51,7 @@ namespace SixLabors.ImageSharp /// public int Height { get; private set; } - /// - public Span Span => this.PixelBuffer.Span; + public IBuffer Buffer => this.PixelBuffer.Buffer; /// /// Gets or sets the pixel at the specified position. @@ -66,14 +65,14 @@ namespace SixLabors.ImageSharp get { this.CheckCoordinates(x, y); - return this.Span[(y * this.Width) + x]; + return this.GetSpan()[(y * this.Width) + x]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.CheckCoordinates(x, y); - Span span = this.Span; + Span span = this.GetSpan(); span[(y * this.Width) + x] = value; } } @@ -110,7 +109,7 @@ namespace SixLabors.ImageSharp /// The target pixel buffer accessor. internal void CopyTo(PixelAccessor target) { - this.PixelBuffer.Span.CopyTo(target.PixelBuffer.Span); + this.PixelBuffer.GetSpan().CopyTo(target.PixelBuffer.GetSpan()); } /// diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index c3d59b039..b84a78a55 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -31,11 +31,11 @@ namespace SixLabors.ImageSharp.Tests.Memory where T : struct { IBuffer buffer = this.MemoryManager.Allocate(length); - ref T ptrToPrevPosition0 = ref buffer.DangerousGetPinnableReference(); + ref T ptrToPrevPosition0 = ref buffer.GetReference(); buffer.Dispose(); buffer = this.MemoryManager.Allocate(length); - bool sameBuffers = Unsafe.AreSame(ref ptrToPrevPosition0, ref buffer.DangerousGetPinnableReference()); + bool sameBuffers = Unsafe.AreSame(ref ptrToPrevPosition0, ref buffer.GetReference()); buffer.Dispose(); return sameBuffers; @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Tests.Memory buffer = this.MemoryManager.Allocate(32); - Assert.False(Unsafe.AreSame(ref ptrToPrev0, ref buffer.DangerousGetPinnableReference())); + Assert.False(Unsafe.AreSame(ref ptrToPrev0, ref buffer.GetReference())); } [Fact] @@ -182,12 +182,12 @@ namespace SixLabors.ImageSharp.Tests.Memory int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int); IBuffer small = this.MemoryManager.Allocate(arrayLengthThreshold - 1); - ref int ptr2Small = ref small.DangerousGetPinnableReference(); + ref int ptr2Small = ref small.GetReference(); small.Dispose(); IBuffer large = this.MemoryManager.Allocate(arrayLengthThreshold + 1); - Assert.False(Unsafe.AreSame(ref ptr2Small, ref large.DangerousGetPinnableReference())); + Assert.False(Unsafe.AreSame(ref ptr2Small, ref large.GetReference())); } [Fact] diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 896bde035..ca3837ad2 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests.Memory where T : struct { ref T actual = ref MemoryMarshal.GetReference(span); - ref T expected = ref Unsafe.Add(ref buffer.DangerousGetPinnableReference(), bufferOffset); + ref T expected = ref Unsafe.Add(ref buffer.GetReference(), bufferOffset); Assert.True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position"); } @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (Buffer2D buffer = this.MemoryManager.Allocate2D(42, 42, true)) { - Span span = buffer.Span; + Span span = buffer.GetSpan(); for (int j = 0; j < span.Length; j++) { Assert.Equal(0, span[j]); diff --git a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs index db7367d97..bae3b4b61 100644 --- a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs +++ b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Tests.Memory using (Buffer2D buffer = CreateTestBuffer(22, 13)) { buffer.GetArea().Clear(); - Span fullSpan = buffer.Span; + Span fullSpan = buffer.GetSpan(); Assert.True(fullSpan.SequenceEqual(new int[fullSpan.Length])); } } diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index b6385a424..b19b1b03b 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Tests.Memory using (IManagedByteBuffer buffer = this.MemoryManager.AllocateManagedByteBuffer(desiredLength)) { ref byte array0 = ref buffer.Array[0]; - ref byte span0 = ref buffer.DangerousGetPinnableReference(); + ref byte span0 = ref buffer.GetReference(); Assert.True(Unsafe.AreSame(ref span0, ref array0)); Assert.True(buffer.Array.Length >= buffer.GetSpan().Length); diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index 650b1a053..ad0d43dcc 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs using (IBuffer workBuffer = Configuration.Default.MemoryManager.Allocate(w)) { - fixed (Bgra32* destPtr = &workBuffer.DangerousGetPinnableReference()) + fixed (Bgra32* destPtr = &workBuffer.GetReference()) { for (int y = 0; y < h; y++) { @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs using (IBuffer workBuffer = Configuration.Default.MemoryManager.Allocate(w)) { - fixed (Bgr24* destPtr = &workBuffer.DangerousGetPinnableReference()) + fixed (Bgr24* destPtr = &workBuffer.GetReference()) { for (int y = 0; y < h; y++) { @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs using (IBuffer workBuffer = image.GetConfiguration().MemoryManager.Allocate(w)) { - fixed (Bgra32* sourcePtr = &workBuffer.DangerousGetPinnableReference()) + fixed (Bgra32* sourcePtr = &workBuffer.GetReference()) { for (int y = 0; y < h; y++) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index b8c0489c8..3c5d5a7ba 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests { using (Buffer2D temp = memoryManager.Allocate2D(img.Width, img.Height)) { - Span tempSpan = temp.Span; + Span tempSpan = temp.GetSpan(); foreach (ImageFrame frame in img.Frames) { Span pixelSpan = frame.GetPixelSpan(); @@ -665,7 +665,7 @@ namespace SixLabors.ImageSharp.Tests Span pixels = image.Frames.RootFrame.GetPixelSpan(); - Span bufferSpan = buffer.Span; + Span bufferSpan = buffer.GetSpan(); for (int i = 0; i < bufferSpan.Length; i++) { From 6c1aca985daac611f994d2d19a23a963610bc918 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 9 Jun 2018 16:01:20 +0200 Subject: [PATCH 05/17] GetPixelMemory() tests --- .../Advanced/AdvancedImageExtensions.cs | 12 +++++++++ .../ArrayPoolMemoryManager.Buffer{T}.cs | 3 ++- src/ImageSharp/Memory/BasicArrayBuffer.cs | 2 +- src/ImageSharp/Memory/IBuffer{T}.cs | 12 +++++---- .../Advanced/AdvancedImageExtensionsTests.cs | 26 +++++++++++++++++++ 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 1f77b93f7..3faa072dd 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -35,6 +35,18 @@ namespace SixLabors.ImageSharp.Advanced return source.PixelBuffer.Buffer.Memory; } + /// + /// Gets the storing the whole pixel buffer in row major order. + /// + /// The Pixel format. + /// The source + /// The + public static Memory GetPixelMemory(this Image source) + where TPixel : struct, IPixel + { + return source.Frames.RootFrame.GetPixelMemory(); + } + /// /// Returns a reference to the 0th element of the Pixel buffer, /// allowing direct manipulation of pixel data through unsafe operations. diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs index 1f52e4bfd..afa5fdbb4 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs @@ -13,7 +13,8 @@ namespace SixLabors.ImageSharp.Memory public partial class ArrayPoolMemoryManager { /// - /// The buffer implementation of + /// The buffer implementation of . + /// In this implementation is owned. /// private class Buffer : ManagedBufferBase, IBuffer where T : struct diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index 2fc62b11e..450399900 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Memory { /// - /// Exposes an array through the interface. + /// Wraps an array as an instance. In this implementation is owned. /// internal class BasicArrayBuffer : ManagedBufferBase, IBuffer where T : struct diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index 838c785bf..fdb70ad9c 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -5,22 +5,24 @@ using System; namespace SixLabors.ImageSharp.Memory { - /// /// - /// Represents a contigous memory buffer of value-type items "promising" a - /// A proper im + /// Represents a contigous memory buffer of value-type items. + /// Depending on it's implementation, an can (1) OWN or (2) CONSUME the instance it wraps. + /// For a deeper understanding of the owner/consumer model, read the following docs:
+ /// https://gist.github.com/GrabYourPitchforks/4c3e1935fd4d9fa2831dbfcab35dffc6 ///
/// The value type internal interface IBuffer : IDisposable where T : struct { /// - /// Gets the ownerd by this buffer. + /// Gets the ownerd/consumed by this buffer. /// Memory Memory { get; } /// - /// Gets the span to the memory "promised" by this buffer. + /// Gets the span to the memory "promised" by this buffer when it's OWNED (1). + /// Gets `this.Memory.Span` when the buffer CONSUMED (2). /// /// The Span GetSpan(); diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 302b90e30..c14866742 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -8,8 +9,33 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Advanced { + + public class AdvancedImageExtensionsTests { + public class GetPixelMemory + { + [Theory] + [WithSolidFilledImages(1, 1, "Red", PixelTypes.Rgba32)] + [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] + public void WhenMemoryIsOwned(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + Memory memory = image.GetPixelMemory(); + Assert.Equal(image.Width * image.Height, memory.Length); + + var targetBuffer = new TPixel[image.Width * image.Height]; + memory.Span.CopyTo(targetBuffer); + + image.ComparePixelBufferTo(targetBuffer); + } + } + } + + + [Theory] [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] public unsafe void DangerousGetPinnableReference_CopyToBuffer(TestImageProvider provider) From 7fd6b2710048a477268e5e26b26a921d19bcd247 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 9 Jun 2018 23:49:24 +0200 Subject: [PATCH 06/17] GetPixelRowMemory(), GetPixelRowSpan() --- .../Advanced/AdvancedImageExtensions.cs | 94 ++++++++++++------- src/ImageSharp/Memory/Buffer2DExtensions.cs | 14 +++ .../Advanced/AdvancedImageExtensionsTests.cs | 69 ++++++++++++-- 3 files changed, 139 insertions(+), 38 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 3faa072dd..1d7f33a9a 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -24,7 +24,8 @@ namespace SixLabors.ImageSharp.Advanced => GetConfiguration((IConfigurable)source); /// - /// Gets the storing the whole pixel buffer in row major order. + /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format + /// stored in row major order. /// /// The Pixel format. /// The source @@ -36,7 +37,8 @@ namespace SixLabors.ImageSharp.Advanced } /// - /// Gets the storing the whole pixel buffer in row major order. + /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format + /// stored in row major order. /// /// The Pixel format. /// The source @@ -48,70 +50,98 @@ namespace SixLabors.ImageSharp.Advanced } /// - /// Returns a reference to the 0th element of the Pixel buffer, - /// allowing direct manipulation of pixel data through unsafe operations. - /// The pixel buffer is a contiguous memory area containing Width*Height TPixel elements laid out in row-major order. + /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format + /// stored in row major order. /// - /// The Pixel format. - /// The source image frame - /// A pinnable reference the first root of the pixel buffer. - public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this ImageFrame source) + /// The type of the pixel. + /// The source. + /// The + public static Span GetPixelSpan(this ImageFrame source) where TPixel : struct, IPixel - => ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource)source); + => source.GetPixelMemory().Span; /// - /// Returns a reference to the 0th element of the Pixel buffer, - /// allowing direct manipulation of pixel data through unsafe operations. - /// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order. + /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format + /// stored in row major order. /// - /// The Pixel format. - /// The source image - /// A pinnable reference the first root of the pixel buffer. - public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this Image source) + /// The type of the pixel. + /// The source. + /// The + public static Span GetPixelSpan(this Image source) where TPixel : struct, IPixel - => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); + => source.Frames.RootFrame.GetPixelSpan(); /// - /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format. + /// Gets the representation of the pixels as a of contiguous memory + /// at row beginning from the the first pixel on that row. /// /// The type of the pixel. /// The source. + /// The row. /// The - internal static Span GetPixelSpan(this ImageFrame source) + public static Memory GetPixelRowMemory(this ImageFrame source, int rowIndex) where TPixel : struct, IPixel - => GetSpan(source); + => source.PixelBuffer.GetRowMemory(rowIndex); /// - /// Gets the representation of the pixels as an area of contiguous memory at row 'y' beginning from the the first pixel on that row. + /// Gets the representation of the pixels as of of contiguous memory + /// at row beginning from the the first pixel on that row. /// /// The type of the pixel. /// The source. - /// The row. + /// The row. /// The - internal static Span GetPixelRowSpan(this ImageFrame source, int row) + public static Memory GetPixelRowMemory(this Image source, int rowIndex) where TPixel : struct, IPixel - => GetSpan(source, row); + => source.Frames.RootFrame.GetPixelRowMemory(rowIndex); /// - /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format. + /// Gets the representation of the pixels as a of contiguous memory + /// at row beginning from the the first pixel on that row. /// /// The type of the pixel. /// The source. + /// The row. /// The - internal static Span GetPixelSpan(this Image source) + public static Span GetPixelRowSpan(this ImageFrame source, int rowIndex) where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelSpan(); + => source.PixelBuffer.GetRowSpan(rowIndex); /// - /// Gets the representation of the pixels as an area of contiguous memory at row 'y' beginning from the the first pixel on that row. + /// Gets the representation of the pixels as of of contiguous memory + /// at row beginning from the the first pixel on that row. /// /// The type of the pixel. /// The source. - /// The row. + /// The row. /// The - internal static Span GetPixelRowSpan(this Image source, int row) + public static Span GetPixelRowSpan(this Image source, int rowIndex) + where TPixel : struct, IPixel + => source.Frames.RootFrame.GetPixelRowSpan(rowIndex); + + /// + /// Returns a reference to the 0th element of the Pixel buffer, + /// allowing direct manipulation of pixel data through unsafe operations. + /// The pixel buffer is a contiguous memory area containing Width*Height TPixel elements laid out in row-major order. + /// + /// The Pixel format. + /// The source image frame + /// A pinnable reference the first root of the pixel buffer. + public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this ImageFrame source) + where TPixel : struct, IPixel + => ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource)source); + + /// + /// Returns a reference to the 0th element of the Pixel buffer, + /// allowing direct manipulation of pixel data through unsafe operations. + /// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order. + /// + /// The Pixel format. + /// The source image + /// A pinnable reference the first root of the pixel buffer. + public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this Image source) where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelRowSpan(row); + => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); /// /// Gets the assigned to 'source'. diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index 6c07a20d3..c236f250c 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -50,6 +50,20 @@ namespace SixLabors.ImageSharp.Memory return buffer.GetSpan().Slice(y * buffer.Width, buffer.Width); } + /// + /// Gets a to the row 'y' beginning from the pixel at the first pixel on that row. + /// + /// The buffer + /// The y (row) coordinate + /// The element type + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Memory GetRowMemory(this IBuffer2D buffer, int y) + where T : struct + { + return buffer.Buffer.Memory.Slice(y * buffer.Width, buffer.Width); + } + /// /// Returns the size of the buffer. /// diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index c14866742..2825ddd77 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -21,20 +21,77 @@ namespace SixLabors.ImageSharp.Tests.Advanced public void WhenMemoryIsOwned(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image0 = provider.GetImage()) { - Memory memory = image.GetPixelMemory(); - Assert.Equal(image.Width * image.Height, memory.Length); + var targetBuffer = new TPixel[image0.Width * image0.Height]; - var targetBuffer = new TPixel[image.Width * image.Height]; + // Act: + Memory memory = image0.GetPixelMemory(); + + // Assert: + Assert.Equal(image0.Width * image0.Height, memory.Length); memory.Span.CopyTo(targetBuffer); - image.ComparePixelBufferTo(targetBuffer); + using (Image image1 = provider.GetImage()) + { + // We are using a copy of the original image for assertion + image1.ComparePixelBufferTo(targetBuffer); + } + } + } + } + + [Theory] + [WithSolidFilledImages(1, 1, "Red", PixelTypes.Rgba32)] + [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] + public void GetPixelRowMemory(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var targetBuffer = new TPixel[image.Width * image.Height]; + + // Act: + for (int y = 0; y < image.Height; y++) + { + Memory rowMemory = image.GetPixelRowMemory(y); + rowMemory.Span.CopyTo(targetBuffer.AsSpan(image.Width * y)); + } + + // Assert: + using (Image image1 = provider.GetImage()) + { + // We are using a copy of the original image for assertion + image1.ComparePixelBufferTo(targetBuffer); } } } - + [Theory] + [WithSolidFilledImages(1, 1, "Red", PixelTypes.Rgba32)] + [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] + public void GetPixelRowSpan(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var targetBuffer = new TPixel[image.Width * image.Height]; + + // Act: + for (int y = 0; y < image.Height; y++) + { + Span rowMemory = image.GetPixelRowSpan(y); + rowMemory.CopyTo(targetBuffer.AsSpan(image.Width * y)); + } + + // Assert: + using (Image image1 = provider.GetImage()) + { + // We are using a copy of the original image for assertion + image1.ComparePixelBufferTo(targetBuffer); + } + } + } [Theory] [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] From 85d0295f44991338435047e1f099e08ade52e684 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 00:10:40 +0200 Subject: [PATCH 07/17] refactor SixLabors.ImageSharp.Primitives.Region --- src/ImageSharp.Drawing/Primitives/Region.cs | 7 +-- .../Primitives/ShapeRegion.cs | 21 +++++---- .../Drawing/Processors/FillRegionProcessor.cs | 2 +- .../Drawing/FillRegionProcessorTests.cs | 46 ++++++++++++++----- .../Drawing/Paths/ShapeRegionTests.cs | 4 +- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/ImageSharp.Drawing/Primitives/Region.cs b/src/ImageSharp.Drawing/Primitives/Region.cs index c85e373fb..27f039f12 100644 --- a/src/ImageSharp.Drawing/Primitives/Region.cs +++ b/src/ImageSharp.Drawing/Primitives/Region.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Primitives @@ -19,7 +20,7 @@ namespace SixLabors.ImageSharp.Primitives /// Gets the bounding box that entirely surrounds this region. /// /// - /// This should always contains all possible points returned from . + /// This should always contains all possible points returned from . /// public abstract Rectangle Bounds { get; } @@ -28,8 +29,8 @@ namespace SixLabors.ImageSharp.Primitives ///
/// The position along the y axis to find intersections. /// The buffer. - /// The point in the buffer to start setting offset. + /// A instance in the context of the caller. /// The number of intersections found. - public abstract int Scan(float y, float[] buffer, int offset); + public abstract int Scan(float y, Span buffer, Configuration configuration); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index cfd1945d0..4c446189e 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; using SixLabors.Shapes; @@ -39,21 +40,23 @@ namespace SixLabors.ImageSharp.Primitives public override Rectangle Bounds { get; } /// - public override int Scan(float y, float[] buffer, int offset) + public override int Scan(float y, Span buffer, Configuration configuration) { var start = new PointF(this.Bounds.Left - 1, y); var end = new PointF(this.Bounds.Right + 1, y); - // TODO: This is a temporary workaround because of the lack of Span API-s on IPath. We should use MemoryManager.Allocate() here! - var innerBuffer = new PointF[buffer.Length]; - int count = this.Shape.FindIntersections(start, end, innerBuffer, 0); - - for (int i = 0; i < count; i++) + using (IBuffer tempBuffer = configuration.MemoryManager.Allocate(buffer.Length)) { - buffer[i + offset] = innerBuffer[i].X; - } + Span innerBuffer = tempBuffer.GetSpan(); + int count = this.Shape.FindIntersections(start, end, innerBuffer); - return count; + for (int i = 0; i < count; i++) + { + buffer[i] = innerBuffer[i].X; + } + + return count; + } } } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 0bb3abc50..571ca5d3f 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors float yPlusOne = y + 1; for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction) { - int pointsFound = region.Scan(subPixel + offset, buffer.Array, 0); + int pointsFound = region.Scan(subPixel + offset, buffer.GetSpan(), configuration); if (pointsFound == 0) { // nothing on this line skip diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 8c619c817..017fee856 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -4,7 +4,8 @@ using System.Numerics; using Moq; - +using System; +using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; @@ -13,13 +14,15 @@ using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Primitives; - using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + + public class FillRegionProcessorTests { + [Theory] [InlineData(true, 1, 4)] [InlineData(true, 2, 4)] @@ -29,21 +32,20 @@ namespace SixLabors.ImageSharp.Tests.Drawing [InlineData(false, 16, 4)] // we always do 4 sub=pixels when antialising is off. public void MinimumAntialiasSubpixelDepth(bool antialias, int antialiasSubpixelDepth, int expectedAntialiasSubpixelDepth) { - var bounds = new SixLabors.Primitives.Rectangle(0, 0, 1, 1); + var bounds = new Rectangle(0, 0, 1, 1); var brush = new Mock>(); - var region = new Mock(); - region.Setup(x => x.Bounds).Returns(bounds); + var region = new MockRegion2(bounds); var options = new GraphicsOptions(antialias) { AntialiasSubpixelDepth = 1 }; - var processor = new FillRegionProcessor(brush.Object, region.Object, options); + var processor = new FillRegionProcessor(brush.Object, region, options); var img = new Image(1, 1); processor.Apply(img, bounds); - region.Verify(x => x.Scan(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(4)); + Assert.Equal(4, region.ScanInvocationCounter); } [Fact] @@ -52,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing var bounds = new Rectangle(-100, -10, 10, 10); var brush = new Mock>(); var options = new GraphicsOptions(true); - var processor = new FillRegionProcessor(brush.Object, new MockRegion(), options); + var processor = new FillRegionProcessor(brush.Object, new MockRegion1(), options); var img = new Image(10, 10); processor.Apply(img, bounds); } @@ -71,13 +73,11 @@ namespace SixLabors.ImageSharp.Tests.Drawing } // Mocking the region throws an error in netcore2.0 - private class MockRegion : Region + private class MockRegion1 : Region { public override Rectangle Bounds => new Rectangle(-100, -10, 10, 10); - public override int MaxIntersections => 10; - - public override int Scan(float y, float[] buffer, int offset) + public override int Scan(float y, Span buffer, Configuration configuration) { if (y < 5) { @@ -87,6 +87,28 @@ namespace SixLabors.ImageSharp.Tests.Drawing } return 0; } + + public override int MaxIntersections => 10; + } + + private class MockRegion2 : Region + { + public MockRegion2(Rectangle bounds) + { + this.Bounds = bounds; + } + + public override int MaxIntersections => 100; + + public override Rectangle Bounds { get; } + + public int ScanInvocationCounter { get; private set; } + + public override int Scan(float y, Span buffer, Configuration configuration) + { + this.ScanInvocationCounter++; + return 0; + } } } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs index 2a9ab3412..08eef5597 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Assert.True(e.X > this.bounds.Right); }).Returns(0); - int i = region.Scan(yToScan, new float[0], 0); + int i = region.Scan(yToScan, new float[0], Configuration.Default); this.pathMock.Verify( x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Assert.True(e.X > this.bounds.Right); }).Returns(0); - int i = region.Scan(yToScan, new float[0], 0); + int i = region.Scan(yToScan, new float[0], Configuration.Default); this.pathMock.Verify( x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), From 66678cc5ae3810321cebbeb5e8a34e42ad6958c7 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 01:12:31 +0200 Subject: [PATCH 08/17] fix ShapeRegionTests --- .../Drawing/Paths/ShapeRegionTests.cs | 121 ++++++++---------- 1 file changed, 52 insertions(+), 69 deletions(-) diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs index 08eef5597..40c5f950d 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -2,39 +2,64 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Primitives; +using System; +using System.Collections.Generic; +using System.Numerics; +using Moq; +using SixLabors.Primitives; +using SixLabors.Shapes; +using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Paths { - using System; - - using Moq; - using SixLabors.Primitives; - using SixLabors.Shapes; - - using Xunit; - public class ShapeRegionTests { - private readonly Mock pathMock; + public abstract class MockPath : IPath + { + public abstract RectangleF Bounds { get; } + public IPath AsClosedPath() => this; + + public abstract SegmentInfo PointAlongPath(float distanceAlongPath); + public abstract PointInfo Distance(PointF point); + public abstract IEnumerable Flatten(); + public abstract bool Contains(PointF point); + public abstract IPath Transform(Matrix3x2 matrix); + public abstract PathTypes PathType { get; } + public abstract int MaxIntersections { get; } + public abstract float Length { get; } + + public int FindIntersections(PointF start, PointF end, PointF[] buffer, int offset) + { + return this.FindIntersections(start, end, buffer, 0); + } + + public int FindIntersections(PointF s, PointF e, Span buffer) + { + Assert.Equal(this.TestYToScan, s.Y); + Assert.Equal(this.TestYToScan, e.Y); + Assert.True(s.X < this.Bounds.Left); + Assert.True(e.X > this.Bounds.Right); + + this.TestFindIntersectionsInvocationCounter++; + + return this.TestFindIntersectionsResult; + } + + public int TestFindIntersectionsInvocationCounter { get; private set; } + public virtual int TestYToScan => 10; + public virtual int TestFindIntersectionsResult => 3; + } + + private readonly Mock pathMock; private readonly RectangleF bounds; public ShapeRegionTests() { - this.pathMock = new Mock(); + this.pathMock = new Mock() { CallBase = true }; this.bounds = new RectangleF(10.5f, 10, 10, 10); this.pathMock.Setup(x => x.Bounds).Returns(this.bounds); - // wire up the 2 mocks to reference eachother - this.pathMock.Setup(x => x.AsClosedPath()).Returns(() => this.pathMock.Object); - } - - [Fact] - public void ShapeRegionWithPathCallsAsShape() - { - new ShapeRegion(this.pathMock.Object); - - this.pathMock.Verify(x => x.AsClosedPath()); } [Fact] @@ -68,59 +93,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void ShapeRegionFromPathScanYProxyToShape() { - int yToScan = 10; - var region = new ShapeRegion(this.pathMock.Object); + MockPath path = this.pathMock.Object; + int yToScan = path.TestYToScan; + var region = new ShapeRegion(path); - this.pathMock - .Setup( - x => x.FindIntersections( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny())).Callback( - (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], Configuration.Default); - - this.pathMock.Verify( - x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), - Times.Once); - } + int i = region.Scan(yToScan, new float[path.TestFindIntersectionsResult], Configuration.Default); - [Fact] - public void ShapeRegionFromShapeScanYProxyToShape() - { - int yToScan = 10; - var region = new ShapeRegion(this.pathMock.Object); - - this.pathMock - .Setup( - x => x.FindIntersections( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny())).Callback( - (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], Configuration.Default); - - this.pathMock.Verify( - x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), - Times.Once); + Assert.Equal(path.TestFindIntersectionsResult, i); + Assert.Equal(1, path.TestFindIntersectionsInvocationCounter); } + [Fact] public void ShapeRegionFromShapeConvertsBoundsProxyToShape() { From 259f9736f3e1850f51a2ca2f3af8cb89d241bbc0 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 01:47:34 +0200 Subject: [PATCH 09/17] refactor FillRegionProcessor, drop MemoryManager.AllocateFake --- .../Drawing/Processors/FillRegionProcessor.cs | 63 +++++++++++-------- src/ImageSharp/Memory/MemoryManager.cs | 10 --- .../Drawing/FillSolidBrushTests.cs | 18 +++++- .../TestUtilities/TestUtils.cs | 2 - tests/Images/External | 2 +- 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 571ca5d3f..4072f88a8 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -96,36 +96,35 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors using (BrushApplicator applicator = this.Brush.CreateApplicator(source, rect, this.Options)) { int scanlineWidth = maxX - minX; - using (BasicArrayBuffer buffer = source.MemoryManager.AllocateFake(maxIntersections)) - using (BasicArrayBuffer scanline = source.MemoryManager.AllocateFake(scanlineWidth)) + using (IBuffer bBuffer = source.MemoryManager.Allocate(maxIntersections)) + using (IBuffer bScanline = source.MemoryManager.Allocate(scanlineWidth)) { bool scanlineDirty = true; float subpixelFraction = 1f / subpixelCount; float subpixelFractionPoint = subpixelFraction / subpixelCount; + + Span buffer = bBuffer.GetSpan(); + Span scanline = bScanline.GetSpan(); + for (int y = minY; y < maxY; y++) { if (scanlineDirty) { - // clear the buffer - for (int x = 0; x < scanlineWidth; x++) - { - scanline[x] = 0; - } - + scanline.Clear(); scanlineDirty = false; } float yPlusOne = y + 1; for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction) { - int pointsFound = region.Scan(subPixel + offset, buffer.GetSpan(), configuration); + int pointsFound = region.Scan(subPixel + offset, buffer, configuration); if (pointsFound == 0) { // nothing on this line skip continue; } - QuickSort(new Span(buffer.Array, 0, pointsFound)); + QuickSort(buffer.Slice(0, pointsFound)); for (int point = 0; point < pointsFound; point += 2) { @@ -181,7 +180,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors } } - applicator.Apply(scanline.GetSpan(), minX, y); + applicator.Apply(scanline, minX, y); } } } @@ -189,31 +188,45 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void Swap(Span data, int left, int right) + private static void Swap(ref float left, ref float right) { - float tmp = data[left]; - data[left] = data[right]; - data[right] = tmp; + float tmp = left; + left = right; + right = tmp; } private static void QuickSort(Span data) { - QuickSort(data, 0, data.Length - 1); + if (data.Length < 2) + { + return; + } + else if (data.Length == 2) + { + if (data[0] > data[1]) + { + Swap(ref data[0], ref data[1]); + } + + return; + } + + QuickSort(ref data[0], 0, data.Length - 1); } - private static void QuickSort(Span data, int lo, int hi) + private static void QuickSort(ref float data0, int lo, int hi) { if (lo < hi) { - int p = Partition(data, lo, hi); - QuickSort(data, lo, p); - QuickSort(data, p + 1, hi); + int p = Partition(ref data0, lo, hi); + QuickSort(ref data0, lo, p); + QuickSort(ref data0, p + 1, hi); } } - private static int Partition(Span data, int lo, int hi) + private static int Partition(ref float data0, int lo, int hi) { - float pivot = data[lo]; + float pivot = Unsafe.Add(ref data0, lo); int i = lo - 1; int j = hi + 1; while (true) @@ -222,20 +235,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors { i = i + 1; } - while (data[i] < pivot && i < hi); + while (Unsafe.Add(ref data0, i) < pivot && i < hi); do { j = j - 1; } - while (data[j] > pivot && j > lo); + while (Unsafe.Add(ref data0, j) > pivot && j > lo); if (i >= j) { return j; } - Swap(data, i, j); + Swap(ref Unsafe.Add(ref data0, i), ref Unsafe.Add(ref data0, j)); } } } diff --git a/src/ImageSharp/Memory/MemoryManager.cs b/src/ImageSharp/Memory/MemoryManager.cs index 52bdc897f..32b1c2001 100644 --- a/src/ImageSharp/Memory/MemoryManager.cs +++ b/src/ImageSharp/Memory/MemoryManager.cs @@ -27,16 +27,6 @@ namespace SixLabors.ImageSharp.Memory /// The internal abstract IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear); - /// - /// Temporal workaround. A method providing a "Buffer" based on a generic array without the 'Unsafe.As()' hackery. - /// Should be replaced with 'Allocate()' as soon as SixLabors.Shapes has Span-based API-s! - /// - internal BasicArrayBuffer AllocateFake(int length, bool dummy = false) - where T : struct - { - return new BasicArrayBuffer(new T[length]); - } - /// /// Releases all retained resources not being in use. /// Eg: by resetting array pools and letting GC to free the arrays. diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 83f4fbde6..58fd4c767 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -12,7 +12,10 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { - + using System; + + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + using SixLabors.Primitives; [GroupOutput("Drawing")] public class FillSolidBrushTests @@ -67,6 +70,19 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } + [Theory] + [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 5, 7, 3, 8)] + [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 8, 5, 6, 4)] + public void FillRegion(TestImageProvider provider, int x0, int y0, int w, int h) + where TPixel : struct, IPixel + { + FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; + var region = new RectangleF(x0, y0, w, h); + TPixel color = TestUtils.GetPixelOfNamedColor("Blue"); + + provider.RunValidatingProcessorTest(c => c.Fill(color, region), testDetails, ImageComparer.Exact); + } + public static readonly TheoryData BlendData = new TheoryData() { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index f71793ff2..43ae8423e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -113,8 +113,6 @@ namespace SixLabors.ImageSharp.Tests /// public static PixelTypes GetPixelType(this Type colorStructClrType) => ClrTypes2PixelTypes[colorStructClrType]; - - public static IEnumerable> ExpandAllTypes(this PixelTypes pixelTypes) { if (pixelTypes == PixelTypes.Undefined) diff --git a/tests/Images/External b/tests/Images/External index eb40b3c03..b1f057df3 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit eb40b3c039dd8c8ca448cb8073a59ca178901e9f +Subproject commit b1f057df33b7bfa6cabe714cf7090ac6017ea5d8 From 5e428ed45827bf0115f1e4afb1e730fa3f4c05ec Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 02:31:33 +0200 Subject: [PATCH 10/17] Image.WrapMemory works --- src/ImageSharp/Image.WrapMemory.cs | 59 ++++++++++++++++++ src/ImageSharp/ImageFrameCollection.cs | 11 ++++ src/ImageSharp/ImageFrame{TPixel}.cs | 31 +++++++++- src/ImageSharp/Image{TPixel}.cs | 24 +++++++- src/ImageSharp/Memory/BasicArrayBuffer.cs | 4 +- src/ImageSharp/Memory/ConsumedBuffer.cs | 32 ++++++++++ .../Advanced/AdvancedImageExtensionsTests.cs | 60 ++++++++++++++++++- .../Image/ImageFramesCollectionTests.cs | 2 +- 8 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 src/ImageSharp/Image.WrapMemory.cs create mode 100644 src/ImageSharp/Memory/ConsumedBuffer.cs diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs new file mode 100644 index 000000000..5abc4e132 --- /dev/null +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -0,0 +1,59 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.MetaData; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp +{ + /// + /// Adds static methods allowing wrapping an existing memory area as an image. + /// + public static partial class Image + { + // TODO: This is a WIP API, should be public when finished. + + /// + /// Wraps an existing contigous memory area of 'width'x'height' pixels, + /// allowing to view/manipulate it as an ImageSharp instance. + /// + /// The pixel type + /// The + /// The pixel memory + /// The width of the memory image + /// The height of the memory image + /// The + /// An instance + internal static Image WrapMemory( + Configuration config, + Memory pixelMemory, + int width, + int height, + ImageMetaData metaData) + where TPixel : struct, IPixel + { + var buffer = new ConsumedBuffer(pixelMemory); + return new Image(config, buffer, width, height, metaData); + } + + /// + /// Wraps an existing contigous memory area of 'width'x'height' pixels, + /// allowing to view/manipulate it as an ImageSharp instance. + /// + /// The pixel type + /// The pixel memory + /// The width of the memory image + /// The height of the memory image + /// An instance + internal static Image WrapMemory( + Memory pixelMemory, + int width, + int height) + where TPixel : struct, IPixel + { + return WrapMemory(Configuration.Default, pixelMemory, width, height, new ImageMetaData()); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index c101b48d3..181ffbce3 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp @@ -29,6 +30,16 @@ namespace SixLabors.ImageSharp this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); } + internal ImageFrameCollection(Image parent, int width, int height, IBuffer consumedBuffer) + { + Guard.NotNull(parent, nameof(parent)); + + this.parent = parent; + + // Frames are already cloned within the caller + this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, consumedBuffer)); + } + internal ImageFrameCollection(Image parent, IEnumerable> frames) { Guard.NotNull(parent, nameof(parent)); diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 328252344..a41a2bf3b 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp /// The height of the image in pixels. /// The meta data. internal ImageFrame(Configuration configuration, int width, int height, ImageFrameMetaData metaData) - : this(configuration, width, height, default, metaData) + : this(configuration, width, height, default(TPixel), metaData) { } @@ -91,6 +91,35 @@ namespace SixLabors.ImageSharp this.Clear(configuration.ParallelOptions, backgroundColor); } + /// + /// Initializes a new instance of the class wrapping an existing buffer. + /// + internal ImageFrame(Configuration configuration, int width, int height, IBuffer consumedBuffer) + : this(configuration, width, height, consumedBuffer, new ImageFrameMetaData()) + { + } + + /// + /// Initializes a new instance of the class wrapping an existing buffer. + /// + internal ImageFrame( + Configuration configuration, + int width, + int height, + IBuffer consumedBuffer, + ImageFrameMetaData metaData) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + Guard.NotNull(metaData, nameof(metaData)); + + this.configuration = configuration; + this.MemoryManager = configuration.MemoryManager; + this.PixelBuffer = new Buffer2D(consumedBuffer, width, height); + this.MetaData = metaData; + } + /// /// Initializes a new instance of the class. /// diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 324385601..2a95398e1 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; @@ -78,7 +79,28 @@ namespace SixLabors.ImageSharp this.configuration = configuration ?? Configuration.Default; this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); this.MetaData = metadata ?? new ImageMetaData(); - this.frames = new ImageFrameCollection(this, width, height, default); + this.frames = new ImageFrameCollection(this, width, height, default(TPixel)); + } + + /// + /// Initializes a new instance of the class + /// consuming an external buffer instance. + /// + internal Image(Configuration configuration, IBuffer consumedBuffer, int width, int height) + : this(configuration, consumedBuffer, width, height, new ImageMetaData()) + { + } + + /// + /// Initializes a new instance of the class + /// consuming an external buffer instance. + /// + internal Image(Configuration configuration, IBuffer consumedBuffer, int width, int height, ImageMetaData metadata) + { + this.configuration = configuration; + this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); + this.MetaData = metadata; + this.frames = new ImageFrameCollection(this, width, height, consumedBuffer); } /// diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index 450399900..3b62f8a31 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -1,5 +1,7 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using System; -using System.Buffers; using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Memory diff --git a/src/ImageSharp/Memory/ConsumedBuffer.cs b/src/ImageSharp/Memory/ConsumedBuffer.cs new file mode 100644 index 000000000..1f1bb76e4 --- /dev/null +++ b/src/ImageSharp/Memory/ConsumedBuffer.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.Memory +{ + /// + /// A buffer implementation that consumes an existing instance. + /// The ownership of the memory remains external. + /// + /// The value type + internal sealed class ConsumedBuffer : IBuffer + where T : struct + { + public ConsumedBuffer(Memory memory) + { + this.Memory = memory; + } + + public Memory Memory { get; } + + public Span GetSpan() + { + return this.Memory.Span; + } + + public void Dispose() + { + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 2825ddd77..3fe1380e4 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -9,7 +9,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Advanced { - + using System.Buffers; public class AdvancedImageExtensionsTests { @@ -39,6 +39,64 @@ namespace SixLabors.ImageSharp.Tests.Advanced } } } + + class TestMemoryManager : System.Buffers.MemoryManager + { + public TestMemoryManager(TPixel[] pixelArray) + { + this.PixelArray = pixelArray; + } + + public TPixel[] PixelArray { get; } + + protected override void Dispose(bool disposing) + { + } + + public override Span GetSpan() + { + return this.PixelArray; + } + + public override MemoryHandle Pin(int elementIndex = 0) + { + throw new NotImplementedException(); + } + + public override void Unpin() + { + throw new NotImplementedException(); + } + } + + [Theory] + [WithSolidFilledImages(1, 1, "Red", PixelTypes.Rgba32 | PixelTypes.Bgr24)] + [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] + public void WhenMemoryIsConsumed(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image0 = provider.GetImage()) + { + var targetBuffer = new TPixel[image0.Width * image0.Height]; + image0.GetPixelSpan().CopyTo(targetBuffer); + + var managerOfExeternalMemory = new TestMemoryManager(targetBuffer); + + Memory externalMemory = managerOfExeternalMemory.Memory; + + using (Image image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height)) + { + Memory internalMemory = image1.GetPixelMemory(); + Assert.Equal(targetBuffer.Length, internalMemory.Length); + Assert.True(Unsafe.AreSame(ref targetBuffer[0], ref internalMemory.Span[0])); + + image0.ComparePixelBufferTo(internalMemory.Span); + } + + // Make sure externalMemory works after destruction: + image0.ComparePixelBufferTo(externalMemory.Span); + } + } } [Theory] diff --git a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs index a26d88720..392397057 100644 --- a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); this.image = new Image(10, 10); - this.collection = new ImageFrameCollection(this.image, 10, 10, default); + this.collection = new ImageFrameCollection(this.image, 10, 10, default(Rgba32)); } [Fact] From 6585f9551f73f79aa377609d31c7b37ea92517df Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 02:37:19 +0200 Subject: [PATCH 11/17] RENAME: MemoryManager -> MemoryAllocator --- .../Primitives/ShapeRegion.cs | 2 +- .../Drawing/Brushes/BrushApplicator.cs | 8 ++-- .../Drawing/Brushes/ImageBrush{TPixel}.cs | 6 +-- .../Drawing/Brushes/PatternBrush{TPixel}.cs | 8 ++-- .../Drawing/Brushes/RecolorBrush{TPixel}.cs | 8 ++-- .../Drawing/Brushes/SolidBrush{TPixel}.cs | 10 ++-- .../Drawing/Processors/DrawImageProcessor.cs | 6 +-- .../Drawing/Processors/FillProcessor.cs | 2 +- .../Drawing/Processors/FillRegionProcessor.cs | 4 +- .../Advanced/AdvancedImageExtensions.cs | 6 +-- src/ImageSharp/Common/Helpers/ParallelFor.cs | 6 +-- src/ImageSharp/Configuration.cs | 6 +-- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 14 +++--- src/ImageSharp/Formats/Bmp/BmpEncoder.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 10 ++-- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 12 ++--- src/ImageSharp/Formats/Gif/GifEncoder.cs | 2 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 12 ++--- src/ImageSharp/Formats/Gif/LzwDecoder.cs | 10 ++-- src/ImageSharp/Formats/Gif/LzwEncoder.cs | 8 ++-- .../Decoder/JpegComponentPostProcessor.cs | 4 +- .../Decoder/JpegImagePostProcessor.cs | 8 ++-- .../Components/Decoder/GolangComponent.cs | 6 +-- .../Jpeg/GolangPort/GolangJpegDecoderCore.cs | 4 +- .../Components/DoubleBufferedStreamReader.cs | 6 +-- .../Components/PdfJsFrameComponent.cs | 8 ++-- .../PdfJsPort/Components/PdfJsHuffmanTable.cs | 8 ++-- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 14 +++--- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 18 ++++---- src/ImageSharp/Formats/Png/PngEncoder.cs | 2 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 26 +++++------ src/ImageSharp/Image.Decode.cs | 2 +- src/ImageSharp/ImageFrame{TPixel}.cs | 14 +++--- ... => ArrayPoolMemoryAllocator.Buffer{T}.cs} | 8 ++-- ...olMemoryAllocator.CommonFactoryMethods.cs} | 18 ++++---- ...Manager.cs => ArrayPoolMemoryAllocator.cs} | 20 ++++---- .../{MemoryManager.cs => MemoryAllocator.cs} | 2 +- ...nsions.cs => MemoryAllocatorExtensions.cs} | 44 +++++++++--------- ...yManager.cs => SimpleGcMemoryAllocator.cs} | 4 +- .../DefaultPixelBlenders.Generated.cs | 42 ++++++++--------- .../DefaultPixelBlenders.Generated.tt | 2 +- .../PixelFormats/PixelBlender{TPixel}.cs | 4 +- .../Processors/Convolution2DProcessor.cs | 2 +- .../Processors/Convolution2PassProcessor.cs | 2 +- .../Processors/ConvolutionProcessor.cs | 2 +- .../DefaultInternalImageProcessorContext.cs | 2 +- .../Processors/OilPaintingProcessor.cs | 2 +- .../IImageProcessingContext{TPixel}.cs | 4 +- .../Processors/BackgroundColorProcessor.cs | 6 +-- .../Overlays/Processors/GlowProcessor.cs | 6 +-- .../Overlays/Processors/VignetteProcessor.cs | 6 +-- .../WuFrameQuantizer{TPixel}.cs | 46 +++++++++---------- .../Processors/AffineTransformProcessor.cs | 6 +-- .../Transforms/Processors/FlipProcessor.cs | 4 +- .../ProjectiveTransformProcessor.cs | 6 +-- .../Transforms/Processors/ResizeProcessor.cs | 14 +++--- .../Transforms/Processors/WeightsBuffer.cs | 6 +-- .../Codecs/Jpeg/DoubleBufferedStreams.cs | 4 +- .../Codecs/Jpeg/YCbCrColorConversion.cs | 2 +- .../Color/Bulk/PackFromVector4.cs | 4 +- .../Color/Bulk/PackFromXyzw.cs | 4 +- .../Color/Bulk/ToVector4.cs | 4 +- .../ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 4 +- .../Color/Bulk/ToXyzw.cs | 4 +- .../PixelBlenders/PorterDuffBulkVsPixel.cs | 6 +-- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 2 +- .../Advanced/AdvancedImageExtensionsTests.cs | 2 +- .../FakeImageOperationsProvider.cs | 2 +- .../Formats/GeneralFormatTests.cs | 4 +- .../Jpg/Block8x8FTests.CopyToBufferArea.cs | 4 +- .../Jpg/DoubleBufferedStreamReaderTests.cs | 12 ++--- .../Formats/Jpg/JpegDecoderTests.Baseline.cs | 4 +- .../Jpg/JpegDecoderTests.Progressive.cs | 4 +- .../Formats/Jpg/JpegDecoderTests.cs | 4 +- .../Jpg/JpegImagePostProcessorTests.cs | 4 +- .../Jpg/Utils/LibJpegTools.ComponentData.cs | 2 +- .../Memory/ArrayPoolMemoryManagerTests.cs | 38 +++++++-------- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 18 ++++---- .../Memory/BufferAreaTests.cs | 4 +- .../Memory/BufferTestSuite.cs | 20 ++++---- .../Memory/SimpleGcMemoryManagerTests.cs | 2 +- .../PorterDuffFunctionsTests_TPixel.cs | 20 ++++---- .../PixelFormats/PixelOperationsTests.cs | 6 +-- .../Transforms/ResizeProfilingBenchmarks.cs | 2 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 6 +-- .../TestUtilities/TestImageExtensions.cs | 4 +- 86 files changed, 358 insertions(+), 358 deletions(-) rename src/ImageSharp/Memory/{ArrayPoolMemoryManager.Buffer{T}.cs => ArrayPoolMemoryAllocator.Buffer{T}.cs} (91%) rename src/ImageSharp/Memory/{ArrayPoolMemoryManager.CommonFactoryMethods.cs => ArrayPoolMemoryAllocator.CommonFactoryMethods.cs} (77%) rename src/ImageSharp/Memory/{ArrayPoolMemoryManager.cs => ArrayPoolMemoryAllocator.cs} (88%) rename src/ImageSharp/Memory/{MemoryManager.cs => MemoryAllocator.cs} (97%) rename src/ImageSharp/Memory/{MemoryManagerExtensions.cs => MemoryAllocatorExtensions.cs} (52%) rename src/ImageSharp/Memory/{SimpleGcMemoryManager.cs => SimpleGcMemoryAllocator.cs} (72%) diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index 4c446189e..cb4305248 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Primitives var start = new PointF(this.Bounds.Left - 1, y); var end = new PointF(this.Bounds.Right + 1, y); - using (IBuffer tempBuffer = configuration.MemoryManager.Allocate(buffer.Length)) + using (IBuffer tempBuffer = configuration.MemoryAllocator.Allocate(buffer.Length)) { Span innerBuffer = tempBuffer.GetSpan(); int count = this.Shape.FindIntersections(start, end, innerBuffer); diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs index 83bff9c47..bd22759fc 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs @@ -65,10 +65,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes /// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs. internal virtual void Apply(Span scanline, int x, int y) { - MemoryManager memoryManager = this.Target.MemoryManager; + MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; - using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) + using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs index dfdc1721d..30e48b54c 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs @@ -118,8 +118,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes internal override void Apply(Span scanline, int x, int y) { // Create a span for colors - using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length)) + using (IBuffer amountBuffer = this.Target.MemoryAllocator.Allocate(scanline.Length)) + using (IBuffer overlay = this.Target.MemoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); @@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(this.source.MemoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(this.source.MemoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs index b5bc5a7ef..dccb05f87 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs @@ -151,10 +151,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes internal override void Apply(Span scanline, int x, int y) { int patternY = y % this.pattern.Rows; - MemoryManager memoryManager = this.Target.MemoryManager; + MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; - using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) + using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); @@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs index 05607472e..a2d5c296d 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -136,10 +136,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes /// internal override void Apply(Span scanline, int x, int y) { - MemoryManager memoryManager = this.Target.MemoryManager; + MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; - using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) + using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); @@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs index a32152ba0..c5ea5792f 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes public SolidBrushApplicator(ImageFrame source, TPixel color, GraphicsOptions options) : base(source, options) { - this.Colors = source.MemoryManager.Allocate(source.Width); + this.Colors = source.MemoryAllocator.Allocate(source.Width); this.Colors.GetSpan().Fill(color); } @@ -88,15 +88,15 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - MemoryManager memoryManager = this.Target.MemoryManager; + MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; if (this.Options.BlendPercentage == 1f) { - this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.GetSpan(), scanline); + this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), scanline); } else { - using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) + using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes amountSpan[i] = scanline[i] * this.Options.BlendPercentage; } - this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan); + this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs index c5691aa64..38805c517 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs @@ -133,9 +133,9 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors int width = maxX - minX; - MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager; + MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator; - using (IBuffer amount = memoryManager.Allocate(width)) + using (IBuffer amount = memoryAllocator.Allocate(width)) { amount.GetSpan().Fill(this.Opacity); @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors { Span background = source.GetPixelRowSpan(y).Slice(minX, width); Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); - blender.Blend(memoryManager, background, background, foreground, amount.GetSpan()); + blender.Blend(memoryAllocator, background, background, foreground, amount.GetSpan()); }); } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs index 3cf2f7d63..7a0b7a05d 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors startY = 0; } - using (IBuffer amount = source.MemoryManager.Allocate(width)) + using (IBuffer amount = source.MemoryAllocator.Allocate(width)) using (BrushApplicator applicator = this.brush.CreateApplicator( source, sourceRectangle, diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 4072f88a8..916da360b 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -96,8 +96,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors using (BrushApplicator applicator = this.Brush.CreateApplicator(source, rect, this.Options)) { int scanlineWidth = maxX - minX; - using (IBuffer bBuffer = source.MemoryManager.Allocate(maxIntersections)) - using (IBuffer bScanline = source.MemoryManager.Allocate(scanlineWidth)) + using (IBuffer bBuffer = source.MemoryAllocator.Allocate(maxIntersections)) + using (IBuffer bScanline = source.MemoryAllocator.Allocate(scanlineWidth)) { bool scanlineDirty = true; float subpixelFraction = 1f / subpixelCount; diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 1d7f33a9a..337f82e03 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -144,12 +144,12 @@ namespace SixLabors.ImageSharp.Advanced => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); /// - /// Gets the assigned to 'source'. + /// Gets the assigned to 'source'. /// /// The source image /// Returns the configuration. - internal static MemoryManager GetMemoryManager(this IConfigurable source) - => GetConfiguration(source).MemoryManager; + internal static MemoryAllocator GetMemoryAllocator(this IConfigurable source) + => GetConfiguration(source).MemoryAllocator; /// /// Gets the span to the backing buffer. diff --git a/src/ImageSharp/Common/Helpers/ParallelFor.cs b/src/ImageSharp/Common/Helpers/ParallelFor.cs index da9125905..fc22b42be 100644 --- a/src/ImageSharp/Common/Helpers/ParallelFor.cs +++ b/src/ImageSharp/Common/Helpers/ParallelFor.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp /// The value type of the buffer /// The start index, inclusive. /// The end index, exclusive. - /// The used for getting the and + /// The used for getting the and /// The length of the requested parallel buffer /// The delegate that is invoked once per iteration. public static void WithTemporaryBuffer( @@ -35,12 +35,12 @@ namespace SixLabors.ImageSharp Action> body) where T : struct { - MemoryManager memoryManager = configuration.MemoryManager; + MemoryAllocator memoryAllocator = configuration.MemoryAllocator; ParallelOptions parallelOptions = configuration.ParallelOptions; IBuffer InitBuffer() { - return memoryManager.Allocate(bufferLength); + return memoryAllocator.Allocate(bufferLength); } void CleanUpBuffer(IBuffer buffer) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index eb08bc579..f30b5469f 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -75,9 +75,9 @@ namespace SixLabors.ImageSharp public ImageFormatManager ImageFormatsManager { get; set; } = new ImageFormatManager(); /// - /// Gets or sets the that is currently in use. + /// Gets or sets the that is currently in use. /// - public MemoryManager MemoryManager { get; set; } = ArrayPoolMemoryManager.CreateDefault(); + public MemoryAllocator MemoryAllocator { get; set; } = ArrayPoolMemoryAllocator.CreateDefault(); /// /// Gets the maximum header size of all the formats. @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp { ParallelOptions = this.ParallelOptions, ImageFormatsManager = this.ImageFormatsManager, - MemoryManager = this.MemoryManager, + MemoryAllocator = this.MemoryAllocator, ImageOperationsProvider = this.ImageOperationsProvider, ReadOrigin = this.ReadOrigin, diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 43be0004e..b6905a62f 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp private readonly Configuration configuration; - private readonly MemoryManager memoryManager; + private readonly MemoryAllocator memoryAllocator; /// /// Initializes a new instance of the class. @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp public BmpDecoderCore(Configuration configuration, IBmpDecoderOptions options) { this.configuration = configuration; - this.memoryManager = configuration.MemoryManager; + this.memoryAllocator = configuration.MemoryAllocator; } /// @@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp var color = default(TPixel); var rgba = new Rgba32(0, 0, 0, 255); - using (Buffer2D buffer = this.memoryManager.AllocateClean2D(width, height)) + using (Buffer2D buffer = this.memoryAllocator.AllocateClean2D(width, height)) { this.UncompressRle8(width, buffer.GetSpan()); @@ -337,7 +337,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp padding = 4 - padding; } - using (IManagedByteBuffer row = this.memoryManager.AllocateCleanManagedByteBuffer(arrayWidth + padding)) + using (IManagedByteBuffer row = this.memoryAllocator.AllocateCleanManagedByteBuffer(arrayWidth + padding)) { TPixel color = default; var rgba = new Rgba32(0, 0, 0, 255); @@ -389,7 +389,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp var color = default(TPixel); var rgba = new Rgba32(0, 0, 0, 255); - using (IManagedByteBuffer buffer = this.memoryManager.AllocateManagedByteBuffer(stride)) + using (IManagedByteBuffer buffer = this.memoryAllocator.AllocateManagedByteBuffer(stride)) { for (int y = 0; y < height; y++) { @@ -427,7 +427,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { int padding = CalculatePadding(width, 3); - using (IManagedByteBuffer row = this.memoryManager.AllocatePaddedPixelRowBuffer(width, 3, padding)) + using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 3, padding)) { for (int y = 0; y < height; y++) { @@ -452,7 +452,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { int padding = CalculatePadding(width, 4); - using (IManagedByteBuffer row = this.memoryManager.AllocatePaddedPixelRowBuffer(width, 4, padding)) + using (IManagedByteBuffer row = this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, 4, padding)) { for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs index 9edd0fcd4..23b01ae9e 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp public void Encode(Image image, Stream stream) where TPixel : struct, IPixel { - var encoder = new BmpEncoderCore(this, image.GetMemoryManager()); + var encoder = new BmpEncoderCore(this, image.GetMemoryAllocator()); encoder.Encode(image, stream); } } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index aefcda402..aff0c024d 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -20,16 +20,16 @@ namespace SixLabors.ImageSharp.Formats.Bmp private readonly BmpBitsPerPixel bitsPerPixel; - private readonly MemoryManager memoryManager; + private readonly MemoryAllocator memoryAllocator; /// /// Initializes a new instance of the class. /// /// The encoder options - /// The memory manager - public BmpEncoderCore(IBmpEncoderOptions options, MemoryManager memoryManager) + /// The memory manager + public BmpEncoderCore(IBmpEncoderOptions options, MemoryAllocator memoryAllocator) { - this.memoryManager = memoryManager; + this.memoryAllocator = memoryAllocator; this.bitsPerPixel = options.BitsPerPixel; } @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp private IManagedByteBuffer AllocateRow(int width, int bytesPerPixel) { - return this.memoryManager.AllocatePaddedPixelRowBuffer(width, bytesPerPixel, this.padding); + return this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, bytesPerPixel, this.padding); } /// diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index d37682a3d..bba983af8 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public FrameDecodingMode DecodingMode { get; } - private MemoryManager MemoryManager => this.configuration.MemoryManager; + private MemoryAllocator MemoryAllocator => this.configuration.MemoryAllocator; /// /// Decodes the stream to the image. @@ -293,7 +293,7 @@ namespace SixLabors.ImageSharp.Formats.Gif continue; } - using (IManagedByteBuffer commentsBuffer = this.MemoryManager.AllocateManagedByteBuffer(length)) + using (IManagedByteBuffer commentsBuffer = this.MemoryAllocator.AllocateManagedByteBuffer(length)) { this.stream.Read(commentsBuffer.Array, 0, length); string comments = this.TextEncoding.GetString(commentsBuffer.Array, 0, length); @@ -321,11 +321,11 @@ namespace SixLabors.ImageSharp.Formats.Gif if (imageDescriptor.LocalColorTableFlag) { int length = imageDescriptor.LocalColorTableSize * 3; - localColorTable = this.configuration.MemoryManager.AllocateManagedByteBuffer(length, true); + localColorTable = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(length, true); this.stream.Read(localColorTable.Array, 0, length); } - indices = this.configuration.MemoryManager.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, true); + indices = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, true); this.ReadFrameIndices(imageDescriptor, indices.GetSpan()); ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).GetSpan()); @@ -350,7 +350,7 @@ namespace SixLabors.ImageSharp.Formats.Gif private void ReadFrameIndices(in GifImageDescriptor imageDescriptor, Span indices) { int dataSize = this.stream.ReadByte(); - using (var lzwDecoder = new LzwDecoder(this.configuration.MemoryManager, this.stream)) + using (var lzwDecoder = new LzwDecoder(this.configuration.MemoryAllocator, this.stream)) { lzwDecoder.DecodePixels(imageDescriptor.Width, imageDescriptor.Height, dataSize, indices); } @@ -528,7 +528,7 @@ namespace SixLabors.ImageSharp.Formats.Gif { int globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3; - this.globalColorTable = this.MemoryManager.AllocateManagedByteBuffer(globalColorTableLength, true); + this.globalColorTable = this.MemoryAllocator.AllocateManagedByteBuffer(globalColorTableLength, true); // Read the global color table data from the stream stream.Read(this.globalColorTable.Array, 0, globalColorTableLength); diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index fb072bcb7..a07928b04 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Gif public void Encode(Image image, Stream stream) where TPixel : struct, IPixel { - var encoder = new GifEncoderCore(image.GetConfiguration().MemoryManager, this); + var encoder = new GifEncoderCore(image.GetConfiguration().MemoryAllocator, this); encoder.Encode(image, stream); } } diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 6f134c4bd..8de347086 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// internal sealed class GifEncoderCore { - private readonly MemoryManager memoryManager; + private readonly MemoryAllocator memoryAllocator; /// /// A reusable buffer used to reduce allocations. @@ -49,11 +49,11 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The options for the encoder. - public GifEncoderCore(MemoryManager memoryManager, IGifEncoderOptions options) + public GifEncoderCore(MemoryAllocator memoryAllocator, IGifEncoderOptions options) { - this.memoryManager = memoryManager; + this.memoryAllocator = memoryAllocator; this.textEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding; this.quantizer = options.Quantizer; this.ignoreMetadata = options.IgnoreMetadata; @@ -317,7 +317,7 @@ namespace SixLabors.ImageSharp.Formats.Gif int colorTableLength = (int)Math.Pow(2, this.bitDepth) * 3; // The maximium number of colors for the bit depth Rgb24 rgb = default; - using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) + using (IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength)) { ref TPixel paletteRef = ref MemoryMarshal.GetReference(image.Palette.AsSpan()); ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.GetSpan())); @@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Gif private void WriteImageData(QuantizedFrame image, Stream stream) where TPixel : struct, IPixel { - using (var encoder = new LzwEncoder(this.memoryManager, image.Pixels, (byte)this.bitDepth)) + using (var encoder = new LzwEncoder(this.memoryAllocator, image.Pixels, (byte)this.bitDepth)) { encoder.Encode(stream); } diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index f52a8b240..aaf0547b9 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -48,18 +48,18 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Initializes a new instance of the class /// and sets the stream, where the compressed data should be read from. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The stream to read from. /// is null. - public LzwDecoder(MemoryManager memoryManager, Stream stream) + public LzwDecoder(MemoryAllocator memoryAllocator, Stream stream) { Guard.NotNull(stream, nameof(stream)); this.stream = stream; - this.prefix = memoryManager.Allocate(MaxStackSize, true); - this.suffix = memoryManager.Allocate(MaxStackSize, true); - this.pixelStack = memoryManager.Allocate(MaxStackSize + 1, true); + this.prefix = memoryAllocator.Allocate(MaxStackSize, true); + this.suffix = memoryAllocator.Allocate(MaxStackSize, true); + this.pixelStack = memoryAllocator.Allocate(MaxStackSize + 1, true); } /// diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index a23d2f4e2..f3e75b6f6 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -168,16 +168,16 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The array of indexed pixels. /// The color depth in bits. - public LzwEncoder(MemoryManager memoryManager, byte[] indexedPixels, int colorDepth) + public LzwEncoder(MemoryAllocator memoryAllocator, byte[] indexedPixels, int colorDepth) { this.pixelArray = indexedPixels; this.initialCodeSize = Math.Max(2, colorDepth); - this.hashTable = memoryManager.Allocate(HashSize, true); - this.codeTable = memoryManager.Allocate(HashSize, true); + this.hashTable = memoryAllocator.Allocate(HashSize, true); + this.codeTable = memoryAllocator.Allocate(HashSize, true); } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs index fe18f8438..edb34bc03 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs @@ -26,11 +26,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Initializes a new instance of the class. /// - public JpegComponentPostProcessor(MemoryManager memoryManager, JpegImagePostProcessor imagePostProcessor, IJpegComponent component) + public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, JpegImagePostProcessor imagePostProcessor, IJpegComponent component) { this.Component = component; this.ImagePostProcessor = imagePostProcessor; - this.ColorBuffer = memoryManager.Allocate2D( + this.ColorBuffer = memoryAllocator.Allocate2D( imagePostProcessor.PostProcessorBufferSize.Width, imagePostProcessor.PostProcessorBufferSize.Height); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index a8def1e19..1a7f8bebb 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -49,17 +49,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The representing the uncompressed spectral Jpeg data - public JpegImagePostProcessor(MemoryManager memoryManager, IRawJpegData rawJpeg) + public JpegImagePostProcessor(MemoryAllocator memoryAllocator, IRawJpegData rawJpeg) { this.RawJpeg = rawJpeg; IJpegComponent c0 = rawJpeg.Components.First(); this.NumberOfPostProcessorSteps = c0.SizeInBlocks.Height / BlockRowsPerStep; this.PostProcessorBufferSize = new Size(c0.SizeInBlocks.Width * 8, PixelRowsPerStep); - this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryManager, this, c)).ToArray(); - this.rgbaBuffer = memoryManager.Allocate(rawJpeg.ImageSizeInPixels.Width); + this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryAllocator, this, c)).ToArray(); + this.rgbaBuffer = memoryAllocator.Allocate(rawJpeg.ImageSizeInPixels.Width); this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace); } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs index bb3bd01aa..2335800c2 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs @@ -56,9 +56,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// /// Initializes /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The instance - public void InitializeDerivedData(MemoryManager memoryManager, GolangJpegDecoderCore decoder) + public void InitializeDerivedData(MemoryAllocator memoryAllocator, GolangJpegDecoderCore decoder) { // For 4-component images (either CMYK or YCbCrK), we only support two // hv vectors: [0x11 0x11 0x11 0x11] and [0x22 0x11 0x11 0x22]. @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } - this.SpectralBlocks = memoryManager.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true); + this.SpectralBlocks = memoryAllocator.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true); } /// diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs index 86f97d224..34a6e2f0f 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs @@ -705,7 +705,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort foreach (GolangComponent component in this.Components) { - component.InitializeDerivedData(this.configuration.MemoryManager, this); + component.InitializeDerivedData(this.configuration.MemoryAllocator, this); } } } @@ -812,7 +812,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort private Image PostProcessIntoImage() where TPixel : struct, IPixel { - using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this)) + using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this)) { var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData); postProcessor.PostProcess(image.Frames.RootFrame); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs index eb91590e8..ae1dbf75e 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs @@ -38,13 +38,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The input stream. - public DoubleBufferedStreamReader(MemoryManager memoryManager, Stream stream) + public DoubleBufferedStreamReader(MemoryAllocator memoryAllocator, Stream stream) { this.stream = stream; this.length = (int)stream.Length; - this.managedBuffer = memoryManager.AllocateCleanManagedByteBuffer(ChunkLength); + this.managedBuffer = memoryAllocator.AllocateCleanManagedByteBuffer(ChunkLength); this.bufferChunk = this.managedBuffer.Array; } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index 70ac760e6..9a17b2dfa 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// internal class PdfJsFrameComponent : IDisposable, IJpegComponent { - private readonly MemoryManager memoryManager; + private readonly MemoryAllocator memoryAllocator; - public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) + public PdfJsFrameComponent(MemoryAllocator memoryAllocator, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) { - this.memoryManager = memoryManager; + this.memoryAllocator = memoryAllocator; this.Frame = frame; this.Id = id; this.HorizontalSamplingFactor = horizontalFactor; @@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } - this.SpectralBlocks = this.memoryManager.Allocate2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true); + this.SpectralBlocks = this.memoryAllocator.Allocate2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs index e8e0054f2..4a8f9debe 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs @@ -37,14 +37,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// /// Initializes a new instance of the struct. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The code lengths /// The huffman values - public PdfJsHuffmanTable(MemoryManager memoryManager, ReadOnlySpan lengths, ReadOnlySpan values) + public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan lengths, ReadOnlySpan values) { const int length = 257; - using (IBuffer huffsize = memoryManager.Allocate(length)) - using (IBuffer huffcode = memoryManager.Allocate(length)) + using (IBuffer huffsize = memoryAllocator.Allocate(length)) + using (IBuffer huffcode = memoryAllocator.Allocate(length)) { ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan()); ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan()); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index 69994ee59..625c8f691 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -219,7 +219,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort public void ParseStream(Stream stream, bool metadataOnly = false) { this.MetaData = new ImageMetaData(); - this.InputStream = new DoubleBufferedStreamReader(this.configuration.MemoryManager, stream); + this.InputStream = new DoubleBufferedStreamReader(this.configuration.MemoryAllocator, stream); // Check for the Start Of Image marker. this.InputStream.Read(this.markerBuffer, 0, 2); @@ -675,7 +675,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort maxV = v; } - var component = new PdfJsFrameComponent(this.configuration.MemoryManager, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); + var component = new PdfJsFrameComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); this.Frame.Components[i] = component; this.Frame.ComponentIds[i] = component.Id; @@ -703,7 +703,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort throw new ImageFormatException($"DHT has wrong length: {remaining}"); } - using (IManagedByteBuffer huffmanData = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(256)) + using (IManagedByteBuffer huffmanData = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(256)) { ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.GetSpan()); for (int i = 2; i < remaining;) @@ -711,7 +711,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort byte huffmanTableSpec = (byte)this.InputStream.ReadByte(); this.InputStream.Read(huffmanData.Array, 0, 16); - using (IManagedByteBuffer codeLengths = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(17)) + using (IManagedByteBuffer codeLengths = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(17)) { ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.GetSpan()); int codeLengthSum = 0; @@ -721,7 +721,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort codeLengthSum += Unsafe.Add(ref codeLengthsRef, j) = Unsafe.Add(ref huffmanDataRef, j - 1); } - using (IManagedByteBuffer huffmanValues = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(256)) + using (IManagedByteBuffer huffmanValues = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(256)) { this.InputStream.Read(huffmanValues.Array, 0, codeLengthSum); @@ -817,7 +817,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort [MethodImpl(MethodImplOptions.AggressiveInlining)] private void BuildHuffmanTable(PdfJsHuffmanTables tables, int index, ReadOnlySpan codeLengths, ReadOnlySpan values) { - tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryManager, codeLengths, values); + tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryAllocator, codeLengths, values); } /// @@ -834,7 +834,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort private Image PostProcessIntoImage() where TPixel : struct, IPixel { - using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this)) + using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this)) { var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData); postProcessor.PostProcess(image.Frames.RootFrame); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 15edf2ad3..f481dc508 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -188,7 +188,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.ignoreMetadata = options.IgnoreMetadata; } - private MemoryManager MemoryManager => this.configuration.MemoryManager; + private MemoryAllocator MemoryAllocator => this.configuration.MemoryAllocator; /// /// Decodes the stream to the image. @@ -410,8 +410,8 @@ namespace SixLabors.ImageSharp.Formats.Png this.bytesPerSample = this.header.BitDepth / 8; } - this.previousScanline = this.MemoryManager.AllocateCleanManagedByteBuffer(this.bytesPerScanline); - this.scanline = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(this.bytesPerScanline); + this.previousScanline = this.MemoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); + this.scanline = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); } /// @@ -727,7 +727,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (this.header.BitDepth == 16) { int length = this.header.Width * 3; - using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) + using (IBuffer compressed = this.configuration.MemoryAllocator.Allocate(length)) { // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); @@ -744,7 +744,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (this.header.BitDepth == 16) { int length = this.header.Width * 3; - using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) + using (IBuffer compressed = this.configuration.MemoryAllocator.Allocate(length)) { // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); @@ -785,7 +785,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (this.header.BitDepth == 16) { int length = this.header.Width * 4; - using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) + using (IBuffer compressed = this.configuration.MemoryAllocator.Allocate(length)) { // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); @@ -984,7 +984,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (this.header.BitDepth == 16) { int length = this.header.Width * 3; - using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) + using (IBuffer compressed = this.configuration.MemoryAllocator.Allocate(length)) { Span compressedSpan = compressed.GetSpan(); @@ -1054,7 +1054,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (this.header.BitDepth == 16) { int length = this.header.Width * 4; - using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) + using (IBuffer compressed = this.configuration.MemoryAllocator.Allocate(length)) { Span compressedSpan = compressed.GetSpan(); @@ -1273,7 +1273,7 @@ namespace SixLabors.ImageSharp.Formats.Png private IManagedByteBuffer ReadChunkData(int length) { // We rent the buffer here to return it afterwards in Decode() - IManagedByteBuffer buffer = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(length); + IManagedByteBuffer buffer = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(length); this.currentStream.Read(buffer.Array, 0, length); diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index b39a6353e..fab1b5185 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Formats.Png public void Encode(Image image, Stream stream) where TPixel : struct, IPixel { - using (var encoder = new PngEncoderCore(image.GetMemoryManager(), this)) + using (var encoder = new PngEncoderCore(image.GetMemoryAllocator(), this)) { encoder.Encode(image, stream); } diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index b9e09070e..1e6c186ec 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// internal sealed class PngEncoderCore : IDisposable { - private readonly MemoryManager memoryManager; + private readonly MemoryAllocator memoryAllocator; /// /// The maximum block size, defaults at 64k for uncompressed blocks. @@ -144,11 +144,11 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. + /// The to use for buffer allocations. /// The options for influencing the encoder - public PngEncoderCore(MemoryManager memoryManager, IPngEncoderOptions options) + public PngEncoderCore(MemoryAllocator memoryAllocator, IPngEncoderOptions options) { - this.memoryManager = memoryManager; + this.memoryAllocator = memoryAllocator; this.pngColorType = options.PngColorType; this.pngFilterMethod = options.PngFilterMethod; this.compressionLevel = options.CompressionLevel; @@ -460,8 +460,8 @@ namespace SixLabors.ImageSharp.Formats.Png Rgba32 rgba = default; bool anyAlpha = false; - using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) - using (IManagedByteBuffer alphaTable = this.memoryManager.AllocateManagedByteBuffer(pixelCount)) + using (IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength)) + using (IManagedByteBuffer alphaTable = this.memoryAllocator.AllocateManagedByteBuffer(pixelCount)) { Span colorTableSpan = colorTable.GetSpan(); Span alphaTableSpan = alphaTable.GetSpan(); @@ -552,16 +552,16 @@ namespace SixLabors.ImageSharp.Formats.Png this.bytesPerScanline = this.width * this.bytesPerPixel; int resultLength = this.bytesPerScanline + 1; - this.previousScanline = this.memoryManager.AllocateCleanManagedByteBuffer(this.bytesPerScanline); - this.rawScanline = this.memoryManager.AllocateCleanManagedByteBuffer(this.bytesPerScanline); - this.result = this.memoryManager.AllocateCleanManagedByteBuffer(resultLength); + this.previousScanline = this.memoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); + this.rawScanline = this.memoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); + this.result = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); if (this.pngColorType != PngColorType.Palette) { - this.sub = this.memoryManager.AllocateCleanManagedByteBuffer(resultLength); - this.up = this.memoryManager.AllocateCleanManagedByteBuffer(resultLength); - this.average = this.memoryManager.AllocateCleanManagedByteBuffer(resultLength); - this.paeth = this.memoryManager.AllocateCleanManagedByteBuffer(resultLength); + this.sub = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.up = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.average = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.paeth = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); } byte[] buffer; diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index 3f3dbb7e2..bd602875a 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp return null; } - using (IManagedByteBuffer buffer = config.MemoryManager.AllocateManagedByteBuffer(maxHeaderSize)) + using (IManagedByteBuffer buffer = config.MemoryAllocator.AllocateManagedByteBuffer(maxHeaderSize)) { long startPosition = stream.Position; stream.Read(buffer.Array, 0, maxHeaderSize); diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index a41a2bf3b..c6471df14 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -85,8 +85,8 @@ namespace SixLabors.ImageSharp Guard.NotNull(metaData, nameof(metaData)); this.configuration = configuration; - this.MemoryManager = configuration.MemoryManager; - this.PixelBuffer = this.MemoryManager.Allocate2D(width, height, false); + this.MemoryAllocator = configuration.MemoryAllocator; + this.PixelBuffer = this.MemoryAllocator.Allocate2D(width, height, false); this.MetaData = metaData; this.Clear(configuration.ParallelOptions, backgroundColor); } @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp Guard.NotNull(metaData, nameof(metaData)); this.configuration = configuration; - this.MemoryManager = configuration.MemoryManager; + this.MemoryAllocator = configuration.MemoryAllocator; this.PixelBuffer = new Buffer2D(consumedBuffer, width, height); this.MetaData = metaData; } @@ -131,16 +131,16 @@ namespace SixLabors.ImageSharp Guard.NotNull(source, nameof(source)); this.configuration = configuration; - this.MemoryManager = configuration.MemoryManager; - this.PixelBuffer = this.MemoryManager.Allocate2D(source.PixelBuffer.Width, source.PixelBuffer.Height); + this.MemoryAllocator = configuration.MemoryAllocator; + this.PixelBuffer = this.MemoryAllocator.Allocate2D(source.PixelBuffer.Width, source.PixelBuffer.Height); source.PixelBuffer.GetSpan().CopyTo(this.PixelBuffer.GetSpan()); this.MetaData = source.MetaData.Clone(); } /// - /// Gets the to use for buffer allocations. + /// Gets the to use for buffer allocations. /// - public MemoryManager MemoryManager { get; } + public MemoryAllocator MemoryAllocator { get; } /// /// Gets the image pixels. Not private as Buffer2D requires an array in its constructor. diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs similarity index 91% rename from src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs rename to src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs index afa5fdbb4..2216003e5 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs @@ -10,10 +10,10 @@ namespace SixLabors.ImageSharp.Memory /// /// Contains and /// - public partial class ArrayPoolMemoryManager + public partial class ArrayPoolMemoryAllocator { /// - /// The buffer implementation of . + /// The buffer implementation of . /// In this implementation is owned. /// private class Buffer : ManagedBufferBase, IBuffer @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Memory /// /// /// By using a weak reference here, we are making sure that array pools and their retained arrays are always GC-ed - /// after a call to , regardless of having buffer instances still being in use. + /// after a call to , regardless of having buffer instances still being in use. /// private WeakReference> sourcePoolReference; @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Memory } /// - /// The implementation of . + /// The implementation of . /// private class ManagedByteBuffer : Buffer, IManagedByteBuffer { diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs similarity index 77% rename from src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs rename to src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs index 53d7fc021..0f115764b 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs @@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Contains common factory methods and configuration constants. /// - public partial class ArrayPoolMemoryManager + public partial class ArrayPoolMemoryAllocator { /// /// The default value for: maximum size of pooled arrays in bytes. @@ -32,9 +32,9 @@ namespace SixLabors.ImageSharp.Memory /// This is the default. Should be good for most use cases. /// /// The memory manager - public static ArrayPoolMemoryManager CreateDefault() + public static ArrayPoolMemoryAllocator CreateDefault() { - return new ArrayPoolMemoryManager( + return new ArrayPoolMemoryAllocator( DefaultMaxPooledBufferSizeInBytes, DefaultBufferSelectorThresholdInBytes, DefaultLargePoolBucketCount, @@ -45,27 +45,27 @@ namespace SixLabors.ImageSharp.Memory /// For environments with limited memory capabilities. Only small images are pooled, which can result in reduced througput. /// /// The memory manager - public static ArrayPoolMemoryManager CreateWithModeratePooling() + public static ArrayPoolMemoryAllocator CreateWithModeratePooling() { - return new ArrayPoolMemoryManager(1024 * 1024, 32 * 1024, 16, 24); + return new ArrayPoolMemoryAllocator(1024 * 1024, 32 * 1024, 16, 24); } /// /// Only pool small buffers like image rows. /// /// The memory manager - public static ArrayPoolMemoryManager CreateWithMinimalPooling() + public static ArrayPoolMemoryAllocator CreateWithMinimalPooling() { - return new ArrayPoolMemoryManager(64 * 1024, 32 * 1024, 8, 24); + return new ArrayPoolMemoryAllocator(64 * 1024, 32 * 1024, 8, 24); } /// /// RAM is not an issue for me, gimme maximum througput! /// /// The memory manager - public static ArrayPoolMemoryManager CreateWithAggressivePooling() + public static ArrayPoolMemoryAllocator CreateWithAggressivePooling() { - return new ArrayPoolMemoryManager(128 * 1024 * 1024, 32 * 1024 * 1024, 16, 32); + return new ArrayPoolMemoryAllocator(128 * 1024 * 1024, 32 * 1024 * 1024, 16, 32); } } } \ No newline at end of file diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs similarity index 88% rename from src/ImageSharp/Memory/ArrayPoolMemoryManager.cs rename to src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs index 7b8c7ab32..8bc88a5cf 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs @@ -7,9 +7,9 @@ using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Memory { /// - /// Implements by allocating memory from . + /// Implements by allocating memory from . /// - public partial class ArrayPoolMemoryManager : MemoryManager + public partial class ArrayPoolMemoryAllocator : MemoryAllocator { /// /// The for small-to-medium buffers which is not kept clean. @@ -26,40 +26,40 @@ namespace SixLabors.ImageSharp.Memory private readonly int maxArraysPerBucketLargePool; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ArrayPoolMemoryManager() + public ArrayPoolMemoryAllocator() : this(DefaultMaxPooledBufferSizeInBytes, DefaultBufferSelectorThresholdInBytes) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. - public ArrayPoolMemoryManager(int maxPoolSizeInBytes) + public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes) : this(maxPoolSizeInBytes, GetLargeBufferThresholdInBytes(maxPoolSizeInBytes)) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. /// Arrays over this threshold will be pooled in which has less buckets for memory safety. - public ArrayPoolMemoryManager(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes) + public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes) : this(maxPoolSizeInBytes, poolSelectorThresholdInBytes, DefaultLargePoolBucketCount, DefaultNormalPoolBucketCount) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. /// The threshold to pool arrays in which has less buckets for memory safety. /// Max arrays per bucket for the large array pool /// Max arrays per bucket for the normal array pool - public ArrayPoolMemoryManager(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes, int maxArraysPerBucketLargePool, int maxArraysPerBucketNormalPool) + public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes, int maxArraysPerBucketLargePool, int maxArraysPerBucketNormalPool) { Guard.MustBeGreaterThan(maxPoolSizeInBytes, 0, nameof(maxPoolSizeInBytes)); Guard.MustBeLessThanOrEqualTo(poolSelectorThresholdInBytes, maxPoolSizeInBytes, nameof(poolSelectorThresholdInBytes)); diff --git a/src/ImageSharp/Memory/MemoryManager.cs b/src/ImageSharp/Memory/MemoryAllocator.cs similarity index 97% rename from src/ImageSharp/Memory/MemoryManager.cs rename to src/ImageSharp/Memory/MemoryAllocator.cs index 32b1c2001..c62128fd2 100644 --- a/src/ImageSharp/Memory/MemoryManager.cs +++ b/src/ImageSharp/Memory/MemoryAllocator.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Memory managers are used to allocate memory for image processing operations. /// - public abstract class MemoryManager + public abstract class MemoryAllocator { /// /// Allocates an of size , optionally diff --git a/src/ImageSharp/Memory/MemoryManagerExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs similarity index 52% rename from src/ImageSharp/Memory/MemoryManagerExtensions.cs rename to src/ImageSharp/Memory/MemoryAllocatorExtensions.cs index 206000245..1a92b7567 100644 --- a/src/ImageSharp/Memory/MemoryManagerExtensions.cs +++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs @@ -3,9 +3,9 @@ namespace SixLabors.ImageSharp.Memory { /// - /// Extension methods for . + /// Extension methods for . /// - internal static class MemoryManagerExtensions + internal static class MemoryAllocatorExtensions { /// /// Allocates a of size . @@ -13,67 +13,67 @@ namespace SixLabors.ImageSharp.Memory /// returning, so it may contain data from an earlier use. /// /// Type of the data stored in the buffer - /// The + /// The /// Size of the buffer to allocate /// A buffer of values of type . - public static IBuffer Allocate(this MemoryManager memoryManager, int length) + public static IBuffer Allocate(this MemoryAllocator memoryAllocator, int length) where T : struct { - return memoryManager.Allocate(length, false); + return memoryAllocator.Allocate(length, false); } - public static IBuffer AllocateClean(this MemoryManager memoryManager, int length) + public static IBuffer AllocateClean(this MemoryAllocator memoryAllocator, int length) where T : struct { - return memoryManager.Allocate(length, true); + return memoryAllocator.Allocate(length, true); } - public static IManagedByteBuffer AllocateManagedByteBuffer(this MemoryManager memoryManager, int length) + public static IManagedByteBuffer AllocateManagedByteBuffer(this MemoryAllocator memoryAllocator, int length) { - return memoryManager.AllocateManagedByteBuffer(length, false); + return memoryAllocator.AllocateManagedByteBuffer(length, false); } - public static IManagedByteBuffer AllocateCleanManagedByteBuffer(this MemoryManager memoryManager, int length) + public static IManagedByteBuffer AllocateCleanManagedByteBuffer(this MemoryAllocator memoryAllocator, int length) { - return memoryManager.AllocateManagedByteBuffer(length, true); + return memoryAllocator.AllocateManagedByteBuffer(length, true); } - public static Buffer2D Allocate2D(this MemoryManager memoryManager, int width, int height, bool clear) + public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, int width, int height, bool clear) where T : struct { - IBuffer buffer = memoryManager.Allocate(width * height, clear); + IBuffer buffer = memoryAllocator.Allocate(width * height, clear); return new Buffer2D(buffer, width, height); } - public static Buffer2D Allocate2D(this MemoryManager memoryManager, Size size) + public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, Size size) where T : struct => - Allocate2D(memoryManager, size.Width, size.Height, false); + Allocate2D(memoryAllocator, size.Width, size.Height, false); - public static Buffer2D Allocate2D(this MemoryManager memoryManager, int width, int height) + public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, int width, int height) where T : struct => - Allocate2D(memoryManager, width, height, false); + Allocate2D(memoryAllocator, width, height, false); - public static Buffer2D AllocateClean2D(this MemoryManager memoryManager, int width, int height) + public static Buffer2D AllocateClean2D(this MemoryAllocator memoryAllocator, int width, int height) where T : struct => - Allocate2D(memoryManager, width, height, true); + Allocate2D(memoryAllocator, width, height, true); /// /// Allocates padded buffers for BMP encoder/decoder. (Replacing old PixelRow/PixelArea) /// - /// The + /// The /// Pixel count in the row /// The pixel size in bytes, eg. 3 for RGB /// The padding /// A public static IManagedByteBuffer AllocatePaddedPixelRowBuffer( - this MemoryManager memoryManager, + this MemoryAllocator memoryAllocator, int width, int pixelSizeInBytes, int paddingInBytes) { int length = (width * pixelSizeInBytes) + paddingInBytes; - return memoryManager.AllocateManagedByteBuffer(length); + return memoryAllocator.AllocateManagedByteBuffer(length); } } } \ No newline at end of file diff --git a/src/ImageSharp/Memory/SimpleGcMemoryManager.cs b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs similarity index 72% rename from src/ImageSharp/Memory/SimpleGcMemoryManager.cs rename to src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs index f4518bbb9..9ac82e3b5 100644 --- a/src/ImageSharp/Memory/SimpleGcMemoryManager.cs +++ b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs @@ -1,9 +1,9 @@ namespace SixLabors.ImageSharp.Memory { /// - /// Implements by newing up arrays by the GC on every allocation requests. + /// Implements by newing up arrays by the GC on every allocation requests. /// - public class SimpleGcMemoryManager : MemoryManager + public class SimpleGcMemoryAllocator : MemoryAllocator { /// internal override IBuffer Allocate(int length, bool clear) diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 6635a5a2a..2dd97991d 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -194,7 +194,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -233,7 +233,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -272,7 +272,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -311,7 +311,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -350,7 +350,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -389,7 +389,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -428,7 +428,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -467,7 +467,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -506,7 +506,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -545,7 +545,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -584,7 +584,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -623,7 +623,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -662,7 +662,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -701,7 +701,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -740,7 +740,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -779,7 +779,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -818,7 +818,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 485bc31ad..07888a756 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryAllocator memoryManager, Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); diff --git a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs index 666fb3891..75ec11084 100644 --- a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Blend 2 pixels together. /// - /// The + /// The /// The destination span. /// The background span. /// The source span. @@ -36,6 +36,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// A value between 0 and 1 indicating the weight of the second source vector. /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// - public abstract void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount); + public abstract void Blend(MemoryAllocator memoryAllocator, Span destination, Span background, Span source, Span amount); } } diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs index ebadd2850..badc9d886 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors int maxY = endY - 1; int maxX = endX - 1; - using (Buffer2D targetPixels = configuration.MemoryManager.Allocate2D(source.Width, source.Height)) + using (Buffer2D targetPixels = configuration.MemoryAllocator.Allocate2D(source.Width, source.Height)) { source.CopyTo(targetPixels); diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs index 8f96546ae..957f4c364 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors { ParallelOptions parallelOptions = configuration.ParallelOptions; - using (Buffer2D firstPassPixels = configuration.MemoryManager.Allocate2D(source.Size())) + using (Buffer2D firstPassPixels = configuration.MemoryAllocator.Allocate2D(source.Size())) { this.ApplyConvolution(firstPassPixels, source.PixelBuffer, source.Bounds(), this.KernelX, parallelOptions); this.ApplyConvolution(source.PixelBuffer, firstPassPixels, sourceRectangle, this.KernelY, parallelOptions); diff --git a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs index 8f7a1caab..3a4b0cad5 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors int maxY = endY - 1; int maxX = endX - 1; - using (Buffer2D targetPixels = configuration.MemoryManager.Allocate2D(source.Size())) + using (Buffer2D targetPixels = configuration.MemoryAllocator.Allocate2D(source.Size())) { source.CopyTo(targetPixels); diff --git a/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs index b71430e13..d25d63c19 100644 --- a/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing } /// - public MemoryManager MemoryManager => this.source.GetConfiguration().MemoryManager; + public MemoryAllocator MemoryAllocator => this.source.GetConfiguration().MemoryAllocator; /// public Image Apply() diff --git a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs index 9a6d93d1a..a930e9c76 100644 --- a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Processing.Effects.Processors int radius = this.BrushSize >> 1; int levels = this.Levels; - using (Buffer2D targetPixels = configuration.MemoryManager.Allocate2D(source.Size())) + using (Buffer2D targetPixels = configuration.MemoryAllocator.Allocate2D(source.Size())) { source.CopyTo(targetPixels); diff --git a/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs index f56777bed..e12668831 100644 --- a/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs +++ b/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs @@ -16,10 +16,10 @@ namespace SixLabors.ImageSharp.Processing where TPixel : struct, IPixel { /// - /// Gets a reference to the used to allocate buffers + /// Gets a reference to the used to allocate buffers /// for this context. /// - MemoryManager MemoryManager { get; } + MemoryAllocator MemoryAllocator { get; } /// /// Gets the image dimensions at the current point in the processing pipeline. diff --git a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs index 5b8772790..93074944a 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs @@ -66,8 +66,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors int width = maxX - minX; - using (IBuffer colors = source.MemoryManager.Allocate(width)) - using (IBuffer amount = source.MemoryManager.Allocate(width)) + using (IBuffer colors = source.MemoryAllocator.Allocate(width)) + using (IBuffer amount = source.MemoryAllocator.Allocate(width)) { // Be careful! Do not capture colorSpan & amountSpan in the lambda below! Span colorSpan = colors.GetSpan(); @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width); // This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one - blender.Blend(source.MemoryManager, destination, colors.GetSpan(), destination, amount.GetSpan()); + blender.Blend(source.MemoryAllocator, destination, colors.GetSpan(), destination, amount.GetSpan()); }); } } diff --git a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs index b5571ffd0..e2dc43653 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs @@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors } int width = maxX - minX; - using (IBuffer rowColors = source.MemoryManager.Allocate(width)) + using (IBuffer rowColors = source.MemoryAllocator.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! Span rowColorsSpan = rowColors.GetSpan(); @@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors configuration.ParallelOptions, y => { - using (IBuffer amounts = source.MemoryManager.Allocate(width)) + using (IBuffer amounts = source.MemoryAllocator.Allocate(width)) { Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(source.MemoryManager, destination, destination, rowColors.GetSpan(), amountsSpan); + this.blender.Blend(source.MemoryAllocator, destination, destination, rowColors.GetSpan(), amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs index 06bf668d4..613398840 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors } int width = maxX - minX; - using (IBuffer rowColors = source.MemoryManager.Allocate(width)) + using (IBuffer rowColors = source.MemoryAllocator.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! Span rowColorsSpan = rowColors.GetSpan(); @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors configuration.ParallelOptions, y => { - using (IBuffer amounts = source.MemoryManager.Allocate(width)) + using (IBuffer amounts = source.MemoryAllocator.Allocate(width)) { Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(source.MemoryManager, destination, destination, rowColors.GetSpan(), amountsSpan); + this.blender.Blend(source.MemoryAllocator, destination, destination, rowColors.GetSpan(), amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs index 7887b1b2e..a377f922d 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs @@ -141,17 +141,17 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers public override QuantizedFrame QuantizeFrame(ImageFrame image) { Guard.NotNull(image, nameof(image)); - MemoryManager memoryManager = image.MemoryManager; + MemoryAllocator memoryAllocator = image.MemoryAllocator; try { - this.vwt = memoryManager.AllocateClean(TableLength); - this.vmr = memoryManager.AllocateClean(TableLength); - this.vmg = memoryManager.AllocateClean(TableLength); - this.vmb = memoryManager.AllocateClean(TableLength); - this.vma = memoryManager.AllocateClean(TableLength); - this.m2 = memoryManager.AllocateClean(TableLength); - this.tag = memoryManager.AllocateClean(TableLength); + this.vwt = memoryAllocator.AllocateClean(TableLength); + this.vmr = memoryAllocator.AllocateClean(TableLength); + this.vmg = memoryAllocator.AllocateClean(TableLength); + this.vmb = memoryAllocator.AllocateClean(TableLength); + this.vma = memoryAllocator.AllocateClean(TableLength); + this.m2 = memoryAllocator.AllocateClean(TableLength); + this.tag = memoryAllocator.AllocateClean(TableLength); return base.QuantizeFrame(image); } @@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers } } - this.Get3DMoments(source.MemoryManager); + this.Get3DMoments(source.MemoryAllocator); this.BuildCube(); } @@ -464,7 +464,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// Converts the histogram into moments so that we can rapidly calculate the sums of the above quantities over any desired box. /// - private void Get3DMoments(MemoryManager memoryManager) + private void Get3DMoments(MemoryAllocator memoryAllocator) { Span vwtSpan = this.vwt.GetSpan(); Span vmrSpan = this.vmr.GetSpan(); @@ -473,19 +473,19 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers Span vmaSpan = this.vma.GetSpan(); Span m2Span = this.m2.GetSpan(); - using (IBuffer volume = memoryManager.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volumeR = memoryManager.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volumeG = memoryManager.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volumeB = memoryManager.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volumeA = memoryManager.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volume2 = memoryManager.Allocate(IndexCount * IndexAlphaCount)) - - using (IBuffer area = memoryManager.Allocate(IndexAlphaCount)) - using (IBuffer areaR = memoryManager.Allocate(IndexAlphaCount)) - using (IBuffer areaG = memoryManager.Allocate(IndexAlphaCount)) - using (IBuffer areaB = memoryManager.Allocate(IndexAlphaCount)) - using (IBuffer areaA = memoryManager.Allocate(IndexAlphaCount)) - using (IBuffer area2 = memoryManager.Allocate(IndexAlphaCount)) + using (IBuffer volume = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IBuffer volumeR = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IBuffer volumeG = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IBuffer volumeB = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IBuffer volumeA = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IBuffer volume2 = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + + using (IBuffer area = memoryAllocator.Allocate(IndexAlphaCount)) + using (IBuffer areaR = memoryAllocator.Allocate(IndexAlphaCount)) + using (IBuffer areaG = memoryAllocator.Allocate(IndexAlphaCount)) + using (IBuffer areaB = memoryAllocator.Allocate(IndexAlphaCount)) + using (IBuffer areaA = memoryAllocator.Allocate(IndexAlphaCount)) + using (IBuffer area2 = memoryAllocator.Allocate(IndexAlphaCount)) { Span volumeSpan = volume.GetSpan(); Span volumeRSpan = volumeR.GetSpan(); diff --git a/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs index 7c1a581b0..fe82417ce 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs @@ -111,10 +111,10 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors int xLength = (int)MathF.Ceiling((radius.X * 2) + 2); int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2); - MemoryManager memoryManager = configuration.MemoryManager; + MemoryAllocator memoryAllocator = configuration.MemoryAllocator; - using (Buffer2D yBuffer = memoryManager.Allocate2D(yLength, height)) - using (Buffer2D xBuffer = memoryManager.Allocate2D(xLength, height)) + using (Buffer2D yBuffer = memoryAllocator.Allocate2D(yLength, height)) + using (Buffer2D xBuffer = memoryAllocator.Allocate2D(xLength, height)) { Parallel.For( 0, diff --git a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs index cf5ebf418..54b07cb48 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors int height = source.Height; int halfHeight = (int)Math.Ceiling(source.Height * .5F); - using (Buffer2D targetPixels = configuration.MemoryManager.Allocate2D(source.Size())) + using (Buffer2D targetPixels = configuration.MemoryAllocator.Allocate2D(source.Size())) { Parallel.For( 0, @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors int height = source.Height; int halfWidth = (int)Math.Ceiling(width * .5F); - using (Buffer2D targetPixels = configuration.MemoryManager.Allocate2D(source.Size())) + using (Buffer2D targetPixels = configuration.MemoryAllocator.Allocate2D(source.Size())) { Parallel.For( 0, diff --git a/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs index a55613dec..36bc4b1fa 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs @@ -117,10 +117,10 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors int xLength = (int)MathF.Ceiling((radius.X * 2) + 2); int yLength = (int)MathF.Ceiling((radius.Y * 2) + 2); - MemoryManager memoryManager = configuration.MemoryManager; + MemoryAllocator memoryAllocator = configuration.MemoryAllocator; - using (Buffer2D yBuffer = memoryManager.Allocate2D(yLength, height)) - using (Buffer2D xBuffer = memoryManager.Allocate2D(xLength, height)) + using (Buffer2D yBuffer = memoryAllocator.Allocate2D(yLength, height)) + using (Buffer2D xBuffer = memoryAllocator.Allocate2D(xLength, height)) { Parallel.For( 0, diff --git a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs index fc8d94362..3f11127ca 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs @@ -143,12 +143,12 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// /// Computes the weights to apply at each pixel when resizing. /// - /// The to use for buffer allocations + /// The to use for buffer allocations /// The destination size /// The source size /// The // TODO: Made internal to simplify experimenting with weights data. Make it private when finished figuring out how to optimize all the stuff! - internal WeightsBuffer PrecomputeWeights(MemoryManager memoryManager, int destinationSize, int sourceSize) + internal WeightsBuffer PrecomputeWeights(MemoryAllocator memoryAllocator, int destinationSize, int sourceSize) { float ratio = (float)sourceSize / destinationSize; float scale = ratio; @@ -160,7 +160,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors IResampler sampler = this.Sampler; float radius = MathF.Ceiling(scale * sampler.Radius); - var result = new WeightsBuffer(memoryManager, sourceSize, destinationSize); + var result = new WeightsBuffer(memoryAllocator, sourceSize, destinationSize); for (int i = 0; i < destinationSize; i++) { @@ -226,14 +226,14 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors if (!(this.Sampler is NearestNeighborResampler)) { // Since all image frame dimensions have to be the same we can calculate this for all frames. - MemoryManager memoryManager = source.GetMemoryManager(); + MemoryAllocator memoryAllocator = source.GetMemoryAllocator(); this.horizontalWeights = this.PrecomputeWeights( - memoryManager, + memoryAllocator, this.ResizeRectangle.Width, sourceRectangle.Width); this.verticalWeights = this.PrecomputeWeights( - memoryManager, + memoryAllocator, this.ResizeRectangle.Height, sourceRectangle.Height); } @@ -295,7 +295,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. // TODO: Using a transposed variant of 'firstPassPixels' could eliminate the need for the WeightsWindow.ComputeWeightedColumnSum() method, and improve speed! - using (Buffer2D firstPassPixels = source.MemoryManager.Allocate2D(width, source.Height)) + using (Buffer2D firstPassPixels = source.MemoryAllocator.Allocate2D(width, source.Height)) { firstPassPixels.Buffer.Clear(); diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs index 42c95cd33..d025644f5 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs @@ -16,12 +16,12 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// /// Initializes a new instance of the class. /// - /// The MemoryManager to use for allocations. + /// The to use for allocations. /// The size of the source window /// The size of the destination window - public WeightsBuffer(MemoryManager memoryManager, int sourceSize, int destinationSize) + public WeightsBuffer(MemoryAllocator memoryAllocator, int sourceSize, int destinationSize) { - this.dataBuffer = memoryManager.Allocate2D(sourceSize, destinationSize, true); + this.dataBuffer = memoryAllocator.Allocate2D(sourceSize, destinationSize, true); this.Weights = new WeightsWindow[destinationSize]; } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs index 1d76d58a5..f91595df8 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs @@ -29,8 +29,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg this.stream2 = new MemoryStream(this.buffer); this.stream3 = new MemoryStream(this.buffer); this.stream4 = new MemoryStream(this.buffer); - this.reader1 = new DoubleBufferedStreamReader(Configuration.Default.MemoryManager, this.stream2); - this.reader2 = new DoubleBufferedStreamReader(Configuration.Default.MemoryManager, this.stream2); + this.reader1 = new DoubleBufferedStreamReader(Configuration.Default.MemoryAllocator, this.stream2); + this.reader2 = new DoubleBufferedStreamReader(Configuration.Default.MemoryAllocator, this.stream2); } [GlobalCleanup] diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs index ef0d55765..087c033dd 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg } // no need to dispose when buffer is not array owner - buffers[i] = Configuration.Default.MemoryManager.Allocate2D(values.Length, 1); + buffers[i] = Configuration.Default.MemoryAllocator.Allocate2D(values.Length, 1); } return buffers; diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs index 329fcbe67..6874ff54a 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs @@ -23,8 +23,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [GlobalSetup] public void Setup() { - this.destination = Configuration.Default.MemoryManager.Allocate(this.Count); - this.source = Configuration.Default.MemoryManager.Allocate(this.Count); + this.destination = Configuration.Default.MemoryAllocator.Allocate(this.Count); + this.source = Configuration.Default.MemoryAllocator.Allocate(this.Count); } [GlobalCleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 31583bfe2..ca61983ce 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -21,8 +21,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [GlobalSetup] public void Setup() { - this.destination = Configuration.Default.MemoryManager.Allocate(this.Count); - this.source = Configuration.Default.MemoryManager.Allocate(this.Count * 4); + this.destination = Configuration.Default.MemoryAllocator.Allocate(this.Count); + this.source = Configuration.Default.MemoryAllocator.Allocate(this.Count * 4); } [GlobalCleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index e44847274..007306c6e 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -22,8 +22,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [GlobalSetup] public void Setup() { - this.source = Configuration.Default.MemoryManager.Allocate(this.Count); - this.destination = Configuration.Default.MemoryManager.Allocate(this.Count); + this.source = Configuration.Default.MemoryAllocator.Allocate(this.Count); + this.destination = Configuration.Default.MemoryAllocator.Allocate(this.Count); } [GlobalCleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index 030d7ad76..6e17d0276 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -22,8 +22,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [GlobalSetup] public void Setup() { - this.source = Configuration.Default.MemoryManager.Allocate(this.Count); - this.destination = Configuration.Default.MemoryManager.Allocate(this.Count * 3); + this.source = Configuration.Default.MemoryAllocator.Allocate(this.Count); + this.destination = Configuration.Default.MemoryAllocator.Allocate(this.Count * 3); } [GlobalCleanup] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index 4f58d1503..a0d7df72f 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [GlobalSetup] public void Setup() { - this.source = Configuration.Default.MemoryManager.Allocate(this.Count); - this.destination = Configuration.Default.MemoryManager.Allocate(this.Count * 4); + this.source = Configuration.Default.MemoryAllocator.Allocate(this.Count); + this.destination = Configuration.Default.MemoryAllocator.Allocate(this.Count * 4); } [GlobalCleanup] diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index c088e8eed..b194e9a6a 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/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 (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3)) + using (IBuffer buffer = Configuration.Default.MemoryAllocator.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - using (IBuffer amounts = Configuration.Default.MemoryManager.Allocate(image.Width)) + using (IBuffer amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) { amounts.Span.Fill(1); @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - using (IBuffer amounts = Configuration.Default.MemoryManager.Allocate(image.Width)) + using (IBuffer amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) { amounts.Span.Fill(1); using (PixelAccessor pixels = image.Lock()) diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 51b136649..5069336c4 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Benchmarks } int width = maxX - minX; - using (IBuffer rowColors = Configuration.Default.MemoryManager.Allocate(width)) + using (IBuffer rowColors = Configuration.Default.MemoryAllocator.Allocate(width)) using (PixelAccessor sourcePixels = source.Lock()) { rowColors.Span.Fill(glowColor); diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 3fe1380e4..6de84641c 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced } } - class TestMemoryManager : System.Buffers.MemoryManager + class TestMemoryManager : MemoryManager { public TestMemoryManager(TPixel[] pixelArray) { diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index cc2143afe..a553d4fc2 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests public List Applied { get; } = new List(); - public MemoryManager MemoryManager => this.Source.GetConfiguration().MemoryManager; + public MemoryAllocator MemoryAllocator => this.Source.GetConfiguration().MemoryAllocator; public Image Apply() { diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 0187b7e29..77807b66f 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests public void QuantizeImageShouldPreserveMaximumColorPrecision(TestImageProvider provider, string quantizerName) where TPixel : struct, IPixel { - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); IQuantizer quantizer = GetQuantizer(quantizerName); @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests image.DebugSave(provider, new PngEncoder() { PngColorType = PngColorType.Palette }, testOutputDetails: quantizerName); } - provider.Configuration.MemoryManager.ReleaseRetainedResources(); + provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); //string path = TestEnvironment.CreateOutputDirectory("Quantize"); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs index aa7d101c0..c720fdd4a 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { Block8x8F block = CreateRandomFloatBlock(0, 100); - using (var buffer = Configuration.Default.MemoryManager.Allocate2D(20, 20)) + using (var buffer = Configuration.Default.MemoryAllocator.Allocate2D(20, 20)) { BufferArea area = buffer.GetArea(5, 10, 8, 8); block.CopyTo(area); @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg var start = new Point(50, 50); - using (var buffer = Configuration.Default.MemoryManager.Allocate2D(100, 100)) + using (var buffer = Configuration.Default.MemoryAllocator.Allocate2D(100, 100)) { BufferArea area = buffer.GetArea(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor); block.CopyTo(area, horizontalFactor, verticalFactor); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs index be71e554f..7fe1dd577 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { public class DoubleBufferedStreamReaderTests { - private readonly MemoryManager manager = Configuration.Default.MemoryManager; + private readonly MemoryAllocator allocator = Configuration.Default.MemoryAllocator; [Fact] public void DoubleBufferedStreamReaderCanReadSingleByteFromOrigin() @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using (MemoryStream stream = this.CreateTestStream()) { byte[] expected = stream.ToArray(); - var reader = new DoubleBufferedStreamReader(this.manager, stream); + var reader = new DoubleBufferedStreamReader(this.allocator, stream); Assert.Equal(expected[0], reader.ReadByte()); @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using (MemoryStream stream = this.CreateTestStream()) { byte[] expected = stream.ToArray(); - var reader = new DoubleBufferedStreamReader(this.manager, stream); + var reader = new DoubleBufferedStreamReader(this.allocator, stream); for (int i = 0; i < expected.Length; i++) { @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { byte[] buffer = new byte[2]; byte[] expected = stream.ToArray(); - var reader = new DoubleBufferedStreamReader(this.manager, stream); + var reader = new DoubleBufferedStreamReader(this.allocator, stream); Assert.Equal(2, reader.Read(buffer, 0, 2)); Assert.Equal(expected[0], buffer[0]); @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { byte[] buffer = new byte[2]; byte[] expected = stream.ToArray(); - var reader = new DoubleBufferedStreamReader(this.manager, stream); + var reader = new DoubleBufferedStreamReader(this.allocator, stream); for (int i = 0, o = 0; i < expected.Length / 2; i++, o += 2) { @@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using (MemoryStream stream = this.CreateTestStream()) { byte[] expected = stream.ToArray(); - var reader = new DoubleBufferedStreamReader(this.manager, stream); + var reader = new DoubleBufferedStreamReader(this.allocator, stream); int skip = 50; int plusOne = 1; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs index f178c29c0..374b53ab2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); using (Image image = provider.GetImage(GolangJpegDecoder)) { @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg appendPixelTypeToFileName: false); } - provider.Configuration.MemoryManager.ReleaseRetainedResources(); + provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); } [Theory] diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs index c988f8f05..0ffe577fa 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); using (Image image = provider.GetImage(GolangJpegDecoder)) { @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg appendPixelTypeToFileName: false); } - provider.Configuration.MemoryManager.ReleaseRetainedResources(); + provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); } [Theory] diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 3667790a2..3421a06c7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); IImageDecoder decoder = useOldDecoder ? (IImageDecoder)GolangJpegDecoder : PdfJsJpegDecoder; using (Image image = provider.GetImage(decoder)) @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance), provider, appendPixelTypeToFileName: false); } - provider.Configuration.MemoryManager.ReleaseRetainedResources(); + provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); } private string GetDifferenceInPercentageString(Image image, TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs index 45ee64cb4..843843f79 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { string imageFile = provider.SourceFileOrDescription; using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) - using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryManager, decoder)) + using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryAllocator, decoder)) using (var imageFrame = new ImageFrame(Configuration.Default, decoder.ImageWidth, decoder.ImageHeight)) { pp.DoPostProcessorStep(imageFrame); @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { string imageFile = provider.SourceFileOrDescription; using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) - using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryManager, decoder)) + using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryAllocator, decoder)) using (var image = new Image(decoder.ImageWidth, decoder.ImageHeight)) { pp.PostProcess(image.Frames.RootFrame); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 90cc45e4a..2d56a89c6 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils this.HeightInBlocks = heightInBlocks; this.WidthInBlocks = widthInBlocks; this.Index = index; - this.SpectralBlocks = Configuration.Default.MemoryManager.Allocate2D(this.WidthInBlocks, this.HeightInBlocks); + this.SpectralBlocks = Configuration.Default.MemoryAllocator.Allocate2D(this.WidthInBlocks, this.HeightInBlocks); } public Size Size => new Size(this.WidthInBlocks, this.HeightInBlocks); diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index b84a78a55..e13101be4 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private const int PoolSelectorThresholdInBytes = MaxPooledBufferSizeInBytes / 2; - private MemoryManager MemoryManager { get; set; } = new ArrayPoolMemoryManager(MaxPooledBufferSizeInBytes, PoolSelectorThresholdInBytes); + private MemoryAllocator MemoryAllocator { get; set; } = new ArrayPoolMemoryAllocator(MaxPooledBufferSizeInBytes, PoolSelectorThresholdInBytes); /// /// Rent a buffer -> return it -> re-rent -> verify if it's span points to the previous location @@ -30,11 +30,11 @@ namespace SixLabors.ImageSharp.Tests.Memory private bool CheckIsRentingPooledBuffer(int length) where T : struct { - IBuffer buffer = this.MemoryManager.Allocate(length); + IBuffer buffer = this.MemoryAllocator.Allocate(length); ref T ptrToPrevPosition0 = ref buffer.GetReference(); buffer.Dispose(); - buffer = this.MemoryManager.Allocate(length); + buffer = this.MemoryAllocator.Allocate(length); bool sameBuffers = Unsafe.AreSame(ref ptrToPrevPosition0, ref buffer.GetReference()); buffer.Dispose(); @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Memory public class BufferTests : BufferTestSuite { public BufferTests() - : base(new ArrayPoolMemoryManager(MaxPooledBufferSizeInBytes, PoolSelectorThresholdInBytes)) + : base(new ArrayPoolMemoryAllocator(MaxPooledBufferSizeInBytes, PoolSelectorThresholdInBytes)) { } } @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void WhenBothParametersPassedByUser() { - var mgr = new ArrayPoolMemoryManager(1111, 666); + var mgr = new ArrayPoolMemoryAllocator(1111, 666); Assert.Equal(1111, mgr.MaxPoolSizeInBytes); Assert.Equal(666, mgr.PoolSelectorThresholdInBytes); } @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void WhenPassedOnly_MaxPooledBufferSizeInBytes_SmallerThresholdValueIsAutoCalculated() { - var mgr = new ArrayPoolMemoryManager(5000); + var mgr = new ArrayPoolMemoryAllocator(5000); Assert.Equal(5000, mgr.MaxPoolSizeInBytes); Assert.True(mgr.PoolSelectorThresholdInBytes < mgr.MaxPoolSizeInBytes); } @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void When_PoolSelectorThresholdInBytes_IsGreaterThan_MaxPooledBufferSizeInBytes_ExceptionIsThrown() { - Assert.ThrowsAny(() => { new ArrayPoolMemoryManager(100, 200); }); + Assert.ThrowsAny(() => { new ArrayPoolMemoryAllocator(100, 200); }); } } @@ -130,12 +130,12 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(true)] public void CleaningRequests_AreControlledByAllocationParameter_Clean(bool clean) { - using (IBuffer firstAlloc = this.MemoryManager.Allocate(42)) + using (IBuffer firstAlloc = this.MemoryAllocator.Allocate(42)) { firstAlloc.GetSpan().Fill(666); } - using (IBuffer secondAlloc = this.MemoryManager.Allocate(42, clean)) + using (IBuffer secondAlloc = this.MemoryAllocator.Allocate(42, clean)) { int expected = clean ? 0 : 666; Assert.Equal(expected, secondAlloc.GetSpan()[0]); @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(true)] public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive) { - IBuffer buffer = this.MemoryManager.Allocate(32); + IBuffer buffer = this.MemoryAllocator.Allocate(32); ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan()); if (!keepBufferAlive) @@ -155,9 +155,9 @@ namespace SixLabors.ImageSharp.Tests.Memory buffer.Dispose(); } - this.MemoryManager.ReleaseRetainedResources(); + this.MemoryAllocator.ReleaseRetainedResources(); - buffer = this.MemoryManager.Allocate(32); + buffer = this.MemoryAllocator.Allocate(32); Assert.False(Unsafe.AreSame(ref ptrToPrev0, ref buffer.GetReference())); } @@ -165,8 +165,8 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void ReleaseRetainedResources_DisposingPreviouslyAllocatedBuffer_IsAllowed() { - IBuffer buffer = this.MemoryManager.Allocate(32); - this.MemoryManager.ReleaseRetainedResources(); + IBuffer buffer = this.MemoryAllocator.Allocate(32); + this.MemoryAllocator.ReleaseRetainedResources(); buffer.Dispose(); } @@ -181,11 +181,11 @@ namespace SixLabors.ImageSharp.Tests.Memory int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int); - IBuffer small = this.MemoryManager.Allocate(arrayLengthThreshold - 1); + IBuffer small = this.MemoryAllocator.Allocate(arrayLengthThreshold - 1); ref int ptr2Small = ref small.GetReference(); small.Dispose(); - IBuffer large = this.MemoryManager.Allocate(arrayLengthThreshold + 1); + IBuffer large = this.MemoryAllocator.Allocate(arrayLengthThreshold + 1); Assert.False(Unsafe.AreSame(ref ptr2Small, ref large.GetReference())); } @@ -199,7 +199,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return; } - this.MemoryManager = ArrayPoolMemoryManager.CreateWithAggressivePooling(); + this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithAggressivePooling(); Assert.True(this.CheckIsRentingPooledBuffer(4096 * 4096)); } @@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return; } - this.MemoryManager = ArrayPoolMemoryManager.CreateDefault(); + this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault(); Assert.False(this.CheckIsRentingPooledBuffer(2 * 4096 * 4096)); Assert.True(this.CheckIsRentingPooledBuffer(2048 * 2048)); @@ -228,7 +228,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return; } - this.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); Assert.False(this.CheckIsRentingPooledBuffer(2048 * 2048)); Assert.True(this.CheckIsRentingPooledBuffer(1024 * 16)); diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index ca3837ad2..1495bbe44 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -27,9 +27,9 @@ namespace SixLabors.ImageSharp.Tests.Memory } } - private MemoryManager MemoryManager { get; } = new MockMemoryManager(); + private MemoryAllocator MemoryAllocator { get; } = new MockMemoryAllocator(); - private class MockMemoryManager : MemoryManager + private class MockMemoryAllocator : MemoryAllocator { internal override IBuffer Allocate(int length, bool clear) { @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(1025, 17)] public void Construct(int width, int height) { - using (Buffer2D buffer = this.MemoryManager.Allocate2D(width, height)) + using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(width, height)) { Assert.Equal(width, buffer.Width); Assert.Equal(height, buffer.Height); @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void CreateClean() { - using (Buffer2D buffer = this.MemoryManager.Allocate2D(42, 42, true)) + using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(42, 42, true)) { Span span = buffer.GetSpan(); for (int j = 0; j < span.Length; j++) @@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(17, 42, 41)] public void GetRowSpanY(int width, int height, int y) { - using (Buffer2D buffer = this.MemoryManager.Allocate2D(width, height)) + using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(width, height)) { Span span = buffer.GetRowSpan(y); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(17, 42, 0, 41)] public void GetRowSpanXY(int width, int height, int x, int y) { - using (Buffer2D buffer = this.MemoryManager.Allocate2D(width, height)) + using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(width, height)) { Span span = buffer.GetRowSpan(x, y); @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(99, 88, 98, 87)] public void Indexer(int width, int height, int x, int y) { - using (Buffer2D buffer = this.MemoryManager.Allocate2D(width, height)) + using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(width, height)) { Span span = buffer.Buffer.GetSpan(); @@ -132,8 +132,8 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void SwapContents() { - using (Buffer2D a = this.MemoryManager.Allocate2D(10, 5)) - using (Buffer2D b = this.MemoryManager.Allocate2D(3, 7)) + using (Buffer2D a = this.MemoryAllocator.Allocate2D(10, 5)) + using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) { IBuffer aa = a.Buffer; IBuffer bb = b.Buffer; diff --git a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs index bae3b4b61..2a87ed83b 100644 --- a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs +++ b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void Construct() { - using (var buffer = Configuration.Default.MemoryManager.Allocate2D(10, 20)) + using (var buffer = Configuration.Default.MemoryAllocator.Allocate2D(10, 20)) { var rectangle = new Rectangle(3,2, 5, 6); var area = new BufferArea(buffer, rectangle); @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private static Buffer2D CreateTestBuffer(int w, int h) { - var buffer = Configuration.Default.MemoryManager.Allocate2D(w, h); + var buffer = Configuration.Default.MemoryAllocator.Allocate2D(w, h); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index b19b1b03b..040e69c52 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -13,16 +13,16 @@ namespace SixLabors.ImageSharp.Tests.Memory using System.Buffers; /// - /// Inherit this class to test an implementation (provided by ). + /// Inherit this class to test an implementation (provided by ). /// public abstract class BufferTestSuite { - protected BufferTestSuite(MemoryManager memoryManager) + protected BufferTestSuite(MemoryAllocator memoryAllocator) { - this.MemoryManager = memoryManager; + this.MemoryAllocator = memoryAllocator; } - protected MemoryManager MemoryManager { get; } + protected MemoryAllocator MemoryAllocator { get; } public struct CustomStruct : IEquatable { @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private void TestHasCorrectLength(int desiredLength) where T : struct { - using (IBuffer buffer = this.MemoryManager.Allocate(desiredLength)) + using (IBuffer buffer = this.MemoryAllocator.Allocate(desiredLength)) { Assert.Equal(desiredLength, buffer.GetSpan().Length); } @@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { if (managedByteBuffer) { - if (!(this.MemoryManager.AllocateManagedByteBuffer(desiredLength, clean) is IBuffer buffer)) + if (!(this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength, clean) is IBuffer buffer)) { throw new InvalidOperationException("typeof(T) != typeof(byte)"); } @@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return buffer; } - return this.MemoryManager.Allocate(desiredLength, clean); + return this.MemoryAllocator.Allocate(desiredLength, clean); } private void TestCanAllocateCleanBuffer(int desiredLength, bool testManagedByteBuffer = false) @@ -273,7 +273,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(6666)] public void ManagedByteBuffer_ArrayIsCorrect(int desiredLength) { - using (IManagedByteBuffer buffer = this.MemoryManager.AllocateManagedByteBuffer(desiredLength)) + using (IManagedByteBuffer buffer = this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength)) { ref byte array0 = ref buffer.Array[0]; ref byte span0 = ref buffer.GetReference(); @@ -286,7 +286,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void GetMemory_ReturnsValidMemory() { - using (IBuffer buffer = this.MemoryManager.Allocate(42)) + using (IBuffer buffer = this.MemoryAllocator.Allocate(42)) { Span span0 = buffer.GetSpan(); span0[10].A = 30; @@ -303,7 +303,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public unsafe void GetMemory_ResultIsPinnable() { - using (IBuffer buffer = this.MemoryManager.Allocate(42)) + using (IBuffer buffer = this.MemoryAllocator.Allocate(42)) { Span span0 = buffer.GetSpan(); span0[10] = 30; diff --git a/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs index 0d1c2beb8..aedc53f66 100644 --- a/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Tests.Memory public class BufferTests : BufferTestSuite { public BufferTests() - : base(new SimpleGcMemoryManager()) + : base(new SimpleGcMemoryAllocator()) { } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index 10a34ec31..5b7deac01 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(0.6f, 0.6f, 0.6f, 1) }, }; - private MemoryManager MemoryManager { get; } = Configuration.Default.MemoryManager; + private MemoryAllocator MemoryAllocator { get; } = Configuration.Default.MemoryAllocator; [Theory] [MemberData(nameof(NormalBlendFunctionData))] @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Normal().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Normal().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Multiply().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Multiply().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Add().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Add().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Subtract().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Subtract().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -209,7 +209,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Screen().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Screen().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -248,7 +248,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Darken().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Darken().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -287,7 +287,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Lighten().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Lighten().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -326,7 +326,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Overlay().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Overlay().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.HardLight().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.HardLight().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index 97e4615c0..8eeddd406 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -56,8 +56,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats int times = 200000; int count = 1024; - using (IBuffer source = Configuration.Default.MemoryManager.Allocate(count)) - using (IBuffer dest = Configuration.Default.MemoryManager.Allocate(count)) + using (IBuffer source = Configuration.Default.MemoryAllocator.Allocate(count)) + using (IBuffer dest = Configuration.Default.MemoryAllocator.Allocate(count)) { this.Measure( times, @@ -441,7 +441,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { this.SourceBuffer = source; this.ExpectedDestBuffer = expectedDest; - this.ActualDestBuffer = Configuration.Default.MemoryManager.Allocate(expectedDest.Length); + this.ActualDestBuffer = Configuration.Default.MemoryAllocator.Allocate(expectedDest.Length); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index 1160e496c..ab19c21eb 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms var size = new Size(500, 500); var proc = new ResizeProcessor(KnownResamplers.Bicubic, 200, 200, size); - WeightsBuffer weights = proc.PrecomputeWeights(Configuration.Default.MemoryManager, proc.Width, size.Width); + WeightsBuffer weights = proc.PrecomputeWeights(Configuration.Default.MemoryAllocator, proc.Width, size.Width); var bld = new StringBuilder(); diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index ad0d43dcc..73ea6785f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var image = new Image(w, h); - using (IBuffer workBuffer = Configuration.Default.MemoryManager.Allocate(w)) + using (IBuffer workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) { fixed (Bgra32* destPtr = &workBuffer.GetReference()) { @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var image = new Image(w, h); - using (IBuffer workBuffer = Configuration.Default.MemoryManager.Allocate(w)) + using (IBuffer workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) { fixed (Bgr24* destPtr = &workBuffer.GetReference()) { @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs long destRowByteCount = data.Stride; long sourceRowByteCount = w * sizeof(Bgra32); - using (IBuffer workBuffer = image.GetConfiguration().MemoryManager.Allocate(w)) + using (IBuffer workBuffer = image.GetConfiguration().MemoryAllocator.Allocate(w)) { fixed (Bgra32* sourcePtr = &workBuffer.GetReference()) { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 3c5d5a7ba..fcf931935 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -27,11 +27,11 @@ namespace SixLabors.ImageSharp.Tests public static void MakeOpaque(this IImageProcessingContext ctx) where TPixel : struct, IPixel { - MemoryManager memoryManager = ctx.MemoryManager; + MemoryAllocator memoryAllocator = ctx.MemoryAllocator; ctx.Apply(img => { - using (Buffer2D temp = memoryManager.Allocate2D(img.Width, img.Height)) + using (Buffer2D temp = memoryAllocator.Allocate2D(img.Width, img.Height)) { Span tempSpan = temp.GetSpan(); foreach (ImageFrame frame in img.Frames) From 85d7548049f061bc83f84de4ec22a1987c89101d Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 03:05:55 +0200 Subject: [PATCH 12/17] rename namespace: SixLabors.ImageSharp.Memory -> SixLabors.Memory --- src/ImageSharp.Drawing/Primitives/ShapeRegion.cs | 2 +- .../Processing/Drawing/Brushes/BrushApplicator.cs | 2 +- .../Processing/Drawing/Brushes/ImageBrush{TPixel}.cs | 2 +- .../Drawing/Brushes/PatternBrush{TPixel}.cs | 2 +- .../Drawing/Brushes/RecolorBrush{TPixel}.cs | 2 +- .../Processing/Drawing/Brushes/SolidBrush{TPixel}.cs | 2 +- .../Drawing/Processors/DrawImageProcessor.cs | 2 +- .../Processing/Drawing/Processors/FillProcessor.cs | 2 +- .../Drawing/Processors/FillRegionProcessor.cs | 2 +- src/ImageSharp/Advanced/AdvancedImageExtensions.cs | 2 +- src/ImageSharp/Advanced/IPixelSource.cs | 2 +- src/ImageSharp/Common/Helpers/ParallelFor.cs | 2 +- src/ImageSharp/Configuration.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/LzwDecoder.cs | 2 +- src/ImageSharp/Formats/Gif/LzwEncoder.cs | 2 +- .../Formats/Jpeg/Components/Block8x8F.CopyTo.cs | 2 +- .../Decoder/ColorConverters/JpegColorConverter.cs | 2 +- .../Jpeg/Components/Decoder/IJpegComponent.cs | 2 +- .../Components/Decoder/JpegBlockPostProcessor.cs | 2 +- .../Components/Decoder/JpegComponentPostProcessor.cs | 2 +- .../Components/Decoder/JpegImagePostProcessor.cs | 4 +--- .../Formats/Jpeg/Components/GenericBlock8x8.cs | 3 +-- .../GolangPort/Components/Decoder/GolangComponent.cs | 2 +- .../Components/DoubleBufferedStreamReader.cs | 2 +- .../Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs | 2 +- .../Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs | 2 +- .../Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs | 2 +- .../Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 2 +- src/ImageSharp/Formats/Png/PngChunk.cs | 2 +- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 2 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 2 +- src/ImageSharp/Image.Decode.cs | 2 +- src/ImageSharp/Image.WrapMemory.cs | 2 +- src/ImageSharp/ImageFrameCollection.cs | 2 +- src/ImageSharp/ImageFrame{TPixel}.cs | 2 +- src/ImageSharp/Image{TPixel}.cs | 2 +- .../Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs | 2 +- .../ArrayPoolMemoryAllocator.CommonFactoryMethods.cs | 2 +- src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs | 4 ++-- src/ImageSharp/Memory/BasicArrayBuffer.cs | 4 ++-- src/ImageSharp/Memory/BasicByteBuffer.cs | 5 ++++- src/ImageSharp/Memory/Buffer2DExtensions.cs | 2 +- src/ImageSharp/Memory/Buffer2D{T}.cs | 6 +++--- src/ImageSharp/Memory/BufferArea{T}.cs | 12 ++++++------ src/ImageSharp/Memory/BufferExtensions.cs | 2 +- src/ImageSharp/Memory/ConsumedBuffer.cs | 2 +- src/ImageSharp/Memory/IBuffer2D{T}.cs | 2 +- src/ImageSharp/Memory/IBuffer{T}.cs | 2 +- src/ImageSharp/Memory/IManagedByteBuffer.cs | 2 +- src/ImageSharp/Memory/ManagedBufferBase.cs | 2 +- src/ImageSharp/Memory/MemoryAllocator.cs | 2 +- src/ImageSharp/Memory/MemoryAllocatorExtensions.cs | 2 +- src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs | 2 +- src/ImageSharp/PixelAccessor{TPixel}.cs | 2 +- .../PixelBlenders/DefaultPixelBlenders.Generated.cs | 2 +- src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs | 2 +- .../PixelFormats/Rgba32.PixelOperations.cs | 2 +- .../Convolution/Processors/Convolution2DProcessor.cs | 2 +- .../Processors/Convolution2PassProcessor.cs | 2 +- .../Convolution/Processors/ConvolutionProcessor.cs | 2 +- .../Convolution/Processors/SobelProcessor.cs | 1 - .../DefaultInternalImageProcessorContext.cs | 2 +- .../Effects/Processors/OilPaintingProcessor.cs | 2 +- .../Processing/IImageProcessingContext{TPixel}.cs | 2 +- .../Overlays/Processors/BackgroundColorProcessor.cs | 2 +- .../Processing/Overlays/Processors/GlowProcessor.cs | 2 +- .../Overlays/Processors/VignetteProcessor.cs | 2 +- .../FrameQuantizers/WuFrameQuantizer{TPixel}.cs | 2 +- .../Processors/AffineTransformProcessor.cs | 2 +- .../Transforms/Processors/CropProcessor.cs | 1 - .../Transforms/Processors/FlipProcessor.cs | 2 +- .../Processors/ProjectiveTransformProcessor.cs | 2 +- .../Transforms/Processors/ResizeProcessor.cs | 2 +- .../Transforms/Processors/WeightsBuffer.cs | 2 +- .../Transforms/Processors/WeightsWindow.cs | 2 +- tests/ImageSharp.Benchmarks/Codecs/CopyPixels.cs | 2 +- .../Codecs/Jpeg/YCbCrColorConversion.cs | 2 +- .../Color/Bulk/PackFromVector4.cs | 2 +- .../ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs | 2 +- tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs | 2 +- tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 2 +- tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs | 2 +- .../General/Vectorization/VectorFetching.cs | 2 +- .../PixelBlenders/PorterDuffBulkVsPixel.cs | 2 +- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 2 +- .../Drawing/FillRegionProcessorTests.cs | 2 +- .../ImageSharp.Tests/FakeImageOperationsProvider.cs | 2 +- tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs | 2 +- .../Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs | 2 +- .../Formats/Jpg/DoubleBufferedStreamReaderTests.cs | 2 +- .../Formats/Jpg/JpegColorConverterTests.cs | 2 +- .../Formats/Jpg/JpegDecoderTests.Baseline.cs | 2 +- .../Formats/Jpg/JpegDecoderTests.Progressive.cs | 2 +- .../ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs | 2 +- .../Formats/Jpg/Utils/LibJpegTools.ComponentData.cs | 2 +- .../Memory/ArrayPoolMemoryManagerTests.cs | 2 +- tests/ImageSharp.Tests/Memory/Buffer2DTests.cs | 2 +- tests/ImageSharp.Tests/Memory/BufferAreaTests.cs | 2 +- tests/ImageSharp.Tests/Memory/BufferTestSuite.cs | 2 +- .../Memory/SimpleGcMemoryManagerTests.cs | 2 +- .../ICC/DataWriter/IccDataWriter.MatrixTests.cs | 2 +- .../PixelBlenders/PorterDuffFunctionsTests_TPixel.cs | 2 +- .../PixelFormats/PixelOperationsTests.cs | 2 +- .../TestDataIcc/IccTestDataMatrix.cs | 2 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 2 +- .../TestUtilities/TestImageExtensions.cs | 2 +- 110 files changed, 120 insertions(+), 122 deletions(-) diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index cb4305248..9f5611dc0 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.Primitives; using SixLabors.Shapes; diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs index bd22759fc..7672681da 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs @@ -3,8 +3,8 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs index 30e48b54c..779848856 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs @@ -3,8 +3,8 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Brushes diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs index dccb05f87..21f2066fb 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs @@ -4,9 +4,9 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Brushes diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs index a2d5c296d..a7da2cc5b 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -4,8 +4,8 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Brushes diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs index c5ea5792f..791c307bf 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs @@ -3,8 +3,8 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Brushes diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs index 38805c517..506df3886 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs @@ -4,9 +4,9 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Processors diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs index 7a0b7a05d..4214041a7 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs @@ -4,10 +4,10 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Processors diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 916da360b..c81f4028b 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -3,11 +3,11 @@ using System; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Drawing.Processors diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 337f82e03..605c0bfb4 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -3,8 +3,8 @@ using System; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Advanced { diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs index a321e877b..27b3170e6 100644 --- a/src/ImageSharp/Advanced/IPixelSource.cs +++ b/src/ImageSharp/Advanced/IPixelSource.cs @@ -1,8 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Advanced { diff --git a/src/ImageSharp/Common/Helpers/ParallelFor.cs b/src/ImageSharp/Common/Helpers/ParallelFor.cs index fc22b42be..7061475a7 100644 --- a/src/ImageSharp/Common/Helpers/ParallelFor.cs +++ b/src/ImageSharp/Common/Helpers/ParallelFor.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index f30b5469f..e84674355 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -12,8 +12,8 @@ using SixLabors.ImageSharp.Formats.Png; #if !NETSTANDARD1_1 using SixLabors.ImageSharp.IO; #endif -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Processing; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index b6905a62f..3c6e05a8b 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -4,9 +4,9 @@ using System; using System.IO; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Bmp { diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index aff0c024d..d8bf90c7c 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -3,8 +3,8 @@ using System; using System.IO; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Bmp { diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index bba983af8..fc73f55a1 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -7,9 +7,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Gif diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 8de347086..f84b13f5f 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -7,10 +7,10 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Gif { diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index aaf0547b9..977870936 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Gif { diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index f3e75b6f6..de9de5e15 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Gif { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs index 43cc3e9db..4db6d7431 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs @@ -4,7 +4,7 @@ using System.Numerics; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Formats.Jpeg.Components diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs index 080bf8333..11b5c60d1 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Numerics; using SixLabors.ImageSharp.Common.Tuples; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs index efa746819..253b20c39 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs index b586d520a..2baefff9b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs @@ -3,7 +3,7 @@ using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs index edb34bc03..2b442fcdc 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs @@ -3,7 +3,7 @@ using System; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index 1a7f8bebb..99408cf57 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -4,12 +4,10 @@ using System; using System.Linq; using System.Numerics; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; using SixLabors.Primitives; - using JpegColorConverter = SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters.JpegColorConverter; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs index 9aceb78b2..825a7f5f0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs @@ -4,10 +4,9 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Formats.Jpeg.Components diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs index 2335800c2..75cea5551 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs @@ -6,7 +6,7 @@ using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs index ae1dbf75e..7aeee43c2 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; // TODO: This could be useful elsewhere. namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index 9a17b2dfa..eefe8b97e 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -7,7 +7,7 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs index 4a8f9debe..2789f0cc0 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs index 0a780dfe2..c9f1c555d 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs @@ -9,7 +9,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index 625c8f691..937439ed0 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -11,12 +11,12 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort diff --git a/src/ImageSharp/Formats/Png/PngChunk.cs b/src/ImageSharp/Formats/Png/PngChunk.cs index c91f39d7f..c75f9465a 100644 --- a/src/ImageSharp/Formats/Png/PngChunk.cs +++ b/src/ImageSharp/Formats/Png/PngChunk.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Png { diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index f481dc508..67e32f212 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -13,9 +13,9 @@ using System.Text; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Png { diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 1e6c186ec..7ec82c57c 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -8,9 +8,9 @@ using System.Linq; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Png { diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index bd602875a..443ae6a37 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -4,8 +4,8 @@ using System.IO; using System.Linq; using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs index 5abc4e132..3988120e6 100644 --- a/src/ImageSharp/Image.WrapMemory.cs +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index 181ffbce3..14a16b691 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -5,8 +5,8 @@ using System; using System.Collections; using System.Collections.Generic; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index c6471df14..64cf602b0 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -6,9 +6,9 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 2a95398e1..2d84d4552 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -8,9 +8,9 @@ using System.Linq; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs index 2216003e5..2b7497cbf 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs @@ -5,7 +5,7 @@ using System; using System.Buffers; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Contains and diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs index 0f115764b..78d6e27b2 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs @@ -1,6 +1,6 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Contains common factory methods and configuration constants. diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs index 8bc88a5cf..90950d4b3 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs @@ -4,7 +4,7 @@ using System.Buffers; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Implements by allocating memory from . @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Memory /// Max arrays per bucket for the normal array pool public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes, int maxArraysPerBucketLargePool, int maxArraysPerBucketNormalPool) { - Guard.MustBeGreaterThan(maxPoolSizeInBytes, 0, nameof(maxPoolSizeInBytes)); + ImageSharp.Guard.MustBeGreaterThan(maxPoolSizeInBytes, 0, nameof(maxPoolSizeInBytes)); Guard.MustBeLessThanOrEqualTo(poolSelectorThresholdInBytes, maxPoolSizeInBytes, nameof(poolSelectorThresholdInBytes)); this.MaxPoolSizeInBytes = maxPoolSizeInBytes; diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index 3b62f8a31..500a99069 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Wraps an array as an instance. In this implementation is owned. @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Memory { public BasicArrayBuffer(T[] array, int length) { - DebugGuard.MustBeLessThanOrEqualTo(length, array.Length, nameof(length)); + ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(length, array.Length, nameof(length)); this.Array = array; this.Length = length; } diff --git a/src/ImageSharp/Memory/BasicByteBuffer.cs b/src/ImageSharp/Memory/BasicByteBuffer.cs index 96b69ad3b..a8a30b1aa 100644 --- a/src/ImageSharp/Memory/BasicByteBuffer.cs +++ b/src/ImageSharp/Memory/BasicByteBuffer.cs @@ -1,4 +1,7 @@ -namespace SixLabors.ImageSharp.Memory +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.Memory { internal class BasicByteBuffer : BasicArrayBuffer, IManagedByteBuffer { diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index c236f250c..58e273123 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Defines extension methods for . diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index 7689ecdb2..bbfe2d1d3 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Represents a buffer of value type objects @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); + ImageSharp.DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); Span span = this.Buffer.GetSpan(); return ref span[(this.Width * y) + x]; @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Swap the contents (, , ) of the two buffers. - /// Useful to transfer the contents of a temporary to a persistent + /// Useful to transfer the contents of a temporary to a persistent /// /// The first buffer /// The second buffer diff --git a/src/ImageSharp/Memory/BufferArea{T}.cs b/src/ImageSharp/Memory/BufferArea{T}.cs index 315e57d1b..96036f6ee 100644 --- a/src/ImageSharp/Memory/BufferArea{T}.cs +++ b/src/ImageSharp/Memory/BufferArea{T}.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Represents a rectangular area inside a 2D memory buffer (). @@ -20,10 +20,10 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] public BufferArea(IBuffer2D destinationBuffer, Rectangle rectangle) { - DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle)); - DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle)); - DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, destinationBuffer.Width, nameof(rectangle)); - DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, destinationBuffer.Height, nameof(rectangle)); + ImageSharp.DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle)); + ImageSharp.DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle)); + ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, destinationBuffer.Width, nameof(rectangle)); + ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, destinationBuffer.Height, nameof(rectangle)); this.DestinationBuffer = destinationBuffer; this.Rectangle = rectangle; @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] public BufferArea GetSubArea(Rectangle rectangle) { - DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle)); + ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle)); DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, this.Rectangle.Height, nameof(rectangle)); int x = this.Rectangle.X + rectangle.X; diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index 3e7ebcdc8..8ebf866bc 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -6,7 +6,7 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { internal static class BufferExtensions { diff --git a/src/ImageSharp/Memory/ConsumedBuffer.cs b/src/ImageSharp/Memory/ConsumedBuffer.cs index 1f1bb76e4..b793b29c2 100644 --- a/src/ImageSharp/Memory/ConsumedBuffer.cs +++ b/src/ImageSharp/Memory/ConsumedBuffer.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// A buffer implementation that consumes an existing instance. diff --git a/src/ImageSharp/Memory/IBuffer2D{T}.cs b/src/ImageSharp/Memory/IBuffer2D{T}.cs index 0fc8867a6..a92f30dd5 100644 --- a/src/ImageSharp/Memory/IBuffer2D{T}.cs +++ b/src/ImageSharp/Memory/IBuffer2D{T}.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// An interface that represents a contigous buffer of value type objects diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index fdb70ad9c..4e0e0c702 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Represents a contigous memory buffer of value-type items. diff --git a/src/ImageSharp/Memory/IManagedByteBuffer.cs b/src/ImageSharp/Memory/IManagedByteBuffer.cs index 4d159ce86..a977eb68f 100644 --- a/src/ImageSharp/Memory/IManagedByteBuffer.cs +++ b/src/ImageSharp/Memory/IManagedByteBuffer.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Represents a byte buffer backed by a managed array. Useful for interop with classic .NET API-s. diff --git a/src/ImageSharp/Memory/ManagedBufferBase.cs b/src/ImageSharp/Memory/ManagedBufferBase.cs index 1291bcbb1..c1cc51274 100644 --- a/src/ImageSharp/Memory/ManagedBufferBase.cs +++ b/src/ImageSharp/Memory/ManagedBufferBase.cs @@ -4,7 +4,7 @@ using System.Buffers; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Provides a base class for implementations by implementing pinning logic for adaption. diff --git a/src/ImageSharp/Memory/MemoryAllocator.cs b/src/ImageSharp/Memory/MemoryAllocator.cs index c62128fd2..2195444fd 100644 --- a/src/ImageSharp/Memory/MemoryAllocator.cs +++ b/src/ImageSharp/Memory/MemoryAllocator.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Memory managers are used to allocate memory for image processing operations. diff --git a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs index 1a92b7567..ab4fc93b7 100644 --- a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs +++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs @@ -1,6 +1,6 @@ using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Extension methods for . diff --git a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs index 9ac82e3b5..2d339f4c7 100644 --- a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs +++ b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs @@ -1,4 +1,4 @@ -namespace SixLabors.ImageSharp.Memory +namespace SixLabors.Memory { /// /// Implements by newing up arrays by the GC on every allocation requests. diff --git a/src/ImageSharp/PixelAccessor{TPixel}.cs b/src/ImageSharp/PixelAccessor{TPixel}.cs index bcc758e9e..7ca066ff1 100644 --- a/src/ImageSharp/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/PixelAccessor{TPixel}.cs @@ -5,8 +5,8 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 2dd97991d..6828f11dc 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; /// diff --git a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs index 75ec11084..b8b97ea0a 100644 --- a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.PixelFormats { diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs index b1eba3275..ca4231906 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs @@ -5,7 +5,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.PixelFormats { diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs index badc9d886..5636f167c 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs @@ -5,10 +5,10 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Convolution.Processors diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs index 957f4c364..a080beb88 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs @@ -4,10 +4,10 @@ using System; using System.Numerics; using System.Threading.Tasks; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Convolution.Processors diff --git a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs index 3a4b0cad5..918b67caf 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs @@ -5,10 +5,10 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Convolution.Processors diff --git a/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs index bf97c67d7..9fb9c56c4 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.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; namespace SixLabors.ImageSharp.Processing.Convolution.Processors diff --git a/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs index d25d63c19..a392b8d8e 100644 --- a/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs index a930e9c76..15dd000b4 100644 --- a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs @@ -5,9 +5,9 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Effects.Processors diff --git a/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs index e12668831..4897cc58b 100644 --- a/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs +++ b/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs @@ -1,9 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing diff --git a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs index 93074944a..cc7e2ad8b 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs @@ -4,9 +4,9 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Overlays.Processors diff --git a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs index e2dc43653..51634ea2c 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs @@ -5,10 +5,10 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Overlays.Processors diff --git a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs index 613398840..b73fab179 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs @@ -5,10 +5,10 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Overlays.Processors diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs index a377f922d..4887519e3 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs @@ -7,8 +7,8 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { diff --git a/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs index fe82417ce..2e1a88983 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs @@ -9,9 +9,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Transforms.Processors diff --git a/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs index 848ea7b62..2228c69fa 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; diff --git a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs index 54b07cb48..e2ec556fc 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs @@ -4,9 +4,9 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Transforms.Processors diff --git a/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs index 36bc4b1fa..24a72fefb 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs @@ -9,9 +9,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.Memory; using SixLabors.Primitives; // TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior diff --git a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs index 3f11127ca..dfb3a82ff 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs @@ -9,9 +9,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Transforms.Processors diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs index d025644f5..8c479992e 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Transforms.Processors { diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs index 0eac88fd3..440b19ecc 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs @@ -5,7 +5,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Processing.Transforms.Processors { diff --git a/tests/ImageSharp.Benchmarks/Codecs/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Codecs/CopyPixels.cs index ed849d76f..610c356b7 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/CopyPixels.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Advanced; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; public class CopyPixels : BenchmarkBase { diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs index 087c033dd..5a8a62373 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; [Config(typeof(Config.ShortClr))] public class YCbCrColorConversion diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs index 6874ff54a..ac396d42e 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; [Config(typeof(Config.ShortClr))] diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index ca61983ce..c4c09f67c 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; public abstract class PackFromXyzw diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index 007306c6e..375518950 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; public abstract class ToVector4 diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index 6e17d0276..6c5f762b3 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; public abstract class ToXyz diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index a0d7df72f..f073072b8 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk { using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; public abstract class ToXyzw diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs index aa7d926a4..017f58ef7 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; /// /// This benchmark compares different methods for fetching memory data into diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index b194e9a6a..cf26789b5 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Benchmarks using CoreSize = SixLabors.Primitives.Size; using System.Numerics; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats.PixelBlenders; public class PorterDuffBulkVsPixel : BenchmarkBase diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 5069336c4..c4c17f0f1 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Benchmarks using System; using System.Threading.Tasks; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.Primitives; using SixLabors.ImageSharp.Processing.Overlays.Processors; using SixLabors.ImageSharp.Processing.Processors; diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 017fee856..c664bcf9c 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -5,7 +5,7 @@ using System.Numerics; using Moq; using System; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index a553d4fc2..ff4014e61 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 77807b66f..084b93b39 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests using System; using System.Reflection; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Quantization; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs index c720fdd4a..88be54dd0 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs @@ -5,7 +5,7 @@ //#define BENCHMARKING using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs index 7fe1dd577..20b199441 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Jpg diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index c97d62553..aed650b8e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -8,7 +8,7 @@ using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using Xunit; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs index 374b53ab2..e266554d1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs index 0ffe577fa..c793b4034 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Linq; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 3421a06c7..6b3ef1dee 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -10,7 +10,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 2d56a89c6..645ee4512 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.Primitives; internal static partial class LibJpegTools diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index e13101be4..c8e304b41 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Memory using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using Xunit; diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 1495bbe44..f22e558f3 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Tests.Memory using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.ImageSharp.Tests.Common; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs index 2a87ed83b..bbf350514 100644 --- a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs +++ b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs @@ -3,7 +3,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using System; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index 040e69c52..b7e5cfb32 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using Xunit; // ReSharper disable InconsistentNaming diff --git a/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs index aedc53f66..d04336690 100644 --- a/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs @@ -1,6 +1,6 @@ namespace SixLabors.ImageSharp.Tests.Memory { - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; public class SimpleGcMemoryManagerTests { diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs index f01a5ef96..71dd18621 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.MetaData.Profiles.Icc; using Xunit; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index 5b7deac01..1273a453e 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -12,7 +12,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; public class PorterDuffFunctionsTests_TPixel { diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index 8eeddd406..caab05279 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -4,7 +4,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs index 02bda3a0b..1fb745c38 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; namespace SixLabors.ImageSharp.Tests { diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index 73ea6785f..1dfb3ba46 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -5,7 +5,7 @@ using System; using System.Drawing.Imaging; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index fcf931935..e135c5d31 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -8,7 +8,7 @@ using System.Numerics; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Memory; +using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; From 71b826d010acf0f9d8372ddc3425deaeb74f8eac Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 03:46:40 +0200 Subject: [PATCH 13/17] mark DangerousGetPinnableReferenceToPixelBuffer() obsolete --- src/ImageSharp/Advanced/AdvancedImageExtensions.cs | 2 ++ tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 605c0bfb4..1a435733f 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -127,6 +127,7 @@ namespace SixLabors.ImageSharp.Advanced /// The Pixel format. /// The source image frame /// A pinnable reference the first root of the pixel buffer. + [Obsolete("This method will be removed in our next release! Please use MemoryMarshal.GetReference(source.GetPixelSpan())!")] public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this ImageFrame source) where TPixel : struct, IPixel => ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource)source); @@ -139,6 +140,7 @@ namespace SixLabors.ImageSharp.Advanced /// The Pixel format. /// The source image /// A pinnable reference the first root of the pixel buffer. + [Obsolete("This method will be removed in our next release! Please use MemoryMarshal.GetReference(source.GetPixelSpan())!")] public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this Image source) where TPixel : struct, IPixel => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 6de84641c..1b473ab5f 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -151,6 +151,8 @@ namespace SixLabors.ImageSharp.Tests.Advanced } } + #pragma warning disable 0618 + [Theory] [WithTestPatternImages(131, 127, PixelTypes.Rgba32 | PixelTypes.Bgr24)] public unsafe void DangerousGetPinnableReference_CopyToBuffer(TestImageProvider provider) From b909f97a08496973e2245c9c66e41c0926833adc Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 10 Jun 2018 03:52:23 +0200 Subject: [PATCH 14/17] fix Benchmarks project --- tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs | 8 ++++---- tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 8 ++++---- tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs | 8 ++++---- .../PixelBlenders/PorterDuffBulkVsPixel.cs | 8 ++++---- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index 375518950..3b988757d 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - Span s = this.source.Span; - Span d = this.destination.Span; + Span s = this.source.GetSpan(); + Span d = this.destination.GetSpan(); for (int i = 0; i < this.Count; i++) { @@ -49,13 +49,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().ToVector4(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().ToVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.ToVector4(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.ToVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index 6c5f762b3..16743eb73 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - Span s = this.source.Span; - Span d = this.destination.Span; + Span s = this.source.GetSpan(); + Span d = this.destination.GetSpan(); var rgb = default(Rgb24); @@ -55,13 +55,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().ToRgb24Bytes(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().ToRgb24Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.ToRgb24Bytes(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.ToRgb24Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index f073072b8..f947b6e8d 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -38,8 +38,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - Span s = this.source.Span; - Span d = this.destination.Span; + Span s = this.source.GetSpan(); + Span d = this.destination.GetSpan(); var rgba = default(Rgba32); @@ -58,13 +58,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().ToRgba32Bytes(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().ToRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.ToRgba32Bytes(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.ToRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index cf26789b5..fe0678aca 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs @@ -61,14 +61,14 @@ namespace SixLabors.ImageSharp.Benchmarks { using (IBuffer amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) { - amounts.Span.Fill(1); + amounts.GetSpan().Fill(1); using (PixelAccessor pixels = image.Lock()) { for (int y = 0; y < image.Height; y++) { Span span = pixels.GetRowSpan(y); - this.BulkVectorConvert(span, span, span, amounts.Span); + this.BulkVectorConvert(span, span, span, amounts.GetSpan()); } } return new CoreSize(image.Width, image.Height); @@ -83,13 +83,13 @@ namespace SixLabors.ImageSharp.Benchmarks { using (IBuffer amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) { - amounts.Span.Fill(1); + amounts.GetSpan().Fill(1); using (PixelAccessor pixels = image.Lock()) { for (int y = 0; y < image.Height; y++) { Span span = pixels.GetRowSpan(y); - this.BulkPixelConvert(span, span, span, amounts.Span); + this.BulkPixelConvert(span, span, span, amounts.GetSpan()); } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index c4c17f0f1..b2fa47893 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Benchmarks using (IBuffer rowColors = Configuration.Default.MemoryAllocator.Allocate(width)) using (PixelAccessor sourcePixels = source.Lock()) { - rowColors.Span.Fill(glowColor); + rowColors.GetSpan().Fill(glowColor); Parallel.For( minY, From f6dd91922e01cab29ae9cfefc4352bf4bf8eeb43 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 11 Jun 2018 01:09:10 +0200 Subject: [PATCH 15/17] IBuffer.IsMemoryOwner, Buffer2D.SwapOrCopyContent() --- .../ArrayPoolMemoryAllocator.Buffer{T}.cs | 2 +- src/ImageSharp/Memory/BasicArrayBuffer.cs | 2 +- src/ImageSharp/Memory/Buffer2D{T}.cs | 27 +- src/ImageSharp/Memory/ConsumedBuffer.cs | 2 + src/ImageSharp/Memory/IBuffer{T}.cs | 8 + src/ImageSharp/Memory/ManagedBufferBase.cs | 5 +- .../Processors/Convolution2DProcessor.cs | 2 +- .../Processors/ConvolutionProcessor.cs | 2 +- .../Processors/OilPaintingProcessor.cs | 2 +- .../Transforms/Processors/FlipProcessor.cs | 4 +- .../Advanced/AdvancedImageExtensionsTests.cs | 32 +- .../ImageSharp.Tests/Image/ImageLoadTests.cs | 337 ----------------- .../Image/ImageTests.Load_BasicCases.cs | 63 ++++ .../Image/ImageTests.Load_ComplexCases.cs | 338 ++++++++++++++++++ .../ImageSharp.Tests/Image/ImageTests.Save.cs | 70 ++++ .../Image/ImageTests.WrapMemory.cs | 24 ++ tests/ImageSharp.Tests/Image/ImageTests.cs | 102 +----- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 95 ++++- .../Memory/BufferTestSuite.cs | 9 + .../Processors/Convolution/DetectEdgesTest.cs | 18 + .../Processors/Transforms/FlipTests.cs | 21 +- .../TestUtilities/TestMemoryManager.cs | 50 +++ .../TestUtilities/TestUtils.cs | 38 ++ 23 files changed, 761 insertions(+), 492 deletions(-) delete mode 100644 tests/ImageSharp.Tests/Image/ImageLoadTests.cs create mode 100644 tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs create mode 100644 tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs create mode 100644 tests/ImageSharp.Tests/Image/ImageTests.Save.cs create mode 100644 tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs create mode 100644 tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs index 2b7497cbf..d0f68c9c6 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs @@ -16,7 +16,7 @@ namespace SixLabors.Memory /// The buffer implementation of . /// In this implementation is owned. /// - private class Buffer : ManagedBufferBase, IBuffer + private class Buffer : ManagedBufferBase where T : struct { /// diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index 500a99069..5e3893d08 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -9,7 +9,7 @@ namespace SixLabors.Memory /// /// Wraps an array as an instance. In this implementation is owned. /// - internal class BasicArrayBuffer : ManagedBufferBase, IBuffer + internal class BasicArrayBuffer : ManagedBufferBase where T : struct { public BasicArrayBuffer(T[] array, int length) diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index bbfe2d1d3..b62156ffb 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -39,6 +39,10 @@ namespace SixLabors.Memory /// public IBuffer Buffer { get; private set; } + public Memory Memory => this.Buffer.Memory; + + public Span Span => this.Buffer.GetSpan(); + /// /// Gets a reference to the element at the specified position. /// @@ -65,13 +69,34 @@ namespace SixLabors.Memory this.Buffer?.Dispose(); } + /// + /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), + /// copies the contents of 'source' to 'destination' otherwise (2). Buffers should be of same size in case 2! + /// + public static void SwapOrCopyContent(Buffer2D destination, Buffer2D source) + { + if (source.Buffer.IsMemoryOwner && destination.Buffer.IsMemoryOwner) + { + SwapContents(destination, source); + } + else + { + if (destination.Size() != source.Size()) + { + throw new InvalidOperationException("SwapOrCopyContents(): buffers should both owned or the same size!"); + } + + source.Span.CopyTo(destination.Span); + } + } + /// /// Swap the contents (, , ) of the two buffers. /// Useful to transfer the contents of a temporary to a persistent /// /// The first buffer /// The second buffer - public static void SwapContents(Buffer2D a, Buffer2D b) + private static void SwapContents(Buffer2D a, Buffer2D b) { Size aSize = a.Size(); Size bSize = b.Size(); diff --git a/src/ImageSharp/Memory/ConsumedBuffer.cs b/src/ImageSharp/Memory/ConsumedBuffer.cs index b793b29c2..73468a381 100644 --- a/src/ImageSharp/Memory/ConsumedBuffer.cs +++ b/src/ImageSharp/Memory/ConsumedBuffer.cs @@ -20,6 +20,8 @@ namespace SixLabors.Memory public Memory Memory { get; } + public bool IsMemoryOwner => false; + public Span GetSpan() { return this.Memory.Span; diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index 4e0e0c702..847f2741d 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; namespace SixLabors.Memory { @@ -10,6 +11,8 @@ namespace SixLabors.Memory /// Depending on it's implementation, an can (1) OWN or (2) CONSUME the instance it wraps. /// For a deeper understanding of the owner/consumer model, read the following docs:
/// https://gist.github.com/GrabYourPitchforks/4c3e1935fd4d9fa2831dbfcab35dffc6 + /// TODO: We need more SOC here! For owned buffers we should use . + /// For the consumption case we should not use buffers at all. We need to refactor Buffer2D{T} for this. ///
/// The value type internal interface IBuffer : IDisposable @@ -20,6 +23,11 @@ namespace SixLabors.Memory ///
Memory Memory { get; } + /// + /// Gets a value indicating whether this instance is owning the . + /// + bool IsMemoryOwner { get; } + /// /// Gets the span to the memory "promised" by this buffer when it's OWNED (1). /// Gets `this.Memory.Span` when the buffer CONSUMED (2). diff --git a/src/ImageSharp/Memory/ManagedBufferBase.cs b/src/ImageSharp/Memory/ManagedBufferBase.cs index c1cc51274..606d1c962 100644 --- a/src/ImageSharp/Memory/ManagedBufferBase.cs +++ b/src/ImageSharp/Memory/ManagedBufferBase.cs @@ -9,10 +9,13 @@ namespace SixLabors.Memory /// /// Provides a base class for implementations by implementing pinning logic for adaption. /// - internal abstract class ManagedBufferBase : System.Buffers.MemoryManager + internal abstract class ManagedBufferBase : System.Buffers.MemoryManager, IBuffer + where T : struct { private GCHandle pinHandle; + public bool IsMemoryOwner => true; + /// /// Gets the object that should be pinned. /// diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs index 5636f167c..48503e999 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors } }); - Buffer2D.SwapContents(source.PixelBuffer, targetPixels); + Buffer2D.SwapOrCopyContent(source.PixelBuffer, targetPixels); } } } diff --git a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs index 918b67caf..221cf19ec 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors } }); - Buffer2D.SwapContents(source.PixelBuffer, targetPixels); + Buffer2D.SwapOrCopyContent(source.PixelBuffer, targetPixels); } } } diff --git a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs index 15dd000b4..cdaa6113f 100644 --- a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.Processing.Effects.Processors } }); - Buffer2D.SwapContents(source.PixelBuffer, targetPixels); + Buffer2D.SwapOrCopyContent(source.PixelBuffer, targetPixels); } } } diff --git a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs index e2ec556fc..5d4961f57 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors altSourceRow.CopyTo(targetRow); }); - Buffer2D.SwapContents(source.PixelBuffer, targetPixels); + Buffer2D.SwapOrCopyContent(source.PixelBuffer, targetPixels); } } @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors } }); - Buffer2D.SwapContents(source.PixelBuffer, targetPixels); + Buffer2D.SwapOrCopyContent(source.PixelBuffer, targetPixels); } } } diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 1b473ab5f..366266652 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -6,11 +6,14 @@ using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using Xunit; +// ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Advanced { using System.Buffers; + using SixLabors.Memory; + public class AdvancedImageExtensionsTests { public class GetPixelMemory @@ -40,34 +43,6 @@ namespace SixLabors.ImageSharp.Tests.Advanced } } - class TestMemoryManager : MemoryManager - { - public TestMemoryManager(TPixel[] pixelArray) - { - this.PixelArray = pixelArray; - } - - public TPixel[] PixelArray { get; } - - protected override void Dispose(bool disposing) - { - } - - public override Span GetSpan() - { - return this.PixelArray; - } - - public override MemoryHandle Pin(int elementIndex = 0) - { - throw new NotImplementedException(); - } - - public override void Unpin() - { - throw new NotImplementedException(); - } - } [Theory] [WithSolidFilledImages(1, 1, "Red", PixelTypes.Rgba32 | PixelTypes.Bgr24)] @@ -97,6 +72,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced image0.ComparePixelBufferTo(externalMemory.Span); } } + } [Theory] diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs deleted file mode 100644 index 35d6b5722..000000000 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; -using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.IO; -using Moq; -using Xunit; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Tests -{ - /// - /// Tests the class. - /// - public partial class ImageLoadTests : IDisposable - { - private readonly Mock fileSystem; - private Image returnImage; - private Mock localDecoder; - private readonly string FilePath; - private readonly IImageFormatDetector localMimeTypeDetector; - private readonly Mock localImageFormatMock; - - public Configuration LocalConfiguration { get; private set; } - public byte[] Marker { get; private set; } - public MemoryStream DataStream { get; private set; } - public byte[] DecodedData { get; private set; } - - public ImageLoadTests() - { - this.returnImage = new Image(1, 1); - - this.localImageFormatMock = new Mock(); - - this.localDecoder = new Mock(); - this.localMimeTypeDetector = new MockImageFormatDetector(this.localImageFormatMock.Object); - this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny())) - - .Callback((c, s) => - { - using (var ms = new MemoryStream()) - { - s.CopyTo(ms); - this.DecodedData = ms.ToArray(); - } - }) - .Returns(this.returnImage); - - this.fileSystem = new Mock(); - - this.LocalConfiguration = new Configuration - { - FileSystem = this.fileSystem.Object - }; - this.LocalConfiguration.ImageFormatsManager.AddImageFormatDetector(this.localMimeTypeDetector); - this.LocalConfiguration.ImageFormatsManager.SetDecoder(this.localImageFormatMock.Object, this.localDecoder.Object); - - TestFormat.RegisterGlobalTestFormat(); - this.Marker = Guid.NewGuid().ToByteArray(); - this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); - - this.FilePath = Guid.NewGuid().ToString(); - this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream); - - TestFileSystem.RegisterGlobalTestFormat(); - TestFileSystem.Global.AddFile(this.FilePath, this.DataStream); - } - - [Fact] - public void LoadFromStream() - { - Image img = Image.Load(this.DataStream); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromNoneSeekableStream() - { - NoneSeekableStream stream = new NoneSeekableStream(this.DataStream); - Image img = Image.Load(stream); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromStreamWithType() - { - Image img = Image.Load(this.DataStream); - - Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - - [Fact] - public void LoadFromStreamWithConfig() - { - Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream); - - Assert.NotNull(img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); - } - - [Fact] - public void LoadFromStreamWithTypeAndConfig() - { - Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); - } - - - [Fact] - public void LoadFromStreamWithDecoder() - { - Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object); - - Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream)); - } - - [Fact] - public void LoadFromStreamWithTypeAndDecoder() - { - Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream)); - } - - [Fact] - public void LoadFromBytes() - { - Image img = Image.Load(this.DataStream.ToArray()); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromBytesWithType() - { - Image img = Image.Load(this.DataStream.ToArray()); - - Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - - } - - [Fact] - public void LoadFromBytesWithConfig() - { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); - - Assert.NotNull(img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); - - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromBytesWithTypeAndConfig() - { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); - - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromBytesWithDecoder() - { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); - - Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny())); - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromBytesWithTypeAndDecoder() - { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny())); - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromFile() - { - Image img = Image.Load(this.DataStream); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromFileWithType() - { - Image img = Image.Load(this.DataStream); - - Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromFileWithConfig() - { - Image img = Image.Load(this.LocalConfiguration, this.FilePath); - - Assert.NotNull(img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); - } - - [Fact] - public void LoadFromFileWithTypeAndConfig() - { - Image img = Image.Load(this.LocalConfiguration, this.FilePath); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); - } - - [Fact] - public void LoadFromFileWithDecoder() - { - Image img = Image.Load(this.FilePath, this.localDecoder.Object); - - Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream)); - } - - [Fact] - public void LoadFromFileWithTypeAndDecoder() - { - Image img = Image.Load(this.FilePath, this.localDecoder.Object); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream)); - } - - [Fact] - public void LoadFromPixelData_Pixels() - { - var img = Image.LoadPixelData(new Rgba32[] { - Rgba32.Black, Rgba32.White, - Rgba32.White, Rgba32.Black, - }, 2, 2); - - Assert.NotNull(img); - using (var px = img.Lock()) - { - Assert.Equal(Rgba32.Black, px[0, 0]); - Assert.Equal(Rgba32.White, px[0, 1]); - - Assert.Equal(Rgba32.White, px[1, 0]); - Assert.Equal(Rgba32.Black, px[1, 1]); - } - } - - [Fact] - public void LoadFromPixelData_Bytes() - { - var img = Image.LoadPixelData(new byte[] { - 0,0,0,255, // 0,0 - 255,255,255,255, // 0,1 - 255,255,255,255, // 1,0 - 0,0,0,255, // 1,1 - }, 2, 2); - - Assert.NotNull(img); - using (var px = img.Lock()) - { - Assert.Equal(Rgba32.Black, px[0, 0]); - Assert.Equal(Rgba32.White, px[0, 1]); - - Assert.Equal(Rgba32.White, px[1, 0]); - Assert.Equal(Rgba32.Black, px[1, 1]); - } - } - - - [Fact] - public void LoadsImageWithoutThrowingCrcException() - { - var image1Provider = TestImageProvider.File(TestImages.Png.VersioningImage1); - - using (Image img = image1Provider.GetImage()) - { - Assert.Equal(166036, img.Frames.RootFrame.GetPixelSpan().Length); - } - } - - public void Dispose() - { - // clean up the global object; - this.returnImage?.Dispose(); - } - } -} diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs new file mode 100644 index 000000000..e442b5654 --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs @@ -0,0 +1,63 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests +{ + public partial class ImageTests + { + public class Load_BasicCases + { + [Fact] + public void ByteArray() + { + Assert.Throws(() => + { + Image.Load((byte[])null); + }); + + var file = TestFile.Create(TestImages.Bmp.Car); + using (var image = Image.Load(file.Bytes)) + { + Assert.Equal(600, image.Width); + Assert.Equal(450, image.Height); + } + } + + [Fact] + public void FileSystemPath() + { + var file = TestFile.Create(TestImages.Bmp.Car); + using (var image = Image.Load(file.FullPath)) + { + Assert.Equal(600, image.Width); + Assert.Equal(450, image.Height); + } + } + + [Fact] + public void FileSystemPath_FileNotFound() + { + System.IO.FileNotFoundException ex = Assert.Throws( + () => + { + Image.Load(Guid.NewGuid().ToString()); + }); + } + + [Fact] + public void FileSystemPath_NullPath() + { + ArgumentNullException ex = Assert.Throws( + () => + { + Image.Load((string)null); + }); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs new file mode 100644 index 000000000..957e5c40a --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs @@ -0,0 +1,338 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.IO; + +using Moq; + +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.IO; +using SixLabors.ImageSharp.PixelFormats; + +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests +{ + public partial class ImageTests + { + /// + /// Tests the class. + /// + public class Load_ComplexCases : IDisposable + { + private readonly Mock fileSystem; + private readonly Image returnImage; + private readonly Mock localDecoder; + private readonly string FilePath; + private readonly IImageFormatDetector localMimeTypeDetector; + private readonly Mock localImageFormatMock; + + public Configuration LocalConfiguration { get; private set; } + public byte[] Marker { get; private set; } + public MemoryStream DataStream { get; private set; } + public byte[] DecodedData { get; private set; } + + public Load_ComplexCases() + { + this.returnImage = new Image(1, 1); + + this.localImageFormatMock = new Mock(); + + this.localDecoder = new Mock(); + this.localMimeTypeDetector = new MockImageFormatDetector(this.localImageFormatMock.Object); + this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny())) + + .Callback((c, s) => + { + using (var ms = new MemoryStream()) + { + s.CopyTo(ms); + this.DecodedData = ms.ToArray(); + } + }) + .Returns(this.returnImage); + + this.fileSystem = new Mock(); + + this.LocalConfiguration = new Configuration + { + FileSystem = this.fileSystem.Object + }; + this.LocalConfiguration.ImageFormatsManager.AddImageFormatDetector(this.localMimeTypeDetector); + this.LocalConfiguration.ImageFormatsManager.SetDecoder(this.localImageFormatMock.Object, this.localDecoder.Object); + + TestFormat.RegisterGlobalTestFormat(); + this.Marker = Guid.NewGuid().ToByteArray(); + this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); + + this.FilePath = Guid.NewGuid().ToString(); + this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream); + + TestFileSystem.RegisterGlobalTestFormat(); + TestFileSystem.Global.AddFile(this.FilePath, this.DataStream); + } + + [Fact] + public void LoadFromStream() + { + var img = Image.Load(this.DataStream); + + Assert.NotNull(img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + } + + [Fact] + public void LoadFromNoneSeekableStream() + { + var stream = new NoneSeekableStream(this.DataStream); + var img = Image.Load(stream); + + Assert.NotNull(img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + } + + [Fact] + public void LoadFromStreamWithType() + { + var img = Image.Load(this.DataStream); + + Assert.NotNull(img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + } + + + [Fact] + public void LoadFromStreamWithConfig() + { + Stream stream = new MemoryStream(); + var img = Image.Load(this.LocalConfiguration, stream); + + Assert.NotNull(img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); + } + + [Fact] + public void LoadFromStreamWithTypeAndConfig() + { + Stream stream = new MemoryStream(); + var img = Image.Load(this.LocalConfiguration, stream); + + Assert.NotNull(img); + Assert.Equal(this.returnImage, img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); + } + + + [Fact] + public void LoadFromStreamWithDecoder() + { + Stream stream = new MemoryStream(); + var img = Image.Load(stream, this.localDecoder.Object); + + Assert.NotNull(img); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream)); + } + + [Fact] + public void LoadFromStreamWithTypeAndDecoder() + { + Stream stream = new MemoryStream(); + var img = Image.Load(stream, this.localDecoder.Object); + + Assert.NotNull(img); + Assert.Equal(this.returnImage, img); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream)); + } + + [Fact] + public void LoadFromBytes() + { + var img = Image.Load(this.DataStream.ToArray()); + + Assert.NotNull(img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + } + + [Fact] + public void LoadFromBytesWithType() + { + var img = Image.Load(this.DataStream.ToArray()); + + Assert.NotNull(img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + + } + + [Fact] + public void LoadFromBytesWithConfig() + { + var img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + + Assert.NotNull(img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); + + Assert.Equal(this.DataStream.ToArray(), this.DecodedData); + } + + [Fact] + public void LoadFromBytesWithTypeAndConfig() + { + var img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + + Assert.NotNull(img); + Assert.Equal(this.returnImage, img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); + + Assert.Equal(this.DataStream.ToArray(), this.DecodedData); + } + + [Fact] + public void LoadFromBytesWithDecoder() + { + var img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); + + Assert.NotNull(img); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny())); + Assert.Equal(this.DataStream.ToArray(), this.DecodedData); + } + + [Fact] + public void LoadFromBytesWithTypeAndDecoder() + { + var img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); + + Assert.NotNull(img); + Assert.Equal(this.returnImage, img); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny())); + Assert.Equal(this.DataStream.ToArray(), this.DecodedData); + } + + [Fact] + public void LoadFromFile() + { + var img = Image.Load(this.DataStream); + + Assert.NotNull(img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + } + + [Fact] + public void LoadFromFileWithType() + { + var img = Image.Load(this.DataStream); + + Assert.NotNull(img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + + TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); + } + + [Fact] + public void LoadFromFileWithConfig() + { + var img = Image.Load(this.LocalConfiguration, this.FilePath); + + Assert.NotNull(img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); + } + + [Fact] + public void LoadFromFileWithTypeAndConfig() + { + var img = Image.Load(this.LocalConfiguration, this.FilePath); + + Assert.NotNull(img); + Assert.Equal(this.returnImage, img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); + } + + [Fact] + public void LoadFromFileWithDecoder() + { + var img = Image.Load(this.FilePath, this.localDecoder.Object); + + Assert.NotNull(img); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream)); + } + + [Fact] + public void LoadFromFileWithTypeAndDecoder() + { + var img = Image.Load(this.FilePath, this.localDecoder.Object); + + Assert.NotNull(img); + Assert.Equal(this.returnImage, img); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream)); + } + + [Fact] + public void LoadFromPixelData_Pixels() + { + var img = Image.LoadPixelData(new Rgba32[] { + Rgba32.Black, Rgba32.White, + Rgba32.White, Rgba32.Black, + }, 2, 2); + + Assert.NotNull(img); + Assert.Equal(Rgba32.Black, img[0, 0]); + Assert.Equal(Rgba32.White, img[0, 1]); + + Assert.Equal(Rgba32.White, img[1, 0]); + Assert.Equal(Rgba32.Black, img[1, 1]); + } + + [Fact] + public void LoadFromPixelData_Bytes() + { + var img = Image.LoadPixelData(new byte[] { + 0,0,0,255, // 0,0 + 255,255,255,255, // 0,1 + 255,255,255,255, // 1,0 + 0,0,0,255, // 1,1 + }, 2, 2); + + Assert.NotNull(img); + Assert.Equal(Rgba32.Black, img[0, 0]); + Assert.Equal(Rgba32.White, img[0, 1]); + + Assert.Equal(Rgba32.White, img[1, 0]); + Assert.Equal(Rgba32.Black, img[1, 1]); + } + + + [Fact] + public void LoadsImageWithoutThrowingCrcException() + { + var image1Provider = TestImageProvider.File(TestImages.Png.VersioningImage1); + + using (Image img = image1Provider.GetImage()) + { + Assert.Equal(166036, img.Frames.RootFrame.GetPixelSpan().Length); + } + } + + public void Dispose() + { + // clean up the global object; + this.returnImage?.Dispose(); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Save.cs b/tests/ImageSharp.Tests/Image/ImageTests.Save.cs new file mode 100644 index 000000000..45399919a --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.Save.cs @@ -0,0 +1,70 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +// ReSharper disable InconsistentNaming + +using System; +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests +{ + using SixLabors.ImageSharp.Formats; + + public partial class ImageTests + { + public class Save + { + [Fact] + public void DetecedEncoding() + { + string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); + string file = System.IO.Path.Combine(dir, "DetecedEncoding.png"); + + using (var image = new Image(10, 10)) + { + image.Save(file); + } + + using (var img = Image.Load(file, out IImageFormat mime)) + { + Assert.Equal("image/png", mime.DefaultMimeType); + } + } + + [Fact] + public void WhenExtensionIsUnknown_Throws() + { + string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); + string file = System.IO.Path.Combine(dir, "UnknownExtensionsEncoding_Throws.tmp"); + + NotSupportedException ex = Assert.Throws( + () => + { + using (var image = new Image(10, 10)) + { + image.Save(file); + } + }); + } + + [Fact] + public void SetEncoding() + { + string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); + string file = System.IO.Path.Combine(dir, "SetEncoding.dat"); + + using (var image = new Image(10, 10)) + { + image.Save(file, new PngEncoder()); + } + + using (var img = Image.Load(file, out var mime)) + { + Assert.Equal("image/png", mime.DefaultMimeType); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs new file mode 100644 index 000000000..066be4a73 --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -0,0 +1,24 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.Memory; +using Xunit; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ + public partial class ImageTests + { + public class WrapMemory + { + [Fact] + public void ConsumedBuffer_IsMemoryOwner_ReturnsFalse() + { + var memory = new Memory(new int[55]); + var buffer = new ConsumedBuffer(memory); + Assert.False(buffer.IsMemoryOwner); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs index 8234df24e..ed142ed97 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.cs @@ -1,19 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; using Xunit; +// ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests { /// /// Tests the class. /// - public class ImageTests + public partial class ImageTests { public class Constructor { @@ -64,101 +62,5 @@ namespace SixLabors.ImageSharp.Tests } } } - - [Fact] - public void Load_ByteArray() - { - Assert.Throws(() => - { - Image.Load((byte[])null); - }); - - TestFile file = TestFile.Create(TestImages.Bmp.Car); - using (Image image = Image.Load(file.Bytes)) - { - Assert.Equal(600, image.Width); - Assert.Equal(450, image.Height); - } - } - - [Fact] - public void Load_FileSystemPath() - { - TestFile file = TestFile.Create(TestImages.Bmp.Car); - using (Image image = Image.Load(file.FullPath)) - { - Assert.Equal(600, image.Width); - Assert.Equal(450, image.Height); - } - } - - [Fact] - public void Load_FileSystemPath_FileNotFound() - { - System.IO.FileNotFoundException ex = Assert.Throws( - () => - { - Image.Load(Guid.NewGuid().ToString()); - }); - } - - [Fact] - public void Load_FileSystemPath_NullPath() - { - ArgumentNullException ex = Assert.Throws( - () => - { - Image.Load((string)null); - }); - } - - [Fact] - public void Save_DetecedEncoding() - { - string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); - string file = System.IO.Path.Combine(dir, "Save_DetecedEncoding.png"); - - using (Image image = new Image(10, 10)) - { - image.Save(file); - } - - using (Image img = Image.Load(file, out var mime)) - { - Assert.Equal("image/png", mime.DefaultMimeType); - } - } - - [Fact] - public void Save_WhenExtensionIsUnknown_Throws() - { - string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); - string file = System.IO.Path.Combine(dir, "Save_UnknownExtensionsEncoding_Throws.tmp"); - - NotSupportedException ex = Assert.Throws( - () => - { - using (Image image = new Image(10, 10)) - { - image.Save(file); - } - }); - } - - [Fact] - public void Save_SetEncoding() - { - string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageTests)); - string file = System.IO.Path.Combine(dir, "Save_SetEncoding.dat"); - - using (Image image = new Image(10, 10)) - { - image.Save(file, new PngEncoder()); - } - using (Image img = Image.Load(file, out var mime)) - { - Assert.Equal("image/png", mime.DefaultMimeType); - } - } } } diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index f22e558f3..301a76f56 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -1,11 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +// ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Memory { using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + + using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; using SixLabors.ImageSharp.Tests.Common; using SixLabors.Primitives; @@ -128,22 +131,92 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.True(Unsafe.AreSame(ref expected, ref actual)); } } - - [Fact] - public void SwapContents() + + public class SwapOrCopyContent { - using (Buffer2D a = this.MemoryAllocator.Allocate2D(10, 5)) - using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) + private MemoryAllocator MemoryAllocator { get; } = new MockMemoryAllocator(); + + [Fact] + public void WhenBothBuffersAreMemoryOwners_ShouldSwap() + { + using (Buffer2D a = this.MemoryAllocator.Allocate2D(10, 5)) + using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) + { + IBuffer aa = a.Buffer; + IBuffer bb = b.Buffer; + + Buffer2D.SwapOrCopyContent(a, b); + + Assert.Equal(bb, a.Buffer); + Assert.Equal(aa, b.Buffer); + + Assert.Equal(new Size(3, 7), a.Size()); + Assert.Equal(new Size(10, 5), b.Size()); + } + } + + [Fact] + public void WhenDestIsNotMemoryOwner_SameSize_ShouldCopy() + { + var data = new Rgba32[3 * 7]; + var color = new Rgba32(1, 2, 3, 4); + + var mmg = new TestMemoryManager(data); + var aBuff = new ConsumedBuffer(mmg.Memory); + + using (Buffer2D a = new Buffer2D(aBuff, 3, 7)) + { + IBuffer aa = a.Buffer; + + // Precondition: + Assert.Equal(aBuff, aa); + + using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) + { + IBuffer bb = b.Buffer; + bb.GetSpan()[10] = color; + + // Act: + Buffer2D.SwapOrCopyContent(a, b); + + // Assert: + Assert.Equal(aBuff, a.Buffer); + Assert.Equal(bb, b.Buffer); + } + + // Assert: + Assert.Equal(color, a.Buffer.GetSpan()[10]); + } + } + + [Fact] + public void WhenDestIsNotMemoryOwner_DifferentSize_Throws() { - IBuffer aa = a.Buffer; - IBuffer bb = b.Buffer; + var data = new Rgba32[3 * 7]; + var color = new Rgba32(1, 2, 3, 4); + data[10] = color; - Buffer2D.SwapContents(a, b); + var mmg = new TestMemoryManager(data); + var aBuff = new ConsumedBuffer(mmg.Memory); - Assert.Equal(bb, a.Buffer); - Assert.Equal(new Size(3, 7), a.Size()); - Assert.Equal(new Size(10, 5), b.Size()); + using (Buffer2D a = new Buffer2D(aBuff, 3, 7)) + { + IBuffer aa = a.Buffer; + using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 8)) + { + IBuffer bb = b.Buffer; + + Assert.ThrowsAny( + () => + { + Buffer2D.SwapOrCopyContent(a, b); + }); + } + + Assert.Equal(color, a.Buffer.GetSpan()[10]); + } } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index b7e5cfb32..6530850ec 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -64,6 +64,15 @@ namespace SixLabors.ImageSharp.Tests.Memory public static readonly TheoryData LenthValues = new TheoryData { 0, 1, 7, 1023, 1024 }; + [Fact] + public void IsMemoryOwner() + { + using (IBuffer buffer = this.MemoryAllocator.Allocate(42)) + { + Assert.True(buffer.IsMemoryOwner); + } + } + [Theory] [MemberData(nameof(LenthValues))] public void HasCorrectLength_byte(int desiredLength) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index e83d7009b..87a057549 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -7,9 +7,12 @@ using SixLabors.ImageSharp.Processing.Convolution; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; using Xunit; +// ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { + using SixLabors.ImageSharp.Advanced; + public class DetectEdgesTest : FileTestBase { private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.001f); @@ -30,6 +33,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution EdgeDetectionOperators.Sobel }; + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void DetectEdges_WorksOnWrappedMemoryImage(TestImageProvider provider) + where TPixel : struct, IPixel + { + provider.RunValidatingProcessorTestOnWrappedMemoryImage( + ctx => + { + Size size = ctx.GetCurrentSize(); + var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2); + ctx.DetectEdges(bounds); + }, + testName: nameof(this.DetectEdges_InBox)); + } + [Theory] [WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, DefaultPixelType)] [WithFileCollection(nameof(CommonTestImages), nameof(DetectEdgesFilters), DefaultPixelType)] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs index 3f028259c..dd475675b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -5,6 +5,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using Xunit; +// ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { @@ -23,15 +24,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms }; [Theory] - [WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] - public void ImageShouldFlip(TestImageProvider provider, FlipMode flipType) + [WithTestPatternImages(nameof(FlipValues), 53, 37, DefaultPixelType)] + [WithTestPatternImages(nameof(FlipValues), 17, 32, DefaultPixelType)] + public void Flip(TestImageProvider provider, FlipMode flipMode) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Flip(flipType)); - image.DebugSave(provider, flipType); - } + provider.RunValidatingProcessorTest(ctx => ctx.Flip(flipMode), testOutputDetails: flipMode); + } + + [Theory] + [WithTestPatternImages(nameof(FlipValues), 53, 37, DefaultPixelType)] + [WithTestPatternImages(nameof(FlipValues), 17, 32, DefaultPixelType)] + public void Flip_WorksOnWrappedMemoryImage(TestImageProvider provider, FlipMode flipMode) + where TPixel : struct, IPixel + { + provider.RunValidatingProcessorTestOnWrappedMemoryImage(ctx => ctx.Flip(flipMode), testOutputDetails: flipMode); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs new file mode 100644 index 000000000..e7ecb2dda --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs @@ -0,0 +1,50 @@ +using System; +using System.Buffers; + +namespace SixLabors.ImageSharp.Tests +{ + using SixLabors.ImageSharp.Advanced; + using SixLabors.ImageSharp.PixelFormats; + + class TestMemoryManager : MemoryManager + where T : struct, IPixel + { + public TestMemoryManager(T[] pixelArray) + { + this.PixelArray = pixelArray; + } + + public T[] PixelArray { get; } + + protected override void Dispose(bool disposing) + { + } + + public override Span GetSpan() + { + return this.PixelArray; + } + + public override MemoryHandle Pin(int elementIndex = 0) + { + throw new NotImplementedException(); + } + + public override void Unpin() + { + throw new NotImplementedException(); + } + + public static TestMemoryManager CreateAsCopyOfPixelData(Span pixelData) + { + var pixelArray = new T[pixelData.Length]; + pixelData.CopyTo(pixelArray); + return new TestMemoryManager(pixelArray); + } + + public static TestMemoryManager CreateAsCopyOfPixelData(Image image) + { + return CreateAsCopyOfPixelData(image.GetPixelSpan()); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index 43ae8423e..1c44c9aae 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -14,6 +14,8 @@ using SixLabors.Primitives; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Advanced; + /// /// Various utility and extension methods. /// @@ -186,6 +188,42 @@ namespace SixLabors.ImageSharp.Tests } } + public static void RunValidatingProcessorTestOnWrappedMemoryImage( + this TestImageProvider provider, + Action> process, + object testOutputDetails = null, + ImageComparer comparer = null, + string testName = null) + where TPixel : struct, IPixel + { + if (comparer == null) + { + comparer = ImageComparer.TolerantPercentage(0.001f); + } + + if (testName != null) + { + provider.Utility.TestName = testName; + } + + using (Image image0 = provider.GetImage()) + { + var mmg = TestMemoryManager.CreateAsCopyOfPixelData(image0.GetPixelSpan()); + + using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) + { + image1.Mutate(process); + image1.DebugSave(provider, testOutputDetails); + + // TODO: Investigate the cause of pixel inaccuracies under Linux + if (TestEnvironment.IsWindows) + { + image1.CompareToReferenceOutput(comparer, provider, testOutputDetails); + } + } + } + } + /// /// Same as but with an additional parameter passed to 'process' /// From dfd59dd25e5b36ecc50346cc862c2c11335ed343 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 11 Jun 2018 01:36:54 +0200 Subject: [PATCH 16/17] CloningImageProcessor uses SwapOrCopyPixelsBuffersFrom() --- src/ImageSharp/ImageFrame{TPixel}.cs | 19 +------- src/ImageSharp/Image{TPixel}.cs | 4 +- .../Processors/CloningImageProcessor.cs | 2 +- .../Processors/Convolution/DetectEdgesTest.cs | 2 +- .../Processors/Transforms/FlipTests.cs | 23 +++++---- .../Processors/Transforms/ResizeTests.cs | 22 +++++++++ .../TestUtilities/TestUtils.cs | 47 ++++++++++++++----- tests/Images/External | 2 +- 8 files changed, 79 insertions(+), 42 deletions(-) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 64cf602b0..4fb09f0a9 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -245,30 +245,15 @@ namespace SixLabors.ImageSharp this.GetPixelSpan().CopyTo(target.GetSpan()); } - /// - /// Switches the buffers used by the image and the PixelAccessor meaning that the Image will "own" the buffer from the PixelAccessor and the PixelAccessor will now own the Images buffer. - /// - /// The pixel source. - internal void SwapPixelsBuffers(PixelAccessor pixelSource) - { - Guard.NotNull(pixelSource, nameof(pixelSource)); - - // Push my memory into the accessor (which in turn unpins the old buffer ready for the images use) - Buffer2D newPixels = pixelSource.SwapBufferOwnership(this.PixelBuffer); - this.PixelBuffer = newPixels; - } - /// /// Switches the buffers used by the image and the pixelSource meaning that the Image will "own" the buffer from the pixelSource and the pixelSource will now own the Images buffer. /// /// The pixel source. - internal void SwapPixelsBuffers(ImageFrame pixelSource) + internal void SwapOrCopyPixelsBufferFrom(ImageFrame pixelSource) { Guard.NotNull(pixelSource, nameof(pixelSource)); - Buffer2D temp = this.PixelBuffer; - this.PixelBuffer = pixelSource.PixelBuffer; - pixelSource.PixelBuffer = temp; + Buffer2D.SwapOrCopyContent(this.PixelBuffer, pixelSource.PixelBuffer); } /// diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 2d84d4552..ad754bc75 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -233,13 +233,13 @@ namespace SixLabors.ImageSharp /// Switches the buffers used by the image and the pixelSource meaning that the Image will "own" the buffer from the pixelSource and the pixelSource will now own the Images buffer. /// /// The pixel source. - internal void SwapPixelsBuffers(Image pixelSource) + internal void SwapOrCopyPixelsBuffersFrom(Image pixelSource) { Guard.NotNull(pixelSource, nameof(pixelSource)); for (int i = 0; i < this.frames.Count; i++) { - this.frames[i].SwapPixelsBuffers(pixelSource.frames[i]); + this.frames[i].SwapOrCopyPixelsBufferFrom(pixelSource.frames[i]); } } } diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs index ec342dd9f..8150d5921 100644 --- a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing.Processors throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. The processor changed the number of frames."); } - source.SwapPixelsBuffers(cloned); + source.SwapOrCopyPixelsBuffersFrom(cloned); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index 87a057549..6894f9b9b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2); ctx.DetectEdges(bounds); }, - testName: nameof(this.DetectEdges_InBox)); + useReferenceOutputFrom: nameof(this.DetectEdges_InBox)); } [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs index dd475675b..0ac8a9459 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -11,10 +11,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { using SixLabors.ImageSharp.Processing.Transforms; - public class FlipTests : FileTestBase + public class FlipTests { - public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - public static readonly TheoryData FlipValues = new TheoryData { @@ -24,21 +22,28 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms }; [Theory] - [WithTestPatternImages(nameof(FlipValues), 53, 37, DefaultPixelType)] - [WithTestPatternImages(nameof(FlipValues), 17, 32, DefaultPixelType)] + [WithTestPatternImages(nameof(FlipValues), 53, 37, PixelTypes.Rgba32)] + [WithTestPatternImages(nameof(FlipValues), 17, 32, PixelTypes.Rgba32)] public void Flip(TestImageProvider provider, FlipMode flipMode) where TPixel : struct, IPixel { - provider.RunValidatingProcessorTest(ctx => ctx.Flip(flipMode), testOutputDetails: flipMode); + provider.RunValidatingProcessorTest( + ctx => ctx.Flip(flipMode), + testOutputDetails: flipMode, + appendPixelTypeToFileName: false); } [Theory] - [WithTestPatternImages(nameof(FlipValues), 53, 37, DefaultPixelType)] - [WithTestPatternImages(nameof(FlipValues), 17, 32, DefaultPixelType)] + [WithTestPatternImages(nameof(FlipValues), 53, 37, PixelTypes.Rgba32)] + [WithTestPatternImages(nameof(FlipValues), 17, 32, PixelTypes.Rgba32)] public void Flip_WorksOnWrappedMemoryImage(TestImageProvider provider, FlipMode flipMode) where TPixel : struct, IPixel { - provider.RunValidatingProcessorTestOnWrappedMemoryImage(ctx => ctx.Flip(flipMode), testOutputDetails: flipMode); + provider.RunValidatingProcessorTestOnWrappedMemoryImage( + ctx => ctx.Flip(flipMode), + testOutputDetails: flipMode, + useReferenceOutputFrom: nameof(this.Flip), + appendPixelTypeToFileName: false); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 84da154db..3fc22264d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -84,6 +84,28 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms } } + + [Theory] + [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] + public void Resize_ThrowsForWrappedMemoryImage(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image0 = provider.GetImage()) + { + var mmg = TestMemoryManager.CreateAsCopyOfPixelData(image0); + + using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) + { + Assert.ThrowsAny( + () => + { + image1.Mutate(x => x.Resize(image0.Width / 2, image0.Height / 2, true)); + }); + } + } + } + + [Theory] [WithFile(TestImages.Png.Kaboom, DefaultPixelType)] public void Resize_DoesNotBleedAlphaPixels(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index 1c44c9aae..ba7f6ad31 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -163,11 +163,15 @@ namespace SixLabors.ImageSharp.Tests /// The image processing method to test. (As a delegate) /// The value to append to the test output. /// The custom image comparer to use + /// + /// internal static void RunValidatingProcessorTest( this TestImageProvider provider, Action> process, object testOutputDetails = null, - ImageComparer comparer = null) + ImageComparer comparer = null, + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) where TPixel : struct, IPixel { if (comparer == null) @@ -178,12 +182,22 @@ namespace SixLabors.ImageSharp.Tests using (Image image = provider.GetImage()) { image.Mutate(process); - image.DebugSave(provider, testOutputDetails); + + image.DebugSave( + provider, + testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName, + appendSourceFileOrDescription: appendSourceFileOrDescription); // TODO: Investigate the cause of pixel inaccuracies under Linux if (TestEnvironment.IsWindows) { - image.CompareToReferenceOutput(comparer, provider, testOutputDetails); + image.CompareToReferenceOutput( + comparer, + provider, + testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName, + appendSourceFileOrDescription: appendSourceFileOrDescription); } } } @@ -193,7 +207,9 @@ namespace SixLabors.ImageSharp.Tests Action> process, object testOutputDetails = null, ImageComparer comparer = null, - string testName = null) + string useReferenceOutputFrom = null, + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) where TPixel : struct, IPixel { if (comparer == null) @@ -201,11 +217,6 @@ namespace SixLabors.ImageSharp.Tests comparer = ImageComparer.TolerantPercentage(0.001f); } - if (testName != null) - { - provider.Utility.TestName = testName; - } - using (Image image0 = provider.GetImage()) { var mmg = TestMemoryManager.CreateAsCopyOfPixelData(image0.GetPixelSpan()); @@ -213,12 +224,26 @@ namespace SixLabors.ImageSharp.Tests using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) { image1.Mutate(process); - image1.DebugSave(provider, testOutputDetails); + image1.DebugSave( + provider, + testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName, + appendSourceFileOrDescription: appendSourceFileOrDescription); // TODO: Investigate the cause of pixel inaccuracies under Linux if (TestEnvironment.IsWindows) { - image1.CompareToReferenceOutput(comparer, provider, testOutputDetails); + if (useReferenceOutputFrom != null) + { + provider.Utility.TestName = useReferenceOutputFrom; + } + + image1.CompareToReferenceOutput( + comparer, + provider, + testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName, + appendSourceFileOrDescription: appendSourceFileOrDescription); } } } diff --git a/tests/Images/External b/tests/Images/External index b1f057df3..802ffbae9 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit b1f057df33b7bfa6cabe714cf7090ac6017ea5d8 +Subproject commit 802ffbae9af22d986226bc1c20d7d96aaf25d6b9 From 76b60a70f09a84925f9c1c671cedaab4e7c71fc7 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 16 Jun 2018 18:54:30 +0200 Subject: [PATCH 17/17] hide GetPixelMemory() and GetPixelRowMemory() for now --- .../Advanced/AdvancedImageExtensions.cs | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 1a435733f..18b1d994b 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -23,32 +23,6 @@ namespace SixLabors.ImageSharp.Advanced where TPixel : struct, IPixel => GetConfiguration((IConfigurable)source); - /// - /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format - /// stored in row major order. - /// - /// The Pixel format. - /// The source - /// The - public static Memory GetPixelMemory(this ImageFrame source) - where TPixel : struct, IPixel - { - return source.PixelBuffer.Buffer.Memory; - } - - /// - /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format - /// stored in row major order. - /// - /// The Pixel format. - /// The source - /// The - public static Memory GetPixelMemory(this Image source) - where TPixel : struct, IPixel - { - return source.Frames.RootFrame.GetPixelMemory(); - } - /// /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format /// stored in row major order. @@ -71,30 +45,6 @@ namespace SixLabors.ImageSharp.Advanced where TPixel : struct, IPixel => source.Frames.RootFrame.GetPixelSpan(); - /// - /// Gets the representation of the pixels as a of contiguous memory - /// at row beginning from the the first pixel on that row. - /// - /// The type of the pixel. - /// The source. - /// The row. - /// The - public static Memory GetPixelRowMemory(this ImageFrame source, int rowIndex) - where TPixel : struct, IPixel - => source.PixelBuffer.GetRowMemory(rowIndex); - - /// - /// Gets the representation of the pixels as of of contiguous memory - /// at row beginning from the the first pixel on that row. - /// - /// The type of the pixel. - /// The source. - /// The row. - /// The - public static Memory GetPixelRowMemory(this Image source, int rowIndex) - where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelRowMemory(rowIndex); - /// /// Gets the representation of the pixels as a of contiguous memory /// at row beginning from the the first pixel on that row. @@ -145,6 +95,56 @@ namespace SixLabors.ImageSharp.Advanced where TPixel : struct, IPixel => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); + /// + /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format + /// stored in row major order. + /// + /// The Pixel format. + /// The source + /// The + internal static Memory GetPixelMemory(this ImageFrame source) + where TPixel : struct, IPixel + { + return source.PixelBuffer.Buffer.Memory; + } + + /// + /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format + /// stored in row major order. + /// + /// The Pixel format. + /// The source + /// The + internal static Memory GetPixelMemory(this Image source) + where TPixel : struct, IPixel + { + return source.Frames.RootFrame.GetPixelMemory(); + } + + /// + /// Gets the representation of the pixels as a of contiguous memory + /// at row beginning from the the first pixel on that row. + /// + /// The type of the pixel. + /// The source. + /// The row. + /// The + internal static Memory GetPixelRowMemory(this ImageFrame source, int rowIndex) + where TPixel : struct, IPixel + => source.PixelBuffer.GetRowMemory(rowIndex); + + /// + /// Gets the representation of the pixels as of of contiguous memory + /// at row beginning from the the first pixel on that row. + /// + /// The type of the pixel. + /// The source. + /// The row. + /// The + internal static Memory GetPixelRowMemory(this Image source, int rowIndex) + where TPixel : struct, IPixel + => source.Frames.RootFrame.GetPixelRowMemory(rowIndex); + /// /// Gets the assigned to 'source'. ///