Browse Source

RENAME: MemoryManager -> MemoryAllocator

pull/607/head
Anton Firszov 8 years ago
parent
commit
86e6f863ea
  1. 2
      src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
  2. 8
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs
  3. 6
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs
  4. 8
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs
  5. 8
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs
  6. 10
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs
  7. 6
      src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs
  8. 2
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs
  9. 4
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
  10. 6
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  11. 6
      src/ImageSharp/Common/Helpers/ParallelFor.cs
  12. 6
      src/ImageSharp/Configuration.cs
  13. 14
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  14. 2
      src/ImageSharp/Formats/Bmp/BmpEncoder.cs
  15. 10
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  16. 12
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  17. 2
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  18. 12
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  19. 10
      src/ImageSharp/Formats/Gif/LzwDecoder.cs
  20. 8
      src/ImageSharp/Formats/Gif/LzwEncoder.cs
  21. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
  22. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
  23. 6
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs
  24. 4
      src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
  25. 6
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
  26. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  27. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
  28. 14
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  29. 18
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  30. 2
      src/ImageSharp/Formats/Png/PngEncoder.cs
  31. 26
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  32. 2
      src/ImageSharp/Image.Decode.cs
  33. 14
      src/ImageSharp/ImageFrame{TPixel}.cs
  34. 8
      src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs
  35. 18
      src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs
  36. 20
      src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs
  37. 2
      src/ImageSharp/Memory/MemoryAllocator.cs
  38. 44
      src/ImageSharp/Memory/MemoryAllocatorExtensions.cs
  39. 4
      src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs
  40. 42
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
  41. 2
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
  42. 4
      src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
  43. 2
      src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs
  44. 2
      src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs
  45. 2
      src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs
  46. 2
      src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs
  47. 2
      src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs
  48. 4
      src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs
  49. 6
      src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs
  50. 6
      src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs
  51. 6
      src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs
  52. 46
      src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs
  53. 6
      src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs
  54. 4
      src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs
  55. 6
      src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs
  56. 14
      src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs
  57. 6
      src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs
  58. 4
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs
  59. 2
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs
  60. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
  61. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs
  62. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs
  63. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
  64. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
  65. 6
      tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs
  66. 2
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  67. 2
      tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs
  68. 2
      tests/ImageSharp.Tests/FakeImageOperationsProvider.cs
  69. 4
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  70. 4
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs
  71. 12
      tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs
  72. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
  73. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
  74. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  75. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs
  76. 2
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
  77. 38
      tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
  78. 18
      tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
  79. 4
      tests/ImageSharp.Tests/Memory/BufferAreaTests.cs
  80. 20
      tests/ImageSharp.Tests/Memory/BufferTestSuite.cs
  81. 2
      tests/ImageSharp.Tests/Memory/SimpleGcMemoryManagerTests.cs
  82. 20
      tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs
  83. 6
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  84. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs
  85. 6
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs
  86. 4
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

2
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<PointF> tempBuffer = configuration.MemoryManager.Allocate<PointF>(buffer.Length))
using (IBuffer<PointF> tempBuffer = configuration.MemoryAllocator.Allocate<PointF>(buffer.Length))
{
Span<PointF> innerBuffer = tempBuffer.GetSpan();
int count = this.Shape.FindIntersections(start, end, innerBuffer);

8
src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs

@ -65,10 +65,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
/// <remarks>scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.</remarks>
internal virtual void Apply(Span<float> scanline, int x, int y)
{
MemoryManager memoryManager = this.Target.MemoryManager;
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length))
using (IBuffer<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span<TPixel> 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);
}
}
}

6
src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs

@ -118,8 +118,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
internal override void Apply(Span<float> scanline, int x, int y)
{
// Create a span for colors
using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length))
using (IBuffer<float> amountBuffer = this.Target.MemoryAllocator.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = this.Target.MemoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span<TPixel> 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);
}
}
}

8
src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs

@ -151,10 +151,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
internal override void Apply(Span<float> scanline, int x, int y)
{
int patternY = y % this.pattern.Rows;
MemoryManager memoryManager = this.Target.MemoryManager;
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length))
using (IBuffer<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span<TPixel> 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);
}
}
}

8
src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs

@ -136,10 +136,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
/// <inheritdoc />
internal override void Apply(Span<float> scanline, int x, int y)
{
MemoryManager memoryManager = this.Target.MemoryManager;
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length))
using (IBuffer<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span<TPixel> 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);
}
}
}

10
src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs

@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
public SolidBrushApplicator(ImageFrame<TPixel> source, TPixel color, GraphicsOptions options)
: base(source, options)
{
this.Colors = source.MemoryManager.Allocate<TPixel>(source.Width);
this.Colors = source.MemoryAllocator.Allocate<TPixel>(source.Width);
this.Colors.GetSpan().Fill(color);
}
@ -88,15 +88,15 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
Span<TPixel> 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<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
{
Span<float> 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);
}
}
}

6
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<float> amount = memoryManager.Allocate<float>(width))
using (IBuffer<float> amount = memoryAllocator.Allocate<float>(width))
{
amount.GetSpan().Fill(this.Opacity);
@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{
Span<TPixel> background = source.GetPixelRowSpan(y).Slice(minX, width);
Span<TPixel> foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
blender.Blend(memoryManager, background, background, foreground, amount.GetSpan());
blender.Blend(memoryAllocator, background, background, foreground, amount.GetSpan());
});
}
}

2
src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs

