Browse Source

MemoryManager returns IBuffer<T> now

pull/475/head
Anton Firszov 8 years ago
parent
commit
77e524d83b
  1. 4
      src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
  2. 4
      src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
  3. 4
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  4. 4
      src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
  5. 4
      src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
  6. 2
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  7. 2
      src/ImageSharp.Drawing/Processors/FillProcessor.cs
  8. 6
      src/ImageSharp/Formats/Gif/LzwDecoder.cs
  9. 4
      src/ImageSharp/Formats/Gif/LzwEncoder.cs
  10. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs
  11. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs
  12. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponent.cs
  13. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  14. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs
  15. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  16. 11
      src/ImageSharp/Memory/ArrayPoolMemoryManager.cs
  17. 4
      src/ImageSharp/Memory/Buffer{T}.cs
  18. 14
      src/ImageSharp/Memory/IGetArray.cs
  19. 2
      src/ImageSharp/Memory/MemoryManager.cs
  20. 6
      src/ImageSharp/Memory/MemoryManagerExtensions.cs
  21. 2
      src/ImageSharp/Memory/SimpleManagedMemoryManager.cs
  22. 42
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
  23. 2
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
  24. 4
      src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
  25. 26
      src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs
  26. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
  27. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs
  28. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs
  29. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
  30. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
  31. 6
      tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs
  32. 2
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  33. 4
      tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs
  34. 6
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  35. 6
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs

4
src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs

@ -122,8 +122,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
internal override void Apply(Span<float> scanline, int x, int y) internal override void Apply(Span<float> scanline, int x, int y)
{ {
// Create a span for colors // Create a span for colors
using (Buffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length))
using (Buffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.Span;
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.Span;

4
src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs

@ -152,8 +152,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
internal override void Apply(Span<float> scanline, int x, int y) internal override void Apply(Span<float> scanline, int x, int y)
{ {
int patternY = y % this.pattern.Height; int patternY = y % this.pattern.Height;
using (Buffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length))
using (Buffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.Span;
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.Span;

4
src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs

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

4
src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs

@ -144,8 +144,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <inheritdoc /> /// <inheritdoc />
internal override void Apply(Span<float> scanline, int x, int y) internal override void Apply(Span<float> scanline, int x, int y)
{ {
using (Buffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length))
using (Buffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.Span;
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.Span;

4
src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs

@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// Gets the colors. /// Gets the colors.
/// </summary> /// </summary>
protected Buffer<TPixel> Colors { get; } protected IBuffer<TPixel> Colors { get; }
/// <summary> /// <summary>
/// Gets the color for a single pixel. /// Gets the color for a single pixel.
@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
{ {
Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
using (Buffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.Span;

2
src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs

@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
maxY = Math.Min(this.Location.Y + this.Size.Height, maxY); maxY = Math.Min(this.Location.Y + this.Size.Height, maxY);
int width = maxX - minX; int width = maxX - minX;
using (Buffer<float> amount = this.Image.GetConfiguration().MemoryManager.Allocate<float>(width)) using (IBuffer<float> amount = this.Image.GetConfiguration().MemoryManager.Allocate<float>(width))
{ {
amount.Span.Fill(this.Alpha); amount.Span.Fill(this.Alpha);

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

@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
int width = maxX - minX; int width = maxX - minX;
using (Buffer<float> amount = source.MemoryManager.Allocate<float>(width)) using (IBuffer<float> amount = source.MemoryManager.Allocate<float>(width))
using (BrushApplicator<TPixel> applicator = this.brush.CreateApplicator( using (BrushApplicator<TPixel> applicator = this.brush.CreateApplicator(
source, source,
sourceRectangle, sourceRectangle,

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

@ -32,17 +32,17 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// The prefix buffer. /// The prefix buffer.
/// </summary> /// </summary>
private readonly Buffer<int> prefix; private readonly IBuffer<int> prefix;
/// <summary> /// <summary>
/// The suffix buffer. /// The suffix buffer.
/// </summary> /// </summary>
private readonly Buffer<int> suffix; private readonly IBuffer<int> suffix;
/// <summary> /// <summary>
/// The pixel stack buffer. /// The pixel stack buffer.
/// </summary> /// </summary>
private readonly Buffer<int> pixelStack; private readonly IBuffer<int> pixelStack;
/// <summary> /// <summary>
/// A value indicating whether this instance of the given entity has been disposed. /// A value indicating whether this instance of the given entity has been disposed.

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

@ -71,12 +71,12 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// The hash table. /// The hash table.
/// </summary> /// </summary>
private readonly Buffer<int> hashTable; private readonly IBuffer<int> hashTable;
/// <summary> /// <summary>
/// The code table. /// The code table.
/// </summary> /// </summary>
private readonly Buffer<int> codeTable; private readonly IBuffer<int> codeTable;
/// <summary> /// <summary>
/// Define the storage for the packet accumulator. /// Define the storage for the packet accumulator.

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
/// <summary> /// <summary>
/// Temporal buffer to store a row of colors. /// Temporal buffer to store a row of colors.
/// </summary> /// </summary>
private readonly Buffer<Vector4> rgbaBuffer; private readonly IBuffer<Vector4> rgbaBuffer;
/// <summary> /// <summary>
/// The <see cref="ColorConverters.JpegColorConverter"/> corresponding to the current <see cref="JpegColorSpace"/> determined by <see cref="IRawJpegData.ColorSpace"/>. /// The <see cref="ColorConverters.JpegColorConverter"/> corresponding to the current <see cref="JpegColorSpace"/> determined by <see cref="IRawJpegData.ColorSpace"/>.

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs

@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <summary> /// <summary>
/// Values of <see cref="Buffer"/> converted to <see cref="int"/>-s /// Values of <see cref="Buffer"/> converted to <see cref="int"/>-s
/// </summary> /// </summary>
public Buffer<int> BufferAsInt; public IBuffer<int> BufferAsInt;
/// <summary> /// <summary>
/// Start of bytes read /// Start of bytes read

2
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponent.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <summary> /// <summary>
/// Gets or sets the output /// Gets or sets the output
/// </summary> /// </summary>
public Buffer<short> Output; public IBuffer<short> Output;
/// <summary> /// <summary>
/// Gets or sets the scaling factors /// Gets or sets the scaling factors

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

@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <summary> /// <summary>
/// Gets the block data /// Gets the block data
/// </summary> /// </summary>
public Buffer<short> BlockData { get; private set; } public IBuffer<short> BlockData { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public int Index { get; } public int Index { get; }

2
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
private readonly int imageHeight; private readonly int imageHeight;
private Buffer<byte> componentData; private IBuffer<byte> componentData;
private int rowStride; private int rowStride;

4
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -786,8 +786,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
{ {
int blocksPerLine = component.BlocksPerLine; int blocksPerLine = component.BlocksPerLine;
int blocksPerColumn = component.BlocksPerColumn; int blocksPerColumn = component.BlocksPerColumn;
using (Buffer<short> computationBuffer = this.configuration.MemoryManager.Allocate<short>(64, true)) using (IBuffer<short> computationBuffer = this.configuration.MemoryManager.Allocate<short>(64, true))
using (Buffer<short> multiplicationBuffer = this.configuration.MemoryManager.Allocate<short>(64, true)) using (IBuffer<short> multiplicationBuffer = this.configuration.MemoryManager.Allocate<short>(64, true))
{ {
Span<short> quantizationTable = this.quantizationTables.Tables.GetRowSpan(frameComponent.QuantizationTableIndex); Span<short> quantizationTable = this.quantizationTables.Tables.GetRowSpan(frameComponent.QuantizationTableIndex);
Span<short> computationBufferSpan = computationBuffer.Span; Span<short> computationBufferSpan = computationBuffer.Span;

11
src/ImageSharp/Memory/ArrayPoolMemoryManager.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Memory
} }
/// <inheritdoc /> /// <inheritdoc />
internal override Buffer<T> Allocate<T>(int length, bool clear) internal override IBuffer<T> Allocate<T>(int length, bool clear)
{ {
int itemSizeBytes = Unsafe.SizeOf<T>(); int itemSizeBytes = Unsafe.SizeOf<T>();
int bufferSizeInBytes = length * itemSizeBytes; int bufferSizeInBytes = length * itemSizeBytes;
@ -68,7 +68,14 @@ namespace SixLabors.ImageSharp.Memory
/// <inheritdoc /> /// <inheritdoc />
internal override void Release<T>(Buffer<T> buffer) internal override void Release<T>(Buffer<T> buffer)
{ {
byte[] byteBuffer = Unsafe.As<byte[]>(buffer.GetArray()); T[] array = (buffer as IGetArray<T>)?.GetArray();
if (array == null)
{
return;
}
// TODO: OMG Do not do this!
byte[] byteBuffer = Unsafe.As<byte[]>(array);
this.pool.Return(byteBuffer); this.pool.Return(byteBuffer);
} }
} }

4
src/ImageSharp/Memory/Buffer{T}.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Memory
/// The backing array is either pooled or comes from the outside. /// The backing array is either pooled or comes from the outside.
/// </summary> /// </summary>
/// <typeparam name="T">The value type.</typeparam> /// <typeparam name="T">The value type.</typeparam>
internal class Buffer<T> : IBuffer<T> internal class Buffer<T> : IBuffer<T>, IGetArray<T>
where T : struct where T : struct
{ {
private MemoryManager memoryManager; private MemoryManager memoryManager;
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Memory
/// <summary> /// <summary>
/// TODO: Refactor this /// TODO: Refactor this
/// </summary> /// </summary>
internal T[] GetArray() T[] IGetArray<T>.GetArray()
{ {
return this.array; return this.array;
} }

14
src/ImageSharp/Memory/IGetArray.cs

@ -0,0 +1,14 @@
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Absolutely temporal.
/// </summary>
internal interface IGetArray<T>
where T : struct
{
/// <summary>
/// Absolutely temporal.
/// </summary>
T[] GetArray();
}
}

2
src/ImageSharp/Memory/MemoryManager.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Memory
/// <param name="length">Size of the buffer to allocate</param> /// <param name="length">Size of the buffer to allocate</param>
/// <param name="clear">True to clear the backing memory of the buffer</param> /// <param name="clear">True to clear the backing memory of the buffer</param>
/// <returns>A buffer of values of type <typeparamref name="T"/>.</returns> /// <returns>A buffer of values of type <typeparamref name="T"/>.</returns>
internal abstract Buffer<T> Allocate<T>(int length, bool clear) internal abstract IBuffer<T> Allocate<T>(int length, bool clear)
where T : struct; where T : struct;
internal abstract IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear); internal abstract IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear);

6
src/ImageSharp/Memory/MemoryManagerExtensions.cs

@ -14,13 +14,13 @@
/// <param name="memoryManager">The <see cref="MemoryManager"/></param> /// <param name="memoryManager">The <see cref="MemoryManager"/></param>
/// <param name="length">Size of the buffer to allocate</param> /// <param name="length">Size of the buffer to allocate</param>
/// <returns>A buffer of values of type <typeparamref name="T"/>.</returns> /// <returns>A buffer of values of type <typeparamref name="T"/>.</returns>
public static Buffer<T> Allocate<T>(this MemoryManager memoryManager, int length) public static IBuffer<T> Allocate<T>(this MemoryManager memoryManager, int length)
where T : struct where T : struct
{ {
return memoryManager.Allocate<T>(length, false); return memoryManager.Allocate<T>(length, false);
} }
public static Buffer<T> AllocateClean<T>(this MemoryManager memoryManager, int length) public static IBuffer<T> AllocateClean<T>(this MemoryManager memoryManager, int length)
where T : struct where T : struct
{ {
return memoryManager.Allocate<T>(length, true); return memoryManager.Allocate<T>(length, true);
@ -39,7 +39,7 @@
public static Buffer2D<T> Allocate2D<T>(this MemoryManager memoryManager, int width, int height, bool clear) public static Buffer2D<T> Allocate2D<T>(this MemoryManager memoryManager, int width, int height, bool clear)
where T : struct where T : struct
{ {
Buffer<T> buffer = memoryManager.Allocate<T>(width * height, clear); IBuffer<T> buffer = memoryManager.Allocate<T>(width * height, clear);
return new Buffer2D<T>(buffer, width, height); return new Buffer2D<T>(buffer, width, height);
} }

2
src/ImageSharp/Memory/SimpleManagedMemoryManager.cs

@ -6,7 +6,7 @@
public class SimpleManagedMemoryManager : MemoryManager public class SimpleManagedMemoryManager : MemoryManager
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override Buffer<T> Allocate<T>(int length, bool clear) internal override IBuffer<T> Allocate<T>(int length, bool clear)
{ {
return new Buffer<T>(new T[length], length, this); return new Buffer<T>(new T[length], length, this);
} }

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

@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -201,7 +201,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -318,7 +318,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -357,7 +357,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -396,7 +396,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -435,7 +435,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -474,7 +474,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -513,7 +513,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -552,7 +552,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -591,7 +591,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -630,7 +630,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -669,7 +669,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -708,7 +708,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -747,7 +747,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -786,7 +786,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
@ -825,7 +825,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);

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

@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));
using (Buffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3)) using (IBuffer<Vector4> buffer = Configuration.Default.MemoryManager.Allocate<Vector4>(destination.Length * 3, false))
{ {
Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length); Span<Vector4> destinationSpan = buffer.Slice(0, destination.Length);
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);

4
src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs

@ -71,8 +71,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
int width = maxX - minX; int width = maxX - minX;
using (Buffer<TPixel> colors = this.memoryManager.Allocate<TPixel>(width)) using (IBuffer<TPixel> colors = this.memoryManager.Allocate<TPixel>(width))
using (Buffer<float> amount = this.memoryManager.Allocate<float>(width)) using (IBuffer<float> amount = this.memoryManager.Allocate<float>(width))
{ {
// Be careful! Do not capture colorSpan & amountSpan in the lambda below! // Be careful! Do not capture colorSpan & amountSpan in the lambda below!
Span<TPixel> colorSpan = colors.Span; Span<TPixel> colorSpan = colors.Span;

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

@ -473,19 +473,19 @@ namespace SixLabors.ImageSharp.Quantizers
Span<long> vmaSpan = this.vma.Span; Span<long> vmaSpan = this.vma.Span;
Span<float> m2Span = this.m2.Span; Span<float> m2Span = this.m2.Span;
using (Buffer<long> volume = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volume = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeR = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volumeR = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeG = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volumeG = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeB = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volumeB = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<long> volumeA = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volumeA = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (Buffer<float> volume2 = memoryManager.Allocate<float>(IndexCount * IndexAlphaCount)) using (IBuffer<float> volume2 = memoryManager.Allocate<float>(IndexCount * IndexAlphaCount))
using (Buffer<long> area = memoryManager.Allocate<long>(IndexAlphaCount)) using (IBuffer<long> area = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaR = memoryManager.Allocate<long>(IndexAlphaCount)) using (IBuffer<long> areaR = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaG = memoryManager.Allocate<long>(IndexAlphaCount)) using (IBuffer<long> areaG = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaB = memoryManager.Allocate<long>(IndexAlphaCount)) using (IBuffer<long> areaB = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<long> areaA = memoryManager.Allocate<long>(IndexAlphaCount)) using (IBuffer<long> areaA = memoryManager.Allocate<long>(IndexAlphaCount))
using (Buffer<float> area2 = memoryManager.Allocate<float>(IndexAlphaCount)) using (IBuffer<float> area2 = memoryManager.Allocate<float>(IndexAlphaCount))
{ {
Span<long> volumeSpan = volume.Span; Span<long> volumeSpan = volume.Span;
Span<long> volumeRSpan = volumeR.Span; Span<long> volumeRSpan = volumeR.Span;

4
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs

@ -13,9 +13,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
public abstract class PackFromVector4<TPixel> public abstract class PackFromVector4<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private Buffer<Vector4> source; private IBuffer<Vector4> source;
private Buffer<TPixel> destination; private IBuffer<TPixel> destination;
[Params(16, 128, 512)] [Params(16, 128, 512)]
public int Count { get; set; } public int Count { get; set; }

4
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs

@ -11,9 +11,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
public abstract class PackFromXyzw<TPixel> public abstract class PackFromXyzw<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private Buffer<TPixel> destination; private IBuffer<TPixel> destination;
private Buffer<byte> source; private IBuffer<byte> source;
[Params(16, 128, 1024)] [Params(16, 128, 1024)]
public int Count { get; set; } public int Count { get; set; }

4
tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs

@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
public abstract class ToVector4<TPixel> public abstract class ToVector4<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private Buffer<TPixel> source; private IBuffer<TPixel> source;
private Buffer<Vector4> destination; private IBuffer<Vector4> destination;
[Params(64, 300, 1024)] [Params(64, 300, 1024)]
public int Count { get; set; } public int Count { get; set; }

4
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs

@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
public abstract class ToXyz<TPixel> public abstract class ToXyz<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private Buffer<TPixel> source; private IBuffer<TPixel> source;
private Buffer<byte> destination; private IBuffer<byte> destination;
[Params(16, 128, 1024)] [Params(16, 128, 1024)]
public int Count { get; set; } public int Count { get; set; }

4
tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs

@ -14,9 +14,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
public abstract class ToXyzw<TPixel> public abstract class ToXyzw<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private Buffer<TPixel> source; private IBuffer<TPixel> source;
private Buffer<byte> destination; private IBuffer<byte> destination;
[Params(16, 128, 1024)] [Params(16, 128, 1024)]
public int Count { get; set; } public int Count { get; set; }

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

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

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

4
tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs

@ -43,13 +43,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing
public void OverlayByFilledPolygonOpacity<TPixel>(TestImageProvider<TPixel> provider) public void OverlayByFilledPolygonOpacity<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledBezier"); Primitives.PointF[] simplePath = {
SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] {
new Vector2(10, 400), new Vector2(10, 400),
new Vector2(30, 10), new Vector2(30, 10),
new Vector2(240, 30), new Vector2(240, 30),
new Vector2(300, 400) new Vector2(300, 400)
}; };
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (var image = provider.GetImage() as Image<Rgba32>) using (var image = provider.GetImage() as Image<Rgba32>)

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

@ -50,8 +50,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
int times = 200000; int times = 200000;
int count = 1024; int count = 1024;
using (Buffer<ImageSharp.Rgba32> source = Configuration.Default.MemoryManager.Allocate<ImageSharp.Rgba32>(count)) using (IBuffer<ImageSharp.Rgba32> source = Configuration.Default.MemoryManager.Allocate<ImageSharp.Rgba32>(count))
using (Buffer<Vector4> dest = Configuration.Default.MemoryManager.Allocate<Vector4>(count)) using (IBuffer<Vector4> dest = Configuration.Default.MemoryManager.Allocate<Vector4>(count))
{ {
this.Measure( this.Measure(
times, times,
@ -334,7 +334,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
where TDest : struct where TDest : struct
{ {
public TSource[] SourceBuffer { get; } public TSource[] SourceBuffer { get; }
public Buffer<TDest> ActualDestBuffer { get; } public IBuffer<TDest> ActualDestBuffer { get; }
public TDest[] ExpectedDestBuffer { get; } public TDest[] ExpectedDestBuffer { get; }
public TestBuffers(TSource[] source, TDest[] expectedDest) public TestBuffers(TSource[] source, TDest[] expectedDest)

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

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
int length = source.Length; int length = source.Length;
Guard.MustBeSizedAtLeast(dest, length, nameof(dest)); Guard.MustBeSizedAtLeast(dest, length, nameof(dest));
using (Buffer<Rgba32> rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(length)) using (IBuffer<Rgba32> rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(length))
{ {
Span<Rgba32> rgbaSpan = rgbaBuffer.Span; Span<Rgba32> rgbaSpan = rgbaBuffer.Span;
PixelOperations<TPixel>.Instance.ToRgba32(source, rgbaSpan, length); PixelOperations<TPixel>.Instance.ToRgba32(source, rgbaSpan, length);
@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
int length = source.Length; int length = source.Length;
Guard.MustBeSizedAtLeast(dest, length, nameof(dest)); Guard.MustBeSizedAtLeast(dest, length, nameof(dest));
using (Buffer<Rgba32> rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(length)) using (IBuffer<Rgba32> rgbaBuffer = Configuration.Default.MemoryManager.Allocate<Rgba32>(length))
{ {
Span<Rgba32> rgbaSpan = rgbaBuffer.Span; Span<Rgba32> rgbaSpan = rgbaBuffer.Span;
PixelOperations<Argb32>.Instance.ToRgba32(source, rgbaSpan, length); PixelOperations<Argb32>.Instance.ToRgba32(source, rgbaSpan, length);
@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
int length = source.Length; int length = source.Length;
Guard.MustBeSizedAtLeast(dest, length, nameof(dest)); Guard.MustBeSizedAtLeast(dest, length, nameof(dest));
using (Buffer<Rgb24> rgbBuffer = Configuration.Default.MemoryManager.Allocate<Rgb24>(length)) using (IBuffer<Rgb24> rgbBuffer = Configuration.Default.MemoryManager.Allocate<Rgb24>(length))
{ {
Span<Rgb24> rgbSpan = rgbBuffer.Span; Span<Rgb24> rgbSpan = rgbBuffer.Span;
PixelOperations<Rgb24>.Instance.ToRgb24(source, rgbSpan, length); PixelOperations<Rgb24>.Instance.ToRgb24(source, rgbSpan, length);

Loading…
Cancel
Save