diff --git a/src/ImageSharp.Drawing/Primitives/Region.cs b/src/ImageSharp.Drawing/Primitives/Region.cs
index c85e373fb..27f039f12 100644
--- a/src/ImageSharp.Drawing/Primitives/Region.cs
+++ b/src/ImageSharp.Drawing/Primitives/Region.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Primitives
@@ -19,7 +20,7 @@ namespace SixLabors.ImageSharp.Primitives
/// Gets the bounding box that entirely surrounds this region.
///
///
- /// This should always contains all possible points returned from .
+ /// This should always contains all possible points returned from .
///
public abstract Rectangle Bounds { get; }
@@ -28,8 +29,8 @@ namespace SixLabors.ImageSharp.Primitives
///
/// The position along the y axis to find intersections.
/// The buffer.
- /// The point in the buffer to start setting offset.
+ /// A instance in the context of the caller.
/// The number of intersections found.
- public abstract int Scan(float y, float[] buffer, int offset);
+ public abstract int Scan(float y, Span buffer, Configuration configuration);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
index cfd1945d0..9f5611dc0 100644
--- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
+++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
+using SixLabors.Memory;
using SixLabors.Primitives;
using SixLabors.Shapes;
@@ -39,21 +40,23 @@ namespace SixLabors.ImageSharp.Primitives
public override Rectangle Bounds { get; }
///
- public override int Scan(float y, float[] buffer, int offset)
+ public override int Scan(float y, Span buffer, Configuration configuration)
{
var start = new PointF(this.Bounds.Left - 1, y);
var end = new PointF(this.Bounds.Right + 1, y);
- // TODO: This is a temporary workaround because of the lack of Span API-s on IPath. We should use MemoryManager.Allocate() here!
- var innerBuffer = new PointF[buffer.Length];
- int count = this.Shape.FindIntersections(start, end, innerBuffer, 0);
-
- for (int i = 0; i < count; i++)
+ using (IBuffer tempBuffer = configuration.MemoryAllocator.Allocate(buffer.Length))
{
- buffer[i + offset] = innerBuffer[i].X;
- }
+ Span innerBuffer = tempBuffer.GetSpan();
+ int count = this.Shape.FindIntersections(start, end, innerBuffer);
- return count;
+ for (int i = 0; i < count; i++)
+ {
+ buffer[i] = innerBuffer[i].X;
+ }
+
+ return count;
+ }
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs
index c54666335..7672681da 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs
@@ -3,8 +3,8 @@
using System;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
@@ -65,13 +65,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
/// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.
internal virtual void Apply(Span scanline, int x, int y)
{
- MemoryManager memoryManager = this.Target.MemoryManager;
+ MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
- using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length))
- using (IBuffer overlay = memoryManager.Allocate(scanline.Length))
+ using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length))
+ using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length))
{
- Span amountSpan = amountBuffer.Span;
- Span overlaySpan = overlay.Span;
+ Span amountSpan = amountBuffer.GetSpan();
+ Span overlaySpan = overlay.GetSpan();
for (int i = 0; i < scanline.Length; i++)
{
@@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan);
+ this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan);
}
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs
index c2e3a16ef..779848856 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs
@@ -3,8 +3,8 @@
using System;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
@@ -118,11 +118,11 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
internal override void Apply(Span scanline, int x, int y)
{
// Create a span for colors
- using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length))
- using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length))
+ using (IBuffer amountBuffer = this.Target.MemoryAllocator.Allocate(scanline.Length))
+ using (IBuffer overlay = this.Target.MemoryAllocator.Allocate(scanline.Length))
{
- Span amountSpan = amountBuffer.Span;
- Span overlaySpan = overlay.Span;
+ Span amountSpan = amountBuffer.GetSpan();
+ Span overlaySpan = overlay.GetSpan();
int sourceY = (y - this.offsetY) % this.yLength;
int offsetX = x - this.offsetX;
@@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(this.source.MemoryManager, destinationRow, destinationRow, overlaySpan, amountSpan);
+ this.Blender.Blend(this.source.MemoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan);
}
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs
index 765f2a132..21f2066fb 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs
@@ -4,9 +4,9 @@
using System;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
@@ -151,13 +151,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
internal override void Apply(Span scanline, int x, int y)
{
int patternY = y % this.pattern.Rows;
- MemoryManager memoryManager = this.Target.MemoryManager;
+ MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
- using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length))
- using (IBuffer overlay = memoryManager.Allocate(scanline.Length))
+ using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length))
+ using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length))
{
- Span amountSpan = amountBuffer.Span;
- Span overlaySpan = overlay.Span;
+ Span amountSpan = amountBuffer.GetSpan();
+ Span overlaySpan = overlay.GetSpan();
for (int i = 0; i < scanline.Length; i++)
{
@@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan);
+ this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan);
}
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs
index 324c54e18..a7da2cc5b 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs
@@ -4,8 +4,8 @@
using System;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
@@ -136,13 +136,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
///
internal override void Apply(Span scanline, int x, int y)
{
- MemoryManager memoryManager = this.Target.MemoryManager;
+ MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
- using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length))
- using (IBuffer overlay = memoryManager.Allocate(scanline.Length))
+ using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length))
+ using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length))
{
- Span amountSpan = amountBuffer.Span;
- Span overlaySpan = overlay.Span;
+ Span amountSpan = amountBuffer.GetSpan();
+ Span overlaySpan = overlay.GetSpan();
for (int i = 0; i < scanline.Length; i++)
{
@@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
}
Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan);
+ this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, overlaySpan, amountSpan);
}
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs
index f2054ee0d..791c307bf 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs
@@ -3,8 +3,8 @@
using System;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
@@ -58,8 +58,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
public SolidBrushApplicator(ImageFrame source, TPixel color, GraphicsOptions options)
: base(source, options)
{
- this.Colors = source.MemoryManager.Allocate(source.Width);
- this.Colors.Span.Fill(color);
+ this.Colors = source.MemoryAllocator.Allocate(source.Width);
+ this.Colors.GetSpan().Fill(color);
}
///
@@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
///
/// The color
///
- internal override TPixel this[int x, int y] => this.Colors.Span[x];
+ internal override TPixel this[int x, int y] => this.Colors.GetSpan()[x];
///
public override void Dispose()
@@ -88,24 +88,24 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- MemoryManager memoryManager = this.Target.MemoryManager;
+ MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
if (this.Options.BlendPercentage == 1f)
{
- this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, scanline);
+ this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), scanline);
}
else
{
- using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length))
+ using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length))
{
- Span amountSpan = amountBuffer.Span;
+ Span amountSpan = amountBuffer.GetSpan();
for (int i = 0; i < scanline.Length; i++)
{
amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
}
- this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan);
+ this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan);
}
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs
index 7b6e36d9d..506df3886 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs
@@ -4,9 +4,9 @@
using System;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Processors
@@ -133,11 +133,11 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
int width = maxX - minX;
- MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager;
+ MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator;
- using (IBuffer amount = memoryManager.Allocate(width))
+ using (IBuffer amount = memoryAllocator.Allocate(width))
{
- amount.Span.Fill(this.Opacity);
+ amount.GetSpan().Fill(this.Opacity);
Parallel.For(
minY,
@@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{
Span background = source.GetPixelRowSpan(y).Slice(minX, width);
Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
- blender.Blend(memoryManager, background, background, foreground, amount.Span);
+ blender.Blend(memoryAllocator, background, background, foreground, amount.GetSpan());
});
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs
index 645ff0353..4214041a7 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs
@@ -4,10 +4,10 @@
using System;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Processors;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Processors
@@ -77,13 +77,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
startY = 0;
}
- using (IBuffer amount = source.MemoryManager.Allocate(width))
+ using (IBuffer amount = source.MemoryAllocator.Allocate(width))
using (BrushApplicator applicator = this.brush.CreateApplicator(
source,
sourceRectangle,
this.options))
{
- amount.Span.Fill(1f);
+ amount.GetSpan().Fill(1f);
Parallel.For(
minY,
@@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
int offsetY = y - startY;
int offsetX = minX - startX;
- applicator.Apply(amount.Span, offsetX, offsetY);
+ applicator.Apply(amount.GetSpan(), offsetX, offsetY);
});
}
}
diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
index 6eb6a15d0..598e696ba 100644
--- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
@@ -3,11 +3,11 @@
using System;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Processors;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Processors
@@ -103,36 +103,35 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
using (BrushApplicator applicator = this.Brush.CreateApplicator(source, rect, this.Options))
{
int scanlineWidth = maxX - minX;
- using (BasicArrayBuffer buffer = source.MemoryManager.AllocateFake(maxIntersections))
- using (BasicArrayBuffer scanline = source.MemoryManager.AllocateFake(scanlineWidth))
+ using (IBuffer bBuffer = source.MemoryAllocator.Allocate(maxIntersections))
+ using (IBuffer bScanline = source.MemoryAllocator.Allocate(scanlineWidth))
{
bool scanlineDirty = true;
float subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / subpixelCount;
+
+ Span buffer = bBuffer.GetSpan();
+ Span scanline = bScanline.GetSpan();
+
for (int y = minY; y < maxY; y++)
{
if (scanlineDirty)
{
- // clear the buffer
- for (int x = 0; x < scanlineWidth; x++)
- {
- scanline[x] = 0;
- }
-
+ scanline.Clear();
scanlineDirty = false;
}
float yPlusOne = y + 1;
for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction)
{
- int pointsFound = region.Scan(subPixel + offset, buffer.Array, 0);
+ int pointsFound = region.Scan(subPixel + offset, buffer, configuration);
if (pointsFound == 0)
{
// nothing on this line skip
continue;
}
- QuickSort(new Span(buffer.Array, 0, pointsFound));
+ QuickSort(buffer.Slice(0, pointsFound));
for (int point = 0; point < pointsFound; point += 2)
{
@@ -188,7 +187,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
}
}
- applicator.Apply(scanline.Span, minX, y);
+ applicator.Apply(scanline, minX, y);
}
}
}
@@ -196,31 +195,45 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Swap(Span data, int left, int right)
+ private static void Swap(ref float left, ref float right)
{
- float tmp = data[left];
- data[left] = data[right];
- data[right] = tmp;
+ float tmp = left;
+ left = right;
+ right = tmp;
}
private static void QuickSort(Span data)
{
- QuickSort(data, 0, data.Length - 1);
+ if (data.Length < 2)
+ {
+ return;
+ }
+ else if (data.Length == 2)
+ {
+ if (data[0] > data[1])
+ {
+ Swap(ref data[0], ref data[1]);
+ }
+
+ return;
+ }
+
+ QuickSort(ref data[0], 0, data.Length - 1);
}
- private static void QuickSort(Span data, int lo, int hi)
+ private static void QuickSort(ref float data0, int lo, int hi)
{
if (lo < hi)
{
- int p = Partition(data, lo, hi);
- QuickSort(data, lo, p);
- QuickSort(data, p + 1, hi);
+ int p = Partition(ref data0, lo, hi);
+ QuickSort(ref data0, lo, p);
+ QuickSort(ref data0, p + 1, hi);
}
}
- private static int Partition(Span data, int lo, int hi)
+ private static int Partition(ref float data0, int lo, int hi)
{
- float pivot = data[lo];
+ float pivot = Unsafe.Add(ref data0, lo);
int i = lo - 1;
int j = hi + 1;
while (true)
@@ -229,20 +242,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{
i = i + 1;
}
- while (data[i] < pivot && i < hi);
+ while (Unsafe.Add(ref data0, i) < pivot && i < hi);
do
{
j = j - 1;
}
- while (data[j] > pivot && j > lo);
+ while (Unsafe.Add(ref data0, j) > pivot && j > lo);
if (i >= j)
{
return j;
}
- Swap(data, i, j);
+ Swap(ref Unsafe.Add(ref data0, i), ref Unsafe.Add(ref data0, j));
}
}
}
diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
index cbd8db748..18b1d994b 100644
--- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
+++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
@@ -3,8 +3,8 @@
using System;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Advanced
{
@@ -23,6 +23,52 @@ namespace SixLabors.ImageSharp.Advanced
where TPixel : struct, IPixel
=> GetConfiguration((IConfigurable)source);
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format
+ /// stored in row major order.
+ ///
+ /// The type of the pixel.
+ /// The source.
+ /// The
+ public static Span GetPixelSpan(this ImageFrame source)
+ where TPixel : struct, IPixel
+ => source.GetPixelMemory().Span;
+
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format
+ /// stored in row major order.
+ ///
+ /// The type of the pixel.
+ /// The source.
+ /// The
+ public static Span GetPixelSpan(this Image source)
+ where TPixel : struct, IPixel
+ => source.Frames.RootFrame.GetPixelSpan();
+
+ ///
+ /// Gets the representation of the pixels as a of contiguous memory
+ /// at row beginning from the the first pixel on that row.
+ ///
+ /// The type of the pixel.
+ /// The source.
+ /// The row.
+ /// The
+ public static Span GetPixelRowSpan(this ImageFrame source, int rowIndex)
+ where TPixel : struct, IPixel
+ => source.PixelBuffer.GetRowSpan(rowIndex);
+
+ ///
+ /// Gets the representation of the pixels as of of contiguous memory
+ /// at row beginning from the the first pixel on that row.
+ ///
+ /// The type of the pixel.
+ /// The source.
+ /// The row.
+ /// The
+ public static Span GetPixelRowSpan(this Image source, int rowIndex)
+ where TPixel : struct, IPixel
+ => source.Frames.RootFrame.GetPixelRowSpan(rowIndex);
+
///
/// Returns a reference to the 0th element of the Pixel buffer,
/// allowing direct manipulation of pixel data through unsafe operations.
@@ -31,9 +77,10 @@ namespace SixLabors.ImageSharp.Advanced
/// The Pixel format.
/// The source image frame
/// A pinnable reference the first root of the pixel buffer.
+ [Obsolete("This method will be removed in our next release! Please use MemoryMarshal.GetReference(source.GetPixelSpan())!")]
public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this ImageFrame source)
where TPixel : struct, IPixel
- => ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource)source);
+ => ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource)source);
///
/// Returns a reference to the 0th element of the Pixel buffer,
@@ -43,59 +90,68 @@ namespace SixLabors.ImageSharp.Advanced
/// The Pixel format.
/// The source image
/// A pinnable reference the first root of the pixel buffer.
+ [Obsolete("This method will be removed in our next release! Please use MemoryMarshal.GetReference(source.GetPixelSpan())!")]
public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(this Image source)
where TPixel : struct, IPixel
- => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer();
+ => ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer();
///
- /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format.
+ /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format
+ /// stored in row major order.
///
- /// The type of the pixel.
- /// The source.
- /// The
- internal static Span GetPixelSpan(this ImageFrame source)
+ /// The Pixel format.
+ /// The source
+ /// The
+ internal static Memory GetPixelMemory(this ImageFrame source)
where TPixel : struct, IPixel
- => GetSpan(source);
+ {
+ return source.PixelBuffer.Buffer.Memory;
+ }
///
- /// Gets the representation of the pixels as an area of contiguous memory at row 'y' beginning from the the first pixel on that row.
+ /// Gets the representation of the pixels as a of contiguous memory in the source image's pixel format
+ /// stored in row major order.
///
- /// The type of the pixel.
- /// The source.
- /// The row.
- /// The
- internal static Span GetPixelRowSpan(this ImageFrame source, int row)
+ /// The Pixel format.
+ /// The source
+ /// The
+ internal static Memory GetPixelMemory(this Image source)
where TPixel : struct, IPixel
- => GetSpan(source, row);
+ {
+ return source.Frames.RootFrame.GetPixelMemory();
+ }
///
- /// Gets the representation of the pixels as an area of contiguous memory in the given pixel format.
+ /// Gets the representation of the pixels as a of contiguous memory
+ /// at row beginning from the the first pixel on that row.
///
/// The type of the pixel.
/// The source.
+ /// The row.
/// The
- internal static Span GetPixelSpan(this Image source)
+ internal static Memory GetPixelRowMemory(this ImageFrame source, int rowIndex)
where TPixel : struct, IPixel
- => source.Frames.RootFrame.GetPixelSpan();
+ => source.PixelBuffer.GetRowMemory(rowIndex);
///
- /// Gets the representation of the pixels as an area of contiguous memory at row 'y' beginning from the the first pixel on that row.
+ /// Gets the representation of the pixels as of of contiguous memory
+ /// at row beginning from the the first pixel on that row.
///
/// The type of the pixel.
/// The source.
- /// The row.
+ /// The row.
/// The
- internal static Span GetPixelRowSpan(this Image source, int row)
+ internal static Memory GetPixelRowMemory(this Image source, int rowIndex)
where TPixel : struct, IPixel
- => source.Frames.RootFrame.GetPixelRowSpan(row);
+ => source.Frames.RootFrame.GetPixelRowMemory(rowIndex);
///
- /// Gets the assigned to 'source'.
+ /// Gets the assigned to 'source'.
///
/// The source image
/// Returns the configuration.
- internal static MemoryManager GetMemoryManager(this IConfigurable source)
- => GetConfiguration(source).MemoryManager;
+ internal static MemoryAllocator GetMemoryAllocator(this IConfigurable source)
+ => GetConfiguration(source).MemoryAllocator;
///
/// Gets the span to the backing buffer.
@@ -105,7 +161,7 @@ namespace SixLabors.ImageSharp.Advanced
/// The span retuned from Pixel source
private static Span GetSpan(IPixelSource source)
where TPixel : struct, IPixel
- => source.PixelBuffer.Span;
+ => source.PixelBuffer.GetSpan();
///
/// Gets the span to the backing buffer at the given row.
@@ -131,7 +187,7 @@ namespace SixLabors.ImageSharp.Advanced
///
private static Span GetSpan(Buffer2D source, int row)
where TPixel : struct, IPixel
- => source.Span.Slice(row * source.Width, source.Width);
+ => source.GetSpan().Slice(row * source.Width, source.Width);
///
/// Gets the configuration.
@@ -149,6 +205,6 @@ namespace SixLabors.ImageSharp.Advanced
/// A reference to the element.
private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer(IPixelSource source)
where TPixel : struct, IPixel
- => ref MemoryMarshal.GetReference(source.PixelBuffer.Span);
+ => ref MemoryMarshal.GetReference(source.PixelBuffer.GetSpan());
}
}
diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs
index a321e877b..27b3170e6 100644
--- a/src/ImageSharp/Advanced/IPixelSource.cs
+++ b/src/ImageSharp/Advanced/IPixelSource.cs
@@ -1,8 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Advanced
{
diff --git a/src/ImageSharp/Common/Helpers/ParallelFor.cs b/src/ImageSharp/Common/Helpers/ParallelFor.cs
index da9125905..7061475a7 100644
--- a/src/ImageSharp/Common/Helpers/ParallelFor.cs
+++ b/src/ImageSharp/Common/Helpers/ParallelFor.cs
@@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp
{
@@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp
/// The value type of the buffer
/// The start index, inclusive.
/// The end index, exclusive.
- /// The used for getting the and
+ /// The used for getting the and
/// The length of the requested parallel buffer
/// The delegate that is invoked once per iteration.
public static void WithTemporaryBuffer(
@@ -35,12 +35,12 @@ namespace SixLabors.ImageSharp
Action> body)
where T : struct
{
- MemoryManager memoryManager = configuration.MemoryManager;
+ MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
ParallelOptions parallelOptions = configuration.ParallelOptions;
IBuffer InitBuffer()
{
- return memoryManager.Allocate(bufferLength);
+ return memoryAllocator.Allocate(bufferLength);
}
void CleanUpBuffer(IBuffer buffer)
diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs
index eb08bc579..e84674355 100644
--- a/src/ImageSharp/Configuration.cs
+++ b/src/ImageSharp/Configuration.cs
@@ -12,8 +12,8 @@ using SixLabors.ImageSharp.Formats.Png;
#if !NETSTANDARD1_1
using SixLabors.ImageSharp.IO;
#endif
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Processing;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp
{
@@ -75,9 +75,9 @@ namespace SixLabors.ImageSharp
public ImageFormatManager ImageFormatsManager { get; set; } = new ImageFormatManager();
///
- /// Gets or sets the that is currently in use.
+ /// Gets or sets the that is currently in use.
///
- public MemoryManager MemoryManager { get; set; } = ArrayPoolMemoryManager.CreateDefault();
+ public MemoryAllocator MemoryAllocator { get; set; } = ArrayPoolMemoryAllocator.CreateDefault();
///
/// Gets the maximum header size of all the formats.
@@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp
{
ParallelOptions = this.ParallelOptions,
ImageFormatsManager = this.ImageFormatsManager,
- MemoryManager = this.MemoryManager,
+ MemoryAllocator = this.MemoryAllocator,
ImageOperationsProvider = this.ImageOperationsProvider,
ReadOrigin = this.ReadOrigin,
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index 26bd97b81..3c6e05a8b 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -4,9 +4,9 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Bmp
{
@@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
private readonly Configuration configuration;
- private readonly MemoryManager memoryManager;
+ private readonly MemoryAllocator memoryAllocator;
///
/// Initializes a new instance of the class.
@@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
public BmpDecoderCore(Configuration configuration, IBmpDecoderOptions options)
{
this.configuration = configuration;
- this.memoryManager = configuration.MemoryManager;
+ this.memoryAllocator = configuration.MemoryAllocator;
}
///
@@ -213,9 +213,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp
var color = default(TPixel);
var rgba = new Rgba32(0, 0, 0, 255);
- using (Buffer2D buffer = this.memoryManager.AllocateClean2D(width, height))
+ using (Buffer2D buffer = this.memoryAllocator.AllocateClean2D(width, height))
{
- this.UncompressRle8(width, buffer.Span);
+ this.UncompressRle8(width, buffer.GetSpan());
for (int y = 0; y < height; y++)
{
@@ -337,12 +337,12 @@ 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);
- Span rowSpan = row.Span;
+ Span rowSpan = row.GetSpan();
for (int y = 0; y < height; y++)
{
@@ -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,14 +427,14 @@ 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++)
{
this.stream.Read(row);
int newY = Invert(y, height, inverted);
Span pixelSpan = pixels.GetRowSpan(newY);
- PixelOperations.Instance.PackFromBgr24Bytes(row.Span, pixelSpan, width);
+ PixelOperations.Instance.PackFromBgr24Bytes(row.GetSpan(), pixelSpan, width);
}
}
}
@@ -452,14 +452,14 @@ 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++)
{
this.stream.Read(row);
int newY = Invert(y, height, inverted);
Span pixelSpan = pixels.GetRowSpan(newY);
- PixelOperations.Instance.PackFromBgra32Bytes(row.Span, pixelSpan, width);
+ PixelOperations.Instance.PackFromBgra32Bytes(row.GetSpan(), pixelSpan, width);
}
}
}
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
index 9edd0fcd4..23b01ae9e 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
public void Encode(Image image, Stream stream)
where TPixel : struct, IPixel
{
- var encoder = new BmpEncoderCore(this, image.GetMemoryManager());
+ var encoder = new BmpEncoderCore(this, image.GetMemoryAllocator());
encoder.Encode(image, stream);
}
}
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index 2b0c90733..d8bf90c7c 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -3,8 +3,8 @@
using System;
using System.IO;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Bmp
{
@@ -20,16 +20,16 @@ namespace SixLabors.ImageSharp.Formats.Bmp
private readonly BmpBitsPerPixel bitsPerPixel;
- private readonly MemoryManager memoryManager;
+ private readonly MemoryAllocator memoryAllocator;
///
/// Initializes a new instance of the class.
///
/// The encoder options
- /// The memory manager
- public BmpEncoderCore(IBmpEncoderOptions options, MemoryManager memoryManager)
+ /// The memory manager
+ public BmpEncoderCore(IBmpEncoderOptions options, MemoryAllocator memoryAllocator)
{
- this.memoryManager = memoryManager;
+ this.memoryAllocator = memoryAllocator;
this.bitsPerPixel = options.BitsPerPixel;
}
@@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
private IManagedByteBuffer AllocateRow(int width, int bytesPerPixel)
{
- return this.memoryManager.AllocatePaddedPixelRowBuffer(width, bytesPerPixel, this.padding);
+ return this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, bytesPerPixel, this.padding);
}
///
@@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span pixelSpan = pixels.GetRowSpan(y);
- PixelOperations.Instance.ToBgra32Bytes(pixelSpan, row.Span, pixelSpan.Length);
+ PixelOperations.Instance.ToBgra32Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length);
stream.Write(row.Array, 0, row.Length());
}
}
@@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span pixelSpan = pixels.GetRowSpan(y);
- PixelOperations.Instance.ToBgr24Bytes(pixelSpan, row.Span, pixelSpan.Length);
+ PixelOperations.Instance.ToBgr24Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length);
stream.Write(row.Array, 0, row.Length());
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index 4fbd4baf5..fc73f55a1 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -7,9 +7,9 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Gif
@@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
public FrameDecodingMode DecodingMode { get; }
- private MemoryManager MemoryManager => this.configuration.MemoryManager;
+ private MemoryAllocator MemoryAllocator => this.configuration.MemoryAllocator;
///
/// Decodes the stream to the image.
@@ -293,7 +293,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
continue;
}
- using (IManagedByteBuffer commentsBuffer = this.MemoryManager.AllocateManagedByteBuffer(length))
+ using (IManagedByteBuffer commentsBuffer = this.MemoryAllocator.AllocateManagedByteBuffer(length))
{
this.stream.Read(commentsBuffer.Array, 0, length);
string comments = this.TextEncoding.GetString(commentsBuffer.Array, 0, length);
@@ -321,15 +321,15 @@ 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.Span);
- ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).Span);
- this.ReadFrameColors(ref image, ref previousFrame, indices.Span, colorTable, imageDescriptor);
+ this.ReadFrameIndices(imageDescriptor, indices.GetSpan());
+ ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).GetSpan());
+ this.ReadFrameColors(ref image, ref previousFrame, indices.GetSpan(), colorTable, imageDescriptor);
// Skip any remaining blocks
this.Skip(0);
@@ -350,7 +350,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private void ReadFrameIndices(in GifImageDescriptor imageDescriptor, Span indices)
{
int dataSize = this.stream.ReadByte();
- using (var lzwDecoder = new LzwDecoder(this.configuration.MemoryManager, this.stream))
+ using (var lzwDecoder = new LzwDecoder(this.configuration.MemoryAllocator, this.stream))
{
lzwDecoder.DecodePixels(imageDescriptor.Width, imageDescriptor.Height, dataSize, indices);
}
@@ -528,7 +528,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
int globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3;
- this.globalColorTable = this.MemoryManager.AllocateManagedByteBuffer(globalColorTableLength, true);
+ this.globalColorTable = this.MemoryAllocator.AllocateManagedByteBuffer(globalColorTableLength, true);
// Read the global color table data from the stream
stream.Read(this.globalColorTable.Array, 0, globalColorTableLength);
diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs
index fb072bcb7..a07928b04 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs
@@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
public void Encode(Image image, Stream stream)
where TPixel : struct, IPixel
{
- var encoder = new GifEncoderCore(image.GetConfiguration().MemoryManager, this);
+ var encoder = new GifEncoderCore(image.GetConfiguration().MemoryAllocator, this);
encoder.Encode(image, stream);
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index 747867c80..f84b13f5f 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -7,10 +7,10 @@ using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Quantization;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Gif
{
@@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
internal sealed class GifEncoderCore
{
- private readonly MemoryManager memoryManager;
+ private readonly MemoryAllocator memoryAllocator;
///
/// A reusable buffer used to reduce allocations.
@@ -49,11 +49,11 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Initializes a new instance of the class.
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The options for the encoder.
- public GifEncoderCore(MemoryManager memoryManager, IGifEncoderOptions options)
+ public GifEncoderCore(MemoryAllocator memoryAllocator, IGifEncoderOptions options)
{
- this.memoryManager = memoryManager;
+ this.memoryAllocator = memoryAllocator;
this.textEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding;
this.quantizer = options.Quantizer;
this.ignoreMetadata = options.IgnoreMetadata;
@@ -317,10 +317,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
int colorTableLength = (int)Math.Pow(2, this.bitDepth) * 3; // The maximium number of colors for the bit depth
Rgb24 rgb = default;
- using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength))
+ using (IManagedByteBuffer colorTable = this.memoryAllocator.AllocateManagedByteBuffer(colorTableLength))
{
ref TPixel paletteRef = ref MemoryMarshal.GetReference(image.Palette.AsSpan());
- ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.Span));
+ ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.GetSpan()));
for (int i = 0; i < pixelCount; i++)
{
ref TPixel entry = ref Unsafe.Add(ref paletteRef, i);
@@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private void WriteImageData(QuantizedFrame image, Stream stream)
where TPixel : struct, IPixel
{
- using (var encoder = new LzwEncoder(this.memoryManager, image.Pixels, (byte)this.bitDepth))
+ using (var encoder = new LzwEncoder(this.memoryAllocator, image.Pixels, (byte)this.bitDepth))
{
encoder.Encode(stream);
}
diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
index 9f9e070e2..977870936 100644
--- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
@@ -5,7 +5,7 @@ using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Gif
{
@@ -48,18 +48,18 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Initializes a new instance of the class
/// and sets the stream, where the compressed data should be read from.
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The stream to read from.
/// is null.
- public LzwDecoder(MemoryManager memoryManager, Stream stream)
+ public LzwDecoder(MemoryAllocator memoryAllocator, Stream stream)
{
Guard.NotNull(stream, nameof(stream));
this.stream = stream;
- this.prefix = memoryManager.Allocate(MaxStackSize, true);
- this.suffix = memoryManager.Allocate(MaxStackSize, true);
- this.pixelStack = memoryManager.Allocate(MaxStackSize + 1, true);
+ this.prefix = memoryAllocator.Allocate(MaxStackSize, true);
+ this.suffix = memoryAllocator.Allocate(MaxStackSize, true);
+ this.pixelStack = memoryAllocator.Allocate(MaxStackSize + 1, true);
}
///
@@ -102,9 +102,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
int data = 0;
int first = 0;
- ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.Span);
- ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.Span);
- ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.Span);
+ ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.GetSpan());
+ ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.GetSpan());
+ ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.GetSpan());
ref byte pixelsRef = ref MemoryMarshal.GetReference(pixels);
for (code = 0; code < clearCode; code++)
diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
index 1dc7e99e8..de9de5e15 100644
--- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
@@ -5,7 +5,7 @@ using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Gif
{
@@ -168,16 +168,16 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Initializes a new instance of the class.
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The array of indexed pixels.
/// The color depth in bits.
- public LzwEncoder(MemoryManager memoryManager, byte[] indexedPixels, int colorDepth)
+ public LzwEncoder(MemoryAllocator memoryAllocator, byte[] indexedPixels, int colorDepth)
{
this.pixelArray = indexedPixels;
this.initialCodeSize = Math.Max(2, colorDepth);
- this.hashTable = memoryManager.Allocate(HashSize, true);
- this.codeTable = memoryManager.Allocate(HashSize, true);
+ this.hashTable = memoryAllocator.Allocate(HashSize, true);
+ this.codeTable = memoryAllocator.Allocate(HashSize, true);
}
///
@@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ResetCodeTable()
{
- this.hashTable.Span.Fill(-1);
+ this.hashTable.GetSpan().Fill(-1);
}
///
@@ -293,8 +293,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.Output(this.clearCode, stream);
- ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.Span);
- ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.Span);
+ ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.GetSpan());
+ ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.GetSpan());
while (this.position < this.pixelArray.Length)
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs
index 43cc3e9db..4db6d7431 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs
@@ -4,7 +4,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
index 080bf8333..11b5c60d1 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
@@ -7,7 +7,7 @@ using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Common.Tuples;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
index efa746819..253b20c39 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
@@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs
index b586d520a..2baefff9b 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs
@@ -3,7 +3,7 @@
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
index fe18f8438..2b442fcdc 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
@@ -3,7 +3,7 @@
using System;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
@@ -26,11 +26,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
/// Initializes a new instance of the class.
///
- public JpegComponentPostProcessor(MemoryManager memoryManager, JpegImagePostProcessor imagePostProcessor, IJpegComponent component)
+ public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, JpegImagePostProcessor imagePostProcessor, IJpegComponent component)
{
this.Component = component;
this.ImagePostProcessor = imagePostProcessor;
- this.ColorBuffer = memoryManager.Allocate2D(
+ this.ColorBuffer = memoryAllocator.Allocate2D(
imagePostProcessor.PostProcessorBufferSize.Width,
imagePostProcessor.PostProcessorBufferSize.Height);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
index 38340b238..99408cf57 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
@@ -4,12 +4,10 @@
using System;
using System.Linq;
using System.Numerics;
-
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
using SixLabors.Primitives;
-
using JpegColorConverter = SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters.JpegColorConverter;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
@@ -49,17 +47,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
/// Initializes a new instance of the class.
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The representing the uncompressed spectral Jpeg data
- public JpegImagePostProcessor(MemoryManager memoryManager, IRawJpegData rawJpeg)
+ public JpegImagePostProcessor(MemoryAllocator memoryAllocator, IRawJpegData rawJpeg)
{
this.RawJpeg = rawJpeg;
IJpegComponent c0 = rawJpeg.Components.First();
this.NumberOfPostProcessorSteps = c0.SizeInBlocks.Height / BlockRowsPerStep;
this.PostProcessorBufferSize = new Size(c0.SizeInBlocks.Width * 8, PixelRowsPerStep);
- this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryManager, this, c)).ToArray();
- this.rgbaBuffer = memoryManager.Allocate(rawJpeg.ImageSizeInPixels.Width);
+ this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryAllocator, this, c)).ToArray();
+ this.rgbaBuffer = memoryAllocator.Allocate(rawJpeg.ImageSizeInPixels.Width);
this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace);
}
@@ -155,11 +153,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
int y = yy - this.PixelRowCounter;
var values = new JpegColorConverter.ComponentValues(buffers, y);
- this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.Span);
+ this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan());
Span destRow = destination.GetPixelRowSpan(yy);
- PixelOperations.Instance.PackFromVector4(this.rgbaBuffer.Span, destRow, destination.Width);
+ PixelOperations.Instance.PackFromVector4(this.rgbaBuffer.GetSpan(), destRow, destination.Width);
}
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
index 9aceb78b2..825a7f5f0 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
@@ -4,10 +4,9 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs
index bb3bd01aa..75cea5551 100644
--- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs
@@ -6,7 +6,7 @@ using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
@@ -56,9 +56,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
///
/// Initializes
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The instance
- public void InitializeDerivedData(MemoryManager memoryManager, GolangJpegDecoderCore decoder)
+ public void InitializeDerivedData(MemoryAllocator memoryAllocator, GolangJpegDecoderCore decoder)
{
// For 4-component images (either CMYK or YCbCrK), we only support two
// hv vectors: [0x11 0x11 0x11 0x11] and [0x22 0x11 0x11 0x22].
@@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors);
}
- this.SpectralBlocks = memoryManager.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true);
+ this.SpectralBlocks = memoryAllocator.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true);
}
///
diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
index 86f97d224..34a6e2f0f 100644
--- a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
@@ -705,7 +705,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
foreach (GolangComponent component in this.Components)
{
- component.InitializeDerivedData(this.configuration.MemoryManager, this);
+ component.InitializeDerivedData(this.configuration.MemoryAllocator, this);
}
}
}
@@ -812,7 +812,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
private Image PostProcessIntoImage()
where TPixel : struct, IPixel
{
- using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this))
+ using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this))
{
var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData);
postProcessor.PostProcess(image.Frames.RootFrame);
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
index eb91590e8..7aeee43c2 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
@@ -5,7 +5,7 @@ using System;
using System.IO;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
// TODO: This could be useful elsewhere.
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
@@ -38,13 +38,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
///
/// Initializes a new instance of the class.
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The input stream.
- public DoubleBufferedStreamReader(MemoryManager memoryManager, Stream stream)
+ public DoubleBufferedStreamReader(MemoryAllocator memoryAllocator, Stream stream)
{
this.stream = stream;
this.length = (int)stream.Length;
- this.managedBuffer = memoryManager.AllocateCleanManagedByteBuffer(ChunkLength);
+ this.managedBuffer = memoryAllocator.AllocateCleanManagedByteBuffer(ChunkLength);
this.bufferChunk = this.managedBuffer.Array;
}
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
index ccbb5c6c0..eefe8b97e 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
@@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
@@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
///
internal class PdfJsFrameComponent : IDisposable, IJpegComponent
{
- private readonly MemoryManager memoryManager;
+ private readonly MemoryAllocator memoryAllocator;
- public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index)
+ public PdfJsFrameComponent(MemoryAllocator memoryAllocator, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index)
{
- this.memoryManager = memoryManager;
+ this.memoryAllocator = memoryAllocator;
this.Frame = frame;
this.Id = id;
this.HorizontalSamplingFactor = horizontalFactor;
@@ -129,14 +129,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors);
}
- this.SpectralBlocks = this.memoryManager.Allocate2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true);
+ this.SpectralBlocks = this.memoryAllocator.Allocate2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref Block8x8 GetBlockReference(int column, int row)
{
int offset = ((this.WidthInBlocks + 1) * row) + column;
- return ref Unsafe.Add(ref MemoryMarshal.GetReference(this.SpectralBlocks.Span), offset);
+ return ref Unsafe.Add(ref MemoryMarshal.GetReference(this.SpectralBlocks.GetSpan()), offset);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
index 875a86263..2789f0cc0 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
@@ -4,7 +4,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
@@ -37,17 +37,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
///
/// Initializes a new instance of the struct.
///
- /// The to use for buffer allocations.
+ /// The to use for buffer allocations.
/// The code lengths
/// The huffman values
- public PdfJsHuffmanTable(MemoryManager memoryManager, ReadOnlySpan lengths, ReadOnlySpan values)
+ public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan lengths, ReadOnlySpan values)
{
const int length = 257;
- using (IBuffer huffsize = memoryManager.Allocate(length))
- using (IBuffer huffcode = memoryManager.Allocate(length))
+ using (IBuffer huffsize = memoryAllocator.Allocate(length))
+ using (IBuffer huffcode = memoryAllocator.Allocate(length))
{
- ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.Span);
- ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.Span);
+ ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan());
+ ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan());
GenerateSizeTable(lengths, ref huffsizeRef);
GenerateCodeTable(ref huffsizeRef, ref huffcodeRef, length);
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs
index 49bc10539..c9f1c555d 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs
@@ -2,13 +2,14 @@
// Licensed under the Apache License, Version 2.0.
using System;
+
#if DEBUG
using System.Diagnostics;
#endif
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-
using SixLabors.ImageSharp.Formats.Jpeg.Components;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
@@ -166,7 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
if (componentsLength == 1)
{
PdfJsFrameComponent component = components[this.compIndex];
- ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span));
+ ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan()));
ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
@@ -188,7 +189,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
for (int i = 0; i < componentsLength; i++)
{
PdfJsFrameComponent component = components[i];
- ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span));
+ ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan()));
ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
int h = component.HorizontalSamplingFactor;
@@ -224,7 +225,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
if (componentsLength == 1)
{
PdfJsFrameComponent component = components[this.compIndex];
- ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span));
+ ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan()));
ref PdfJsHuffmanTable huffmanTable = ref huffmanTables[isAC ? component.ACHuffmanTableId : component.DCHuffmanTableId];
for (int n = 0; n < this.mcuToRead; n++)
@@ -267,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
for (int i = 0; i < componentsLength; i++)
{
PdfJsFrameComponent component = components[i];
- ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.Span));
+ ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan()));
ref PdfJsHuffmanTable huffmanTable = ref huffmanTables[isAC ? component.ACHuffmanTableId : component.DCHuffmanTableId];
int h = component.HorizontalSamplingFactor;
int v = component.VerticalSamplingFactor;
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
index 752e72dd2..937439ed0 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
@@ -11,12 +11,12 @@ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.MetaData.Profiles.Icc;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
+using SixLabors.Memory;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
@@ -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,17 +703,17 @@ 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.Span);
+ ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.GetSpan());
for (int i = 2; i < remaining;)
{
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.Span);
+ ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.GetSpan());
int codeLengthSum = 0;
for (int j = 1; j < 17; j++)
@@ -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);
@@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
this.BuildHuffmanTable(
huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables,
huffmanTableSpec & 15,
- codeLengths.Span,
- huffmanValues.Span);
+ codeLengths.GetSpan(),
+ huffmanValues.GetSpan());
}
}
}
@@ -817,7 +817,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void BuildHuffmanTable(PdfJsHuffmanTables tables, int index, ReadOnlySpan codeLengths, ReadOnlySpan values)
{
- tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryManager, codeLengths, values);
+ tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryAllocator, codeLengths, values);
}
///
@@ -834,7 +834,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
private Image PostProcessIntoImage()
where TPixel : struct, IPixel
{
- using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this))
+ using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this))
{
var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData);
postProcessor.PostProcess(image.Frames.RootFrame);
diff --git a/src/ImageSharp/Formats/Png/PngChunk.cs b/src/ImageSharp/Formats/Png/PngChunk.cs
index c91f39d7f..c75f9465a 100644
--- a/src/ImageSharp/Formats/Png/PngChunk.cs
+++ b/src/ImageSharp/Formats/Png/PngChunk.cs
@@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.Memory;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index cc98b8450..67e32f212 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -13,9 +13,9 @@ using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Png.Filters;
using SixLabors.ImageSharp.Formats.Png.Zlib;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
namespace SixLabors.ImageSharp.Formats.Png
{
@@ -188,7 +188,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.ignoreMetadata = options.IgnoreMetadata;
}
- private MemoryManager MemoryManager => this.configuration.MemoryManager;
+ private MemoryAllocator MemoryAllocator => this.configuration.MemoryAllocator;
///
/// Decodes the stream to the image.
@@ -410,8 +410,8 @@ namespace SixLabors.ImageSharp.Formats.Png
this.bytesPerSample = this.header.BitDepth / 8;
}
- this.previousScanline = this.MemoryManager.AllocateCleanManagedByteBuffer(this.bytesPerScanline);
- this.scanline = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(this.bytesPerScanline);
+ this.previousScanline = this.MemoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline);
+ this.scanline = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline);
}
///
@@ -531,7 +531,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
this.currentRowBytesRead = 0;
- Span scanlineSpan = this.scanline.Span;
+ Span scanlineSpan = this.scanline.GetSpan();
var filterType = (FilterType)scanlineSpan[0];
switch (filterType)
@@ -546,17 +546,17 @@ namespace SixLabors.ImageSharp.Formats.Png
case FilterType.Up:
- UpFilter.Decode(scanlineSpan, this.previousScanline.Span);
+ UpFilter.Decode(scanlineSpan, this.previousScanline.GetSpan());
break;
case FilterType.Average:
- AverageFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel);
+ AverageFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel);
break;
case FilterType.Paeth:
- PaethFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel);
+ PaethFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel);
break;
default:
@@ -639,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
Span rowSpan = image.GetPixelRowSpan(this.currentRow);
- this.ProcessInterlacedDefilteredScanline(this.scanline.Span, rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]);
+ this.ProcessInterlacedDefilteredScanline(this.scanline.GetSpan(), rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]);
this.SwapBuffers();
@@ -727,11 +727,11 @@ namespace SixLabors.ImageSharp.Formats.Png
if (this.header.BitDepth == 16)
{
int length = this.header.Width * 3;
- using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length))
+ using (IBuffer compressed = this.configuration.MemoryAllocator.Allocate(length))
{
// TODO: Should we use pack from vector here instead?
- this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length);
- PixelOperations.Instance.PackFromRgb24Bytes(compressed.Span, rowSpan, this.header.Width);
+ this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length);
+ PixelOperations