@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
startY = 0;
}
using (IBuffer<float> amount = source.MemoryManager.Allocate<float>(width))
using (IBuffer<float> amount = source.MemoryAllocator.Allocate<float>(width))
using (BrushApplicator<TPixel> applicator = this.brush.CreateApplicator(
source,
sourceRectangle,

4
src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs

@ -96,8 +96,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
using (BrushApplicator<TPixel> applicator = this.Brush.CreateApplicator(source, rect, this.Options))
{
int scanlineWidth = maxX - minX;
using (IBuffer<float> bBuffer = source.MemoryManager.Allocate<float>(maxIntersections))
using (IBuffer<float> bScanline = source.MemoryManager.Allocate<float>(scanlineWidth))
using (IBuffer<float> bBuffer = source.MemoryAllocator.Allocate<float>(maxIntersections))
using (IBuffer<float> bScanline = source.MemoryAllocator.Allocate<float>(scanlineWidth))
{
bool scanlineDirty = true;
float subpixelFraction = 1f / subpixelCount;

6
src/ImageSharp/Advanced/AdvancedImageExtensions.cs

@ -144,12 +144,12 @@ namespace SixLabors.ImageSharp.Advanced
=> ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer();
/// <summary>
/// Gets the <see cref="MemoryManager"/> assigned to 'source'.
/// Gets the <see cref="MemoryAllocator"/> assigned to 'source'.
/// </summary>
/// <param name="source">The source image</param>
/// <returns>Returns the configuration.</returns>
internal static MemoryManager GetMemoryManager(this IConfigurable source)
=> GetConfiguration(source).MemoryManager;
internal static MemoryAllocator GetMemoryAllocator(this IConfigurable source)
=> GetConfiguration(source).MemoryAllocator;
/// <summary>
/// Gets the span to the backing buffer.

6
src/ImageSharp/Common/Helpers/ParallelFor.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp
/// <typeparam name="T">The value type of the buffer</typeparam>
/// <param name="fromInclusive">The start index, inclusive.</param>
/// <param name="toExclusive">The end index, exclusive.</param>
/// <param name="configuration">The <see cref="Configuration"/> used for getting the <see cref="MemoryManager"/> and <see cref="ParallelOptions"/></param>
/// <param name="configuration">The <see cref="Configuration"/> used for getting the <see cref="MemoryAllocator"/> and <see cref="ParallelOptions"/></param>
/// <param name="bufferLength">The length of the requested parallel buffer</param>
/// <param name="body">The delegate that is invoked once per iteration.</param>
public static void WithTemporaryBuffer<T>(
@ -35,12 +35,12 @@ namespace SixLabors.ImageSharp
Action<int, IBuffer<T>> body)
where T : struct
{
MemoryManager memoryManager = configuration.MemoryManager;
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
ParallelOptions parallelOptions = configuration.ParallelOptions;
IBuffer<T> InitBuffer()
{
return memoryManager.Allocate<T>(bufferLength);
return memoryAllocator.Allocate<T>(bufferLength);
}
void CleanUpBuffer(IBuffer<T> buffer)

6
src/ImageSharp/Configuration.cs

@ -75,9 +75,9 @@ namespace SixLabors.ImageSharp
public ImageFormatManager ImageFormatsManager { get; set; } = new ImageFormatManager();
/// <summary>
/// Gets or sets the <see cref="MemoryManager"/> that is currently in use.
/// Gets or sets the <see cref="MemoryAllocator"/> that is currently in use.
/// </summary>
public MemoryManager MemoryManager { get; set; } = ArrayPoolMemoryManager.CreateDefault();
public MemoryAllocator MemoryAllocator { get; set; } = ArrayPoolMemoryAllocator.CreateDefault();
/// <summary>
/// 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,

14
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;
/// <summary>
/// Initializes a new instance of the <see cref="BmpDecoderCore"/> 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;
}
/// <summary>
@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
var color = default(TPixel);
var rgba = new Rgba32(0, 0, 0, 255);
using (Buffer2D<byte> buffer = this.memoryManager.AllocateClean2D<byte>(width, height))
using (Buffer2D<byte> buffer = this.memoryAllocator.AllocateClean2D<byte>(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++)
{

2
src/ImageSharp/Formats/Bmp/BmpEncoder.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
var encoder = new BmpEncoderCore(this, image.GetMemoryManager());
var encoder = new BmpEncoderCore(this, image.GetMemoryAllocator());
encoder.Encode(image, stream);
}
}

10
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;
/// <summary>
/// Initializes a new instance of the <see cref="BmpEncoderCore"/> class.
/// </summary>
/// <param name="options">The encoder options</param>
/// <param name="memoryManager">The memory manager</param>
public BmpEncoderCore(IBmpEncoderOptions options, MemoryManager memoryManager)
/// <param name="memoryAllocator">The memory manager</param>
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);
}
/// <summary>

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

@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// </summary>
public FrameDecodingMode DecodingMode { get; }
private MemoryManager MemoryManager => this.configuration.MemoryManager;
private MemoryAllocator MemoryAllocator => this.configuration.MemoryAllocator;
/// <summary>
/// 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<Rgb24> colorTable = MemoryMarshal.Cast<byte, Rgb24>((localColorTable ?? this.globalColorTable).GetSpan());
@ -350,7 +350,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private void ReadFrameIndices(in GifImageDescriptor imageDescriptor, Span<byte> 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);

2
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
var encoder = new GifEncoderCore(image.GetConfiguration().MemoryManager, this);
var encoder = new GifEncoderCore(image.GetConfiguration().MemoryAllocator, this);
encoder.Encode(image, stream);
}
}

12
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// </summary>
internal sealed class GifEncoderCore
{
private readonly MemoryManager memoryManager;
private readonly MemoryAllocator memoryAllocator;
/// <summary>
/// A reusable buffer used to reduce allocations.
@ -49,11 +49,11 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// Initializes a new instance of the <see cref="GifEncoderCore"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="options">The options for the encoder.</param>
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<byte, Rgb24>(ref MemoryMarshal.GetReference(colorTable.GetSpan()));
@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private void WriteImageData<TPixel>(QuantizedFrame<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
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);
}

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

@ -48,18 +48,18 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Initializes a new instance of the <see cref="LzwDecoder"/> class
/// and sets the stream, where the compressed data should be read from.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="stream">The stream to read from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="stream"/> is null.</exception>
public LzwDecoder(MemoryManager memoryManager, Stream stream)
public LzwDecoder(MemoryAllocator memoryAllocator, Stream stream)
{
Guard.NotNull(stream, nameof(stream));
this.stream = stream;
this.prefix = memoryManager.Allocate<int>(MaxStackSize, true);
this.suffix = memoryManager.Allocate<int>(MaxStackSize, true);
this.pixelStack = memoryManager.Allocate<int>(MaxStackSize + 1, true);
this.prefix = memoryAllocator.Allocate<int>(MaxStackSize, true);
this.suffix = memoryAllocator.Allocate<int>(MaxStackSize, true);
this.pixelStack = memoryAllocator.Allocate<int>(MaxStackSize + 1, true);
}
/// <summary>

8
src/ImageSharp/Formats/Gif/LzwEncoder.cs

@ -168,16 +168,16 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// Initializes a new instance of the <see cref="LzwEncoder"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="indexedPixels">The array of indexed pixels.</param>
/// <param name="colorDepth">The color depth in bits.</param>
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<int>(HashSize, true);
this.codeTable = memoryManager.Allocate<int>(HashSize, true);
this.hashTable = memoryAllocator.Allocate<int>(HashSize, true);
this.codeTable = memoryAllocator.Allocate<int>(HashSize, true);
}
/// <summary>

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs

@ -26,11 +26,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary>
/// Initializes a new instance of the <see cref="JpegComponentPostProcessor"/> class.
/// </summary>
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<float>(
this.ColorBuffer = memoryAllocator.Allocate2D<float>(
imagePostProcessor.PostProcessorBufferSize.Width,
imagePostProcessor.PostProcessorBufferSize.Height);

8
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs

@ -49,17 +49,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary>
/// Initializes a new instance of the <see cref="JpegImagePostProcessor"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="rawJpeg">The <see cref="IRawJpegData"/> representing the uncompressed spectral Jpeg data</param>
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<Vector4>(rawJpeg.ImageSizeInPixels.Width);
this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryAllocator, this, c)).ToArray();
this.rgbaBuffer = memoryAllocator.Allocate<Vector4>(rawJpeg.ImageSizeInPixels.Width);
this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace);
}

6
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs

@ -56,9 +56,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <summary>
/// Initializes <see cref="SpectralBlocks"/>
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="decoder">The <see cref="GolangJpegDecoderCore"/> instance</param>
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<Block8x8>(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true);
this.SpectralBlocks = memoryAllocator.Allocate2D<Block8x8>(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true);
}
/// <summary>

4
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<TPixel> PostProcessIntoImage<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this))
using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this))
{
var image = new Image<TPixel>(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData);
postProcessor.PostProcess(image.Frames.RootFrame);

6
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs

@ -38,13 +38,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <summary>
/// Initializes a new instance of the <see cref="DoubleBufferedStreamReader"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="stream">The input stream.</param>
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;
}

8
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs

@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// </summary>
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<Block8x8>(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true);
this.SpectralBlocks = this.memoryAllocator.Allocate2D<Block8x8>(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

8
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs

@ -37,14 +37,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <summary>
/// Initializes a new instance of the <see cref="PdfJsHuffmanTable"/> struct.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="lengths">The code lengths</param>
/// <param name="values">The huffman values</param>
public PdfJsHuffmanTable(MemoryManager memoryManager, ReadOnlySpan<byte> lengths, ReadOnlySpan<byte> values)
public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan<byte> lengths, ReadOnlySpan<byte> values)
{
const int length = 257;
using (IBuffer<short> huffsize = memoryManager.Allocate<short>(length))
using (IBuffer<short> huffcode = memoryManager.Allocate<short>(length))
using (IBuffer<short> huffsize = memoryAllocator.Allocate<short>(length))
using (IBuffer<short> huffcode = memoryAllocator.Allocate<short>(length))
{
ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan());
ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan());

14
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<byte> codeLengths, ReadOnlySpan<byte> values)
{
tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryManager, codeLengths, values);
tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryAllocator, codeLengths, values);
}
/// <summary>
@ -834,7 +834,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
private Image<TPixel> PostProcessIntoImage<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this))
using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this))
{
var image = new Image<TPixel>(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData);
postProcessor.PostProcess(image.Frames.RootFrame);

18
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;
/// <summary>
/// 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);
}
/// <summary>
@ -727,7 +727,7 @@ namespace SixLabors.ImageSharp.Formats.Png
if (this.header.BitDepth == 16)
{
int length = this.header.Width * 3;
using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
using (IBuffer<byte> compressed = this.configuration.MemoryAllocator.Allocate<byte>(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<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
using (IBuffer<byte> compressed = this.configuration.MemoryAllocator.Allocate<byte>(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<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
using (IBuffer<byte> compressed = this.configuration.MemoryAllocator.Allocate<byte>(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<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
using (IBuffer<byte> compressed = this.configuration.MemoryAllocator.Allocate<byte>(length))
{
Span<byte> 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<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
using (IBuffer<byte> compressed = this.configuration.MemoryAllocator.Allocate<byte>(length))
{
Span<byte> 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);

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

@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Formats.Png
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
using (var encoder = new PngEncoderCore(image.GetMemoryManager(), this))
using (var encoder = new PngEncoderCore(image.GetMemoryAllocator(), this))
{
encoder.Encode(image, stream);
}

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

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary>
internal sealed class PngEncoderCore : IDisposable
{
private readonly MemoryManager memoryManager;
private readonly MemoryAllocator memoryAllocator;
/// <summary>
/// The maximum block size, defaults at 64k for uncompressed blocks.
@ -144,11 +144,11 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <summary>
/// Initializes a new instance of the <see cref="PngEncoderCore"/> class.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
/// <param name="options">The options for influencing the encoder</param>
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<byte> colorTableSpan = colorTable.GetSpan();
Span<byte> 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;

2
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);

14
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<TPixel>(width, height, false);
this.MemoryAllocator = configuration.MemoryAllocator;
this.PixelBuffer = this.MemoryAllocator.Allocate2D<TPixel>(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<TPixel>(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<TPixel>(source.PixelBuffer.Width, source.PixelBuffer.Height);
this.MemoryAllocator = configuration.MemoryAllocator;
this.PixelBuffer = this.MemoryAllocator.Allocate2D<TPixel>(source.PixelBuffer.Width, source.PixelBuffer.Height);
source.PixelBuffer.GetSpan().CopyTo(this.PixelBuffer.GetSpan());
this.MetaData = source.MetaData.Clone();
}
/// <summary>
/// Gets the <see cref="MemoryManager" /> to use for buffer allocations.
/// Gets the <see cref="MemoryAllocator" /> to use for buffer allocations.
/// </summary>
public MemoryManager MemoryManager { get; }
public MemoryAllocator MemoryAllocator { get; }
/// <summary>
/// Gets the image pixels. Not private as Buffer2D requires an array in its constructor.

8
src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs → src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs

@ -10,10 +10,10 @@ namespace SixLabors.ImageSharp.Memory
/// <summary>
/// Contains <see cref="Buffer{T}"/> and <see cref="ManagedByteBuffer"/>
/// </summary>
public partial class ArrayPoolMemoryManager
public partial class ArrayPoolMemoryAllocator
{
/// <summary>
/// The buffer implementation of <see cref="ArrayPoolMemoryManager"/>.
/// The buffer implementation of <see cref="ArrayPoolMemoryAllocator"/>.
/// In this implementation <see cref="IBuffer{T}.Memory"/> is owned.
/// </summary>
private class Buffer<T> : ManagedBufferBase<T>, IBuffer<T>
@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Memory
/// </summary>
/// <remarks>
/// 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 <see cref="ArrayPoolMemoryManager.ReleaseRetainedResources"/>, regardless of having buffer instances still being in use.
/// after a call to <see cref="ArrayPoolMemoryAllocator.ReleaseRetainedResources"/>, regardless of having buffer instances still being in use.
/// </remarks>
private WeakReference<ArrayPool<byte>> sourcePoolReference;
@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Memory
}
/// <summary>
/// The <see cref="IManagedByteBuffer"/> implementation of <see cref="ArrayPoolMemoryManager"/>.
/// The <see cref="IManagedByteBuffer"/> implementation of <see cref="ArrayPoolMemoryAllocator"/>.
/// </summary>
private class ManagedByteBuffer : Buffer<byte>, IManagedByteBuffer
{

18
src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs → src/ImageSharp/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs

@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Memory
/// <summary>
/// Contains common factory methods and configuration constants.
/// </summary>
public partial class ArrayPoolMemoryManager
public partial class ArrayPoolMemoryAllocator
{
/// <summary>
/// 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.
/// </summary>
/// <returns>The memory manager</returns>
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.
/// </summary>
/// <returns>The memory manager</returns>
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);
}
/// <summary>
/// Only pool small buffers like image rows.
/// </summary>
/// <returns>The memory manager</returns>
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);
}
/// <summary>
/// RAM is not an issue for me, gimme maximum througput!
/// </summary>
/// <returns>The memory manager</returns>
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);
}
}
}

20
src/ImageSharp/Memory/ArrayPoolMemoryManager.cs → src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs

@ -7,9 +7,9 @@ using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Implements <see cref="MemoryManager"/> by allocating memory from <see cref="ArrayPool{T}"/>.
/// Implements <see cref="MemoryAllocator"/> by allocating memory from <see cref="ArrayPool{T}"/>.
/// </summary>
public partial class ArrayPoolMemoryManager : MemoryManager
public partial class ArrayPoolMemoryAllocator : MemoryAllocator
{
/// <summary>
/// The <see cref="ArrayPool{T}"/> for small-to-medium buffers which is not kept clean.
@ -26,40 +26,40 @@ namespace SixLabors.ImageSharp.Memory
private readonly int maxArraysPerBucketLargePool;
/// <summary>
/// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class.
/// Initializes a new instance of the <see cref="ArrayPoolMemoryAllocator"/> class.
/// </summary>
public ArrayPoolMemoryManager()
public ArrayPoolMemoryAllocator()
: this(DefaultMaxPooledBufferSizeInBytes, DefaultBufferSelectorThresholdInBytes)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class.
/// Initializes a new instance of the <see cref="ArrayPoolMemoryAllocator"/> class.
/// </summary>
/// <param name="maxPoolSizeInBytes">The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated.</param>
public ArrayPoolMemoryManager(int maxPoolSizeInBytes)
public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes)
: this(maxPoolSizeInBytes, GetLargeBufferThresholdInBytes(maxPoolSizeInBytes))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class.
/// Initializes a new instance of the <see cref="ArrayPoolMemoryAllocator"/> class.
/// </summary>
/// <param name="maxPoolSizeInBytes">The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated.</param>
/// <param name="poolSelectorThresholdInBytes">Arrays over this threshold will be pooled in <see cref="largeArrayPool"/> which has less buckets for memory safety.</param>
public ArrayPoolMemoryManager(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes)
public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes)
: this(maxPoolSizeInBytes, poolSelectorThresholdInBytes, DefaultLargePoolBucketCount, DefaultNormalPoolBucketCount)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class.
/// Initializes a new instance of the <see cref="ArrayPoolMemoryAllocator"/> class.
/// </summary>
/// <param name="maxPoolSizeInBytes">The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated.</param>
/// <param name="poolSelectorThresholdInBytes">The threshold to pool arrays in <see cref="largeArrayPool"/> which has less buckets for memory safety.</param>
/// <param name="maxArraysPerBucketLargePool">Max arrays per bucket for the large array pool</param>
/// <param name="maxArraysPerBucketNormalPool">Max arrays per bucket for the normal array pool</param>
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));

2
src/ImageSharp/Memory/MemoryManager.cs → src/ImageSharp/Memory/MemoryAllocator.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Memory
/// <summary>
/// Memory managers are used to allocate memory for image processing operations.
/// </summary>
public abstract class MemoryManager
public abstract class MemoryAllocator
{
/// <summary>
/// Allocates an <see cref="IBuffer{T}"/> of size <paramref name="length"/>, optionally

44
src/ImageSharp/Memory/MemoryManagerExtensions.cs → src/ImageSharp/Memory/MemoryAllocatorExtensions.cs

@ -3,9 +3,9 @@
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Extension methods for <see cref="MemoryManager"/>.
/// Extension methods for <see cref="MemoryAllocator"/>.
/// </summary>
internal static class MemoryManagerExtensions
internal static class MemoryAllocatorExtensions
{
/// <summary>
/// Allocates a <see cref="IBuffer{T}"/> of size <paramref name="length"/>.
@ -13,67 +13,67 @@ namespace SixLabors.ImageSharp.Memory
/// returning, so it may contain data from an earlier use.
/// </summary>
/// <typeparam name="T">Type of the data stored in the buffer</typeparam>
/// <param name="memoryManager">The <see cref="MemoryManager"/></param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/></param>
/// <param name="length">Size of the buffer to allocate</param>
/// <returns>A buffer of values of type <typeparamref name="T"/>.</returns>
public static IBuffer<T> Allocate<T>(this MemoryManager memoryManager, int length)
public static IBuffer<T> Allocate<T>(this MemoryAllocator memoryAllocator, int length)
where T : struct
{
return memoryManager.Allocate<T>(length, false);
return memoryAllocator.Allocate<T>(length, false);
}
public static IBuffer<T> AllocateClean<T>(this MemoryManager memoryManager, int length)
public static IBuffer<T> AllocateClean<T>(this MemoryAllocator memoryAllocator, int length)
where T : struct
{
return memoryManager.Allocate<T>(length, true);
return memoryAllocator.Allocate<T>(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<T> Allocate2D<T>(this MemoryManager memoryManager, int width, int height, bool clear)
public static Buffer2D<T> Allocate2D<T>(this MemoryAllocator memoryAllocator, int width, int height, bool clear)
where T : struct
{
IBuffer<T> buffer = memoryManager.Allocate<T>(width * height, clear);
IBuffer<T> buffer = memoryAllocator.Allocate<T>(width * height, clear);
return new Buffer2D<T>(buffer, width, height);
}
public static Buffer2D<T> Allocate2D<T>(this MemoryManager memoryManager, Size size)
public static Buffer2D<T> Allocate2D<T>(this MemoryAllocator memoryAllocator, Size size)
where T : struct =>
Allocate2D<T>(memoryManager, size.Width, size.Height, false);
Allocate2D<T>(memoryAllocator, size.Width, size.Height, false);
public static Buffer2D<T> Allocate2D<T>(this MemoryManager memoryManager, int width, int height)
public static Buffer2D<T> Allocate2D<T>(this MemoryAllocator memoryAllocator, int width, int height)
where T : struct =>
Allocate2D<T>(memoryManager, width, height, false);
Allocate2D<T>(memoryAllocator, width, height, false);
public static Buffer2D<T> AllocateClean2D<T>(this MemoryManager memoryManager, int width, int height)
public static Buffer2D<T> AllocateClean2D<T>(this MemoryAllocator memoryAllocator, int width, int height)
where T : struct =>
Allocate2D<T>(memoryManager, width, height, true);
Allocate2D<T>(memoryAllocator, width, height, true);
/// <summary>
/// Allocates padded buffers for BMP encoder/decoder. (Replacing old PixelRow/PixelArea)
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/></param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/></param>
/// <param name="width">Pixel count in the row</param>
/// <param name="pixelSizeInBytes">The pixel size in bytes, eg. 3 for RGB</param>
/// <param name="paddingInBytes">The padding</param>
/// <returns>A <see cref="IManagedByteBuffer"/></returns>
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);
}
}
}

4
src/ImageSharp/Memory/SimpleGcMemoryManager.cs → src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Implements <see cref="MemoryManager"/> by newing up arrays by the GC on every allocation requests.
/// Implements <see cref="MemoryAllocator"/> by newing up arrays by the GC on every allocation requests.
/// </summary>
public class SimpleGcMemoryManager : MemoryManager
public class SimpleGcMemoryAllocator : MemoryAllocator
{
/// <inheritdoc />
internal override IBuffer<T> Allocate<T>(int length, bool clear)

42
src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> 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
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
{
Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length));
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));

2
src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt

@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
}
/// <inheritdoc />
public override void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
public override void Blend(MemoryAllocator memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount)
{
Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length));
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));

4
src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Blend 2 pixels together.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/></param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/></param>
/// <param name="destination">The destination span.</param>
/// <param name="background">The background span.</param>
/// <param name="source">The source span.</param>
@ -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.
/// </param>
public abstract void Blend(MemoryManager memoryManager, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount);
public abstract void Blend(MemoryAllocator memoryAllocator, Span<TPixel> destination, Span<TPixel> background, Span<TPixel> source, Span<float> amount);
}
}

2
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<TPixel> targetPixels = configuration.MemoryManager.Allocate2D<TPixel>(source.Width, source.Height))
using (Buffer2D<TPixel> targetPixels = configuration.MemoryAllocator.Allocate2D<TPixel>(source.Width, source.Height))
{
source.CopyTo(targetPixels);

2
src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs

@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{
ParallelOptions parallelOptions = configuration.ParallelOptions;
using (Buffer2D<TPixel> firstPassPixels = configuration.MemoryManager.Allocate2D<TPixel>(source.Size()))
using (Buffer2D<TPixel> firstPassPixels = configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size()))
{
this.ApplyConvolution(firstPassPixels, source.PixelBuffer, source.Bounds(), this.KernelX, parallelOptions);
this.ApplyConvolution(source.PixelBuffer, firstPassPixels, sourceRectangle, this.KernelY, parallelOptions);

2
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<TPixel> targetPixels = configuration.MemoryManager.Allocate2D<TPixel>(source.Size()))
using (Buffer2D<TPixel> targetPixels = configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size()))
{
source.CopyTo(targetPixels);

2
src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs

@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing
}
/// <inheritdoc/>
public MemoryManager MemoryManager => this.source.GetConfiguration().MemoryManager;
public MemoryAllocator MemoryAllocator => this.source.GetConfiguration().MemoryAllocator;
/// <inheritdoc/>
public Image<TPixel> Apply()

2
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<TPixel> targetPixels = configuration.MemoryManager.Allocate2D<TPixel>(source.Size()))
using (Buffer2D<TPixel> targetPixels = configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size()))
{
source.CopyTo(targetPixels);

4
src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs

@ -16,10 +16,10 @@ namespace SixLabors.ImageSharp.Processing
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets a reference to the <see cref="MemoryManager" /> used to allocate buffers
/// Gets a reference to the <see cref="MemoryAllocator" /> used to allocate buffers
/// for this context.
/// </summary>
MemoryManager MemoryManager { get; }
MemoryAllocator MemoryAllocator { get; }
/// <summary>
/// Gets the image dimensions at the current point in the processing pipeline.

6
src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs

@ -66,8 +66,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
int width = maxX - minX;
using (IBuffer<TPixel> colors = source.MemoryManager.Allocate<TPixel>(width))
using (IBuffer<float> amount = source.MemoryManager.Allocate<float>(width))
using (IBuffer<TPixel> colors = source.MemoryAllocator.Allocate<TPixel>(width))
using (IBuffer<float> amount = source.MemoryAllocator.Allocate<float>(width))
{
// Be careful! Do not capture colorSpan & amountSpan in the lambda below!
Span<TPixel> colorSpan = colors.GetSpan();
@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
Span<TPixel> 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());
});
}
}

6
src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs

@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
}
int width = maxX - minX;
using (IBuffer<TPixel> rowColors = source.MemoryManager.Allocate<TPixel>(width))
using (IBuffer<TPixel> rowColors = source.MemoryAllocator.Allocate<TPixel>(width))
{
// Be careful! Do not capture rowColorsSpan in the lambda below!
Span<TPixel> rowColorsSpan = rowColors.GetSpan();
@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
configuration.ParallelOptions,
y =>
{
using (IBuffer<float> amounts = source.MemoryManager.Allocate<float>(width))
using (IBuffer<float> amounts = source.MemoryAllocator.Allocate<float>(width))
{
Span<float> amountsSpan = amounts.GetSpan();
int offsetY = y - startY;
@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
Span<TPixel> 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);
}
});
}

6
src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs

@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
}
int width = maxX - minX;
using (IBuffer<TPixel> rowColors = source.MemoryManager.Allocate<TPixel>(width))
using (IBuffer<TPixel> rowColors = source.MemoryAllocator.Allocate<TPixel>(width))
{
// Be careful! Do not capture rowColorsSpan in the lambda below!
Span<TPixel> rowColorsSpan = rowColors.GetSpan();
@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
configuration.ParallelOptions,
y =>
{
using (IBuffer<float> amounts = source.MemoryManager.Allocate<float>(width))
using (IBuffer<float> amounts = source.MemoryAllocator.Allocate<float>(width))
{
Span<float> amountsSpan = amounts.GetSpan();
int offsetY = y - startY;
@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
Span<TPixel> 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);
}
});
}

46
src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs

@ -141,17 +141,17 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
public override QuantizedFrame<TPixel> QuantizeFrame(ImageFrame<TPixel> image)
{
Guard.NotNull(image, nameof(image));
MemoryManager memoryManager = image.MemoryManager;
MemoryAllocator memoryAllocator = image.MemoryAllocator;
try
{
this.vwt = memoryManager.AllocateClean<long>(TableLength);
this.vmr = memoryManager.AllocateClean<long>(TableLength);
this.vmg = memoryManager.AllocateClean<long>(TableLength);
this.vmb = memoryManager.AllocateClean<long>(TableLength);
this.vma = memoryManager.AllocateClean<long>(TableLength);
this.m2 = memoryManager.AllocateClean<float>(TableLength);
this.tag = memoryManager.AllocateClean<byte>(TableLength);
this.vwt = memoryAllocator.AllocateClean<long>(TableLength);
this.vmr = memoryAllocator.AllocateClean<long>(TableLength);
this.vmg = memoryAllocator.AllocateClean<long>(TableLength);
this.vmb = memoryAllocator.AllocateClean<long>(TableLength);
this.vma = memoryAllocator.AllocateClean<long>(TableLength);
this.m2 = memoryAllocator.AllocateClean<float>(TableLength);
this.tag = memoryAllocator.AllocateClean<byte>(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
/// <summary>
/// Converts the histogram into moments so that we can rapidly calculate the sums of the above quantities over any desired box.
/// </summary>
private void Get3DMoments(MemoryManager memoryManager)
private void Get3DMoments(MemoryAllocator memoryAllocator)
{
Span<long> vwtSpan = this.vwt.GetSpan();
Span<long> vmrSpan = this.vmr.GetSpan();
@ -473,19 +473,19 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
Span<long> vmaSpan = this.vma.GetSpan();
Span<float> m2Span = this.m2.GetSpan();
using (IBuffer<long> volume = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeR = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeG = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeB = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeA = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<float> volume2 = memoryManager.Allocate<float>(IndexCount * IndexAlphaCount))
using (IBuffer<long> area = memoryManager.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaR = memoryManager.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaG = memoryManager.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaB = memoryManager.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaA = memoryManager.Allocate<long>(IndexAlphaCount))
using (IBuffer<float> area2 = memoryManager.Allocate<float>(IndexAlphaCount))
using (IBuffer<long> volume = memoryAllocator.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeR = memoryAllocator.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeG = memoryAllocator.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeB = memoryAllocator.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeA = memoryAllocator.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<float> volume2 = memoryAllocator.Allocate<float>(IndexCount * IndexAlphaCount))
using (IBuffer<long> area = memoryAllocator.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaR = memoryAllocator.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaG = memoryAllocator.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaB = memoryAllocator.Allocate<long>(IndexAlphaCount))
using (IBuffer<long> areaA = memoryAllocator.Allocate<long>(IndexAlphaCount))
using (IBuffer<float> area2 = memoryAllocator.Allocate<float>(IndexAlphaCount))
{
Span<long> volumeSpan = volume.GetSpan();
Span<long> volumeRSpan = volumeR.GetSpan();

6
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<float> yBuffer = memoryManager.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryManager.Allocate2D<float>(xLength, height))
using (Buffer2D<float> yBuffer = memoryAllocator.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryAllocator.Allocate2D<float>(xLength, height))
{
Parallel.For(
0,

4
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<TPixel> targetPixels = configuration.MemoryManager.Allocate2D<TPixel>(source.Size()))
using (Buffer2D<TPixel> targetPixels = configuration.MemoryAllocator.Allocate2D<TPixel>(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<TPixel> targetPixels = configuration.MemoryManager.Allocate2D<TPixel>(source.Size()))
using (Buffer2D<TPixel> targetPixels = configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size()))
{
Parallel.For(
0,

6
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<float> yBuffer = memoryManager.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryManager.Allocate2D<float>(xLength, height))
using (Buffer2D<float> yBuffer = memoryAllocator.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryAllocator.Allocate2D<float>(xLength, height))
{
Parallel.For(
0,

14
src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs

@ -143,12 +143,12 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
/// <summary>
/// Computes the weights to apply at each pixel when resizing.
/// </summary>
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations</param>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations</param>
/// <param name="destinationSize">The destination size</param>
/// <param name="sourceSize">The source size</param>
/// <returns>The <see cref="WeightsBuffer"/></returns>
// 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<Vector4> firstPassPixels = source.MemoryManager.Allocate2D<Vector4>(width, source.Height))
using (Buffer2D<Vector4> firstPassPixels = source.MemoryAllocator.Allocate2D<Vector4>(width, source.Height))
{
firstPassPixels.Buffer.Clear();

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

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

4
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]

2
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<float>(values.Length, 1);
buffers[i] = Configuration.Default.MemoryAllocator.Allocate2D<float>(values.Length, 1);
}
return buffers;

4
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<TPixel>(this.Count);
this.source = Configuration.Default.MemoryManager.Allocate<Vector4>(this.Count);
this.destination = Configuration.Default.MemoryAllocator.Allocate<TPixel>(this.Count);
this.source = Configuration.Default.MemoryAllocator.Allocate<Vector4>(this.Count);
}
[GlobalCleanup]

4
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<TPixel>(this.Count);
this.source = Configuration.Default.MemoryManager.Allocate<byte>(this.Count * 4);
this.destination = Configuration.Default.MemoryAllocator.Allocate<TPixel>(this.Count);
this.source = Configuration.Default.MemoryAllocator.Allocate<byte>(this.Count * 4);
}
[GlobalCleanup]

4
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<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<Vector4>(this.Count);
this.source = Configuration.Default.MemoryAllocator.Allocate<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryAllocator.Allocate<Vector4>(this.Count);
}
[GlobalCleanup]

4
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<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<byte>(this.Count * 3);
this.source = Configuration.Default.MemoryAllocator.Allocate<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryAllocator.Allocate<byte>(this.Count * 3);
}
[GlobalCleanup]

4
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<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryManager.Allocate<byte>(this.Count * 4);
this.source = Configuration.Default.MemoryAllocator.Allocate<TPixel>(this.Count);
this.destination = Configuration.Default.MemoryAllocator.Allocate<byte>(this.Count * 4);
}
[GlobalCleanup]

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

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Benchmarks
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3))
using (IBuffer<Vector4> buffer = Configuration.Default.MemoryAllocator.Allocate<Vector4>(destination.Length * 3))
{
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
using (IBuffer<float> amounts = Configuration.Default.MemoryManager.Allocate<float>(image.Width))
using (IBuffer<float> amounts = Configuration.Default.MemoryAllocator.Allocate<float>(image.Width))
{
amounts.Span.Fill(1);
@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
using (IBuffer<float> amounts = Configuration.Default.MemoryManager.Allocate<float>(image.Width))
using (IBuffer<float> amounts = Configuration.Default.MemoryAllocator.Allocate<float>(image.Width))
{
amounts.Span.Fill(1);
using (PixelAccessor<Rgba32> pixels = image.Lock())

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

@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Benchmarks
}
int width = maxX - minX;
using (IBuffer<TPixel> rowColors = Configuration.Default.MemoryManager.Allocate<TPixel>(width))
using (IBuffer<TPixel> rowColors = Configuration.Default.MemoryAllocator.Allocate<TPixel>(width))
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{
rowColors.Span.Fill(glowColor);

2
tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced
}
}
class TestMemoryManager<TPixel> : System.Buffers.MemoryManager<TPixel>
class TestMemoryManager<TPixel> : MemoryManager<TPixel>
{
public TestMemoryManager(TPixel[] pixelArray)
{

2
tests/ImageSharp.Tests/FakeImageOperationsProvider.cs

@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests
public List<AppliedOperation> Applied { get; } = new List<AppliedOperation>();
public MemoryManager MemoryManager => this.Source.GetConfiguration().MemoryManager;
public MemoryAllocator MemoryAllocator => this.Source.GetConfiguration().MemoryAllocator;
public Image<TPixel> Apply()
{

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

@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests
public void QuantizeImageShouldPreserveMaximumColorPrecision<TPixel>(TestImageProvider<TPixel> provider, string quantizerName)
where TPixel : struct, IPixel<TPixel>
{
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");

4
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<float>(20, 20))
using (var buffer = Configuration.Default.MemoryAllocator.Allocate2D<float>(20, 20))
{
BufferArea<float> 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<float>(100, 100))
using (var buffer = Configuration.Default.MemoryAllocator.Allocate2D<float>(100, 100))
{
BufferArea<float> area = buffer.GetArea(start.X, start.Y, 8 * horizontalFactor, 8 * verticalFactor);
block.CopyTo(area, horizontalFactor, verticalFactor);

12
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;

4
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<TPixel> 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]

4
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<TPixel> 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]

4
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<TPixel> 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<TPixel>(Image<TPixel> image, TestImageProvider<TPixel> provider)

4
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<Rgba32>(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<Rgba32>(decoder.ImageWidth, decoder.ImageHeight))
{
pp.PostProcess(image.Frames.RootFrame);

2
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<Block8x8>(this.WidthInBlocks, this.HeightInBlocks);
this.SpectralBlocks = Configuration.Default.MemoryAllocator.Allocate2D<Block8x8>(this.WidthInBlocks, this.HeightInBlocks);
}
public Size Size => new Size(this.WidthInBlocks, this.HeightInBlocks);

38
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);
/// <summary>
/// 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<T>(int length)
where T : struct
{
IBuffer<T> buffer = this.MemoryManager.Allocate<T>(length);
IBuffer<T> buffer = this.MemoryAllocator.Allocate<T>(length);
ref T ptrToPrevPosition0 = ref buffer.GetReference();
buffer.Dispose();
buffer = this.MemoryManager.Allocate<T>(length);
buffer = this.MemoryAllocator.Allocate<T>(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<Exception>(() => { new ArrayPoolMemoryManager(100, 200); });
Assert.ThrowsAny<Exception>(() => { new ArrayPoolMemoryAllocator(100, 200); });
}
}
@ -130,12 +130,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(true)]
public void CleaningRequests_AreControlledByAllocationParameter_Clean(bool clean)
{
using (IBuffer<int> firstAlloc = this.MemoryManager.Allocate<int>(42))
using (IBuffer<int> firstAlloc = this.MemoryAllocator.Allocate<int>(42))
{
firstAlloc.GetSpan().Fill(666);
}
using (IBuffer<int> secondAlloc = this.MemoryManager.Allocate<int>(42, clean))
using (IBuffer<int> secondAlloc = this.MemoryAllocator.Allocate<int>(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<int> buffer = this.MemoryManager.Allocate<int>(32);
IBuffer<int> buffer = this.MemoryAllocator.Allocate<int>(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<int>(32);
buffer = this.MemoryAllocator.Allocate<int>(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<int> buffer = this.MemoryManager.Allocate<int>(32);
this.MemoryManager.ReleaseRetainedResources();
IBuffer<int> buffer = this.MemoryAllocator.Allocate<int>(32);
this.MemoryAllocator.ReleaseRetainedResources();
buffer.Dispose();
}
@ -181,11 +181,11 @@ namespace SixLabors.ImageSharp.Tests.Memory
int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int);
IBuffer<int> small = this.MemoryManager.Allocate<int>(arrayLengthThreshold - 1);
IBuffer<int> small = this.MemoryAllocator.Allocate<int>(arrayLengthThreshold - 1);
ref int ptr2Small = ref small.GetReference();
small.Dispose();
IBuffer<int> large = this.MemoryManager.Allocate<int>(arrayLengthThreshold + 1);
IBuffer<int> large = this.MemoryAllocator.Allocate<int>(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<Rgba32>(4096 * 4096));
}
@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
return;
}
this.MemoryManager = ArrayPoolMemoryManager.CreateDefault();
this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault();
Assert.False(this.CheckIsRentingPooledBuffer<Rgba32>(2 * 4096 * 4096));
Assert.True(this.CheckIsRentingPooledBuffer<Rgba32>(2048 * 2048));
@ -228,7 +228,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
return;
}
this.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling();
this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling();
Assert.False(this.CheckIsRentingPooledBuffer<Rgba32>(2048 * 2048));
Assert.True(this.CheckIsRentingPooledBuffer<Rgba32>(1024 * 16));

18
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<T> Allocate<T>(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<TestStructs.Foo> buffer = this.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = this.MemoryAllocator.Allocate2D<TestStructs.Foo>(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<int> buffer = this.MemoryManager.Allocate2D<int>(42, 42, true))
using (Buffer2D<int> buffer = this.MemoryAllocator.Allocate2D<int>(42, 42, true))
{
Span<int> 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<TestStructs.Foo> buffer = this.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = this.MemoryAllocator.Allocate2D<TestStructs.Foo>(width, height))
{
Span<TestStructs.Foo> 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<TestStructs.Foo> buffer = this.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = this.MemoryAllocator.Allocate2D<TestStructs.Foo>(width, height))
{
Span<TestStructs.Foo> 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<TestStructs.Foo> buffer = this.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
using (Buffer2D<TestStructs.Foo> buffer = this.MemoryAllocator.Allocate2D<TestStructs.Foo>(width, height))
{
Span<TestStructs.Foo> span = buffer.Buffer.GetSpan();
@ -132,8 +132,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void SwapContents()
{
using (Buffer2D<int> a = this.MemoryManager.Allocate2D<int>(10, 5))
using (Buffer2D<int> b = this.MemoryManager.Allocate2D<int>(3, 7))
using (Buffer2D<int> a = this.MemoryAllocator.Allocate2D<int>(10, 5))
using (Buffer2D<int> b = this.MemoryAllocator.Allocate2D<int>(3, 7))
{
IBuffer<int> aa = a.Buffer;
IBuffer<int> bb = b.Buffer;

4
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<int>(10, 20))
using (var buffer = Configuration.Default.MemoryAllocator.Allocate2D<int>(10, 20))
{
var rectangle = new Rectangle(3,2, 5, 6);
var area = new BufferArea<int>(buffer, rectangle);
@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
private static Buffer2D<int> CreateTestBuffer(int w, int h)
{
var buffer = Configuration.Default.MemoryManager.Allocate2D<int>(w, h);
var buffer = Configuration.Default.MemoryAllocator.Allocate2D<int>(w, h);
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)

20
tests/ImageSharp.Tests/Memory/BufferTestSuite.cs

@ -13,16 +13,16 @@ namespace SixLabors.ImageSharp.Tests.Memory
using System.Buffers;
/// <summary>
/// Inherit this class to test an <see cref="IBuffer{T}"/> implementation (provided by <see cref="MemoryManager"/>).
/// Inherit this class to test an <see cref="IBuffer{T}"/> implementation (provided by <see cref="MemoryAllocator"/>).
/// </summary>
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<CustomStruct>
{
@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
private void TestHasCorrectLength<T>(int desiredLength)
where T : struct
{
using (IBuffer<T> buffer = this.MemoryManager.Allocate<T>(desiredLength))
using (IBuffer<T> buffer = this.MemoryAllocator.Allocate<T>(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<T> buffer))
if (!(this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength, clean) is IBuffer<T> buffer))
{
throw new InvalidOperationException("typeof(T) != typeof(byte)");
}
@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
return buffer;
}
return this.MemoryManager.Allocate<T>(desiredLength, clean);
return this.MemoryAllocator.Allocate<T>(desiredLength, clean);
}
private void TestCanAllocateCleanBuffer<T>(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<CustomStruct> buffer = this.MemoryManager.Allocate<CustomStruct>(42))
using (IBuffer<CustomStruct> buffer = this.MemoryAllocator.Allocate<CustomStruct>(42))
{
Span<CustomStruct> span0 = buffer.GetSpan();
span0[10].A = 30;
@ -303,7 +303,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public unsafe void GetMemory_ResultIsPinnable()
{
using (IBuffer<int> buffer = this.MemoryManager.Allocate<int>(42))
using (IBuffer<int> buffer = this.MemoryAllocator.Allocate<int>(42))
{
Span<int> span0 = buffer.GetSpan();
span0[10] = 30;

2
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())
{
}
}

20
tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs

@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Normal().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Multiply().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Add().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Subtract().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Screen().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Darken().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Lighten().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.Overlay().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.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<TPixel>
{
Span<TPixel> dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.HardLight().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
new DefaultPixelBlenders<TPixel>.HardLight().Blend(this.MemoryAllocator, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2);
}
}

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

@ -56,8 +56,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
int times = 200000;
int count = 1024;
using (IBuffer<ImageSharp.PixelFormats.Rgba32> source = Configuration.Default.MemoryManager.Allocate<ImageSharp.PixelFormats.Rgba32>(count))
using (IBuffer<Vector4> dest = Configuration.Default.MemoryManager.Allocate<Vector4>(count))
using (IBuffer<ImageSharp.PixelFormats.Rgba32> source = Configuration.Default.MemoryAllocator.Allocate<ImageSharp.PixelFormats.Rgba32>(count))
using (IBuffer<Vector4> dest = Configuration.Default.MemoryAllocator.Allocate<Vector4>(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<TDest>(expectedDest.Length);
this.ActualDestBuffer = Configuration.Default.MemoryAllocator.Allocate<TDest>(expectedDest.Length);
}
public void Dispose()

2
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<Rgba32>(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();

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

@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
var image = new Image<TPixel>(w, h);
using (IBuffer<Bgra32> workBuffer = Configuration.Default.MemoryManager.Allocate<Bgra32>(w))
using (IBuffer<Bgra32> workBuffer = Configuration.Default.MemoryAllocator.Allocate<Bgra32>(w))
{
fixed (Bgra32* destPtr = &workBuffer.GetReference())
{
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
var image = new Image<TPixel>(w, h);
using (IBuffer<Bgr24> workBuffer = Configuration.Default.MemoryManager.Allocate<Bgr24>(w))
using (IBuffer<Bgr24> workBuffer = Configuration.Default.MemoryAllocator.Allocate<Bgr24>(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<Bgra32> workBuffer = image.GetConfiguration().MemoryManager.Allocate<Bgra32>(w))
using (IBuffer<Bgra32> workBuffer = image.GetConfiguration().MemoryAllocator.Allocate<Bgra32>(w))
{
fixed (Bgra32* sourcePtr = &workBuffer.GetReference())
{

4
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -27,11 +27,11 @@ namespace SixLabors.ImageSharp.Tests
public static void MakeOpaque<TPixel>(this IImageProcessingContext<TPixel> ctx)
where TPixel : struct, IPixel<TPixel>
{
MemoryManager memoryManager = ctx.MemoryManager;
MemoryAllocator memoryAllocator = ctx.MemoryAllocator;
ctx.Apply(img =>
{
using (Buffer2D<Vector4> temp = memoryManager.Allocate2D<Vector4>(img.Width, img.Height))
using (Buffer2D<Vector4> temp = memoryAllocator.Allocate2D<Vector4>(img.Width, img.Height))
{
Span<Vector4> tempSpan = temp.GetSpan();
foreach (ImageFrame<TPixel> frame in img.Frames)

Loading…
Cancel
Save