diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
index 5038ea01b..6f851e5c3 100644
--- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
@@ -5,7 +5,10 @@
namespace ImageSharp.Drawing.Brushes
{
+ using System;
using System.Numerics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Processors;
@@ -114,7 +117,7 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(BufferSpan scanline, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
// create a span for colors
using (Buffer amountBuffer = new Buffer(scanline.Length))
@@ -122,7 +125,7 @@ namespace ImageSharp.Drawing.Brushes
{
int sourceY = (y - this.offsetY) % this.yLength;
int offsetX = x - this.offsetX;
- BufferSpan sourceRow = this.source.GetRowSpan(sourceY);
+ Span sourceRow = this.source.GetRowSpan(sourceY);
for (int i = 0; i < scanline.Length; i++)
{
@@ -133,7 +136,7 @@ namespace ImageSharp.Drawing.Brushes
overlay[i] = pixel;
}
- BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
index dc8a4bc90..90990e54a 100644
--- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
@@ -7,6 +7,8 @@ namespace ImageSharp.Drawing.Brushes
{
using System;
using System.Numerics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Processors;
@@ -147,7 +149,7 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(BufferSpan scanline, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
int patternY = y % this.pattern.Height;
using (Buffer amountBuffer = new Buffer(scanline.Length))
@@ -161,7 +163,7 @@ namespace ImageSharp.Drawing.Brushes
overlay[i] = this.pattern[patternY, patternX];
}
- BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
index d7c70220c..29629324a 100644
--- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
+++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
@@ -7,6 +7,8 @@ namespace ImageSharp.Drawing.Processors
{
using System;
using System.Numerics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
@@ -64,7 +66,7 @@ namespace ImageSharp.Drawing.Processors
/// The x position in the target pixel space that the start of the scanline data corresponds to.
/// The y position in the target pixel space that whole scanline corresponds to.
/// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.
- internal virtual void Apply(BufferSpan scanline, int x, int y)
+ internal virtual void Apply(Span scanline, int x, int y)
{
using (Buffer amountBuffer = new Buffer(scanline.Length))
using (Buffer overlay = new Buffer(scanline.Length))
@@ -79,7 +81,7 @@ namespace ImageSharp.Drawing.Processors
overlay[i] = this[x + i, y];
}
- BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
index a96202b7b..64b91e384 100644
--- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
@@ -5,7 +5,10 @@
namespace ImageSharp.Drawing.Brushes
{
+ using System;
using System.Numerics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Processors;
@@ -139,7 +142,7 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(BufferSpan scanline, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
using (Buffer amountBuffer = new Buffer(scanline.Length))
using (Buffer overlay = new Buffer(scanline.Length))
@@ -155,7 +158,7 @@ namespace ImageSharp.Drawing.Brushes
overlay[i] = this[offsetX, y];
}
- BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
index 71b802136..28f7b0e45 100644
--- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
+++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
@@ -5,7 +5,10 @@
namespace ImageSharp.Drawing.Brushes
{
+ using System;
using System.Numerics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Processors;
@@ -87,9 +90,9 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(BufferSpan scanline, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
- BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
using (Buffer amountBuffer = new Buffer(scanline.Length))
{
diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
index c49631de8..ed45417fc 100644
--- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
@@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Processors
using System;
using System.Numerics;
using System.Threading.Tasks;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
@@ -97,8 +99,8 @@ namespace ImageSharp.Drawing.Processors
this.ParallelOptions,
y =>
{
- BufferSpan background = sourcePixels.GetRowSpan(y).Slice(minX, width);
- BufferSpan foreground = toBlendPixels.GetRowSpan(y - this.Location.Y).Slice(0, width);
+ Span background = sourcePixels.GetRowSpan(y).Slice(minX, width);
+ Span foreground = toBlendPixels.GetRowSpan(y - this.Location.Y).Slice(0, width);
this.blender.Blend(background, background, foreground, amount);
});
}
diff --git a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
index 3fd829549..d1332c435 100644
--- a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
@@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Processors
using System;
using System.Numerics;
using System.Threading.Tasks;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Pens;
@@ -110,7 +112,7 @@ namespace ImageSharp.Drawing.Processors
colors[i] = color.Color;
}
- BufferSpan destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width);
+ Span destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width);
blender.Blend(destination, destination, colors, amount);
}
});
diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processors/FillProcessor.cs
index 25eccd245..fa6f48156 100644
--- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/FillProcessor.cs
@@ -10,6 +10,8 @@ namespace ImageSharp.Drawing.Processors
using System.Threading.Tasks;
using Drawing;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
index 323214fb8..a57be3a5a 100644
--- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
+++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
@@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Processors
using System;
using System.Buffers;
using Drawing;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs
index f7c83452f..096f96f04 100644
--- a/src/ImageSharp/Common/Helpers/DebugGuard.cs
+++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs
@@ -170,7 +170,7 @@ namespace ImageSharp
///
/// is true
///
- public static void MustBeSameSized(BufferSpan target, BufferSpan other, string parameterName)
+ public static void MustBeSameSized(Span target, Span other, string parameterName)
where T : struct
{
if (target.Length != other.Length)
@@ -189,7 +189,7 @@ namespace ImageSharp
///
/// is true
///
- public static void MustBeSizedAtLeast(BufferSpan target, BufferSpan minSpan, string parameterName)
+ public static void MustBeSizedAtLeast(Span target, Span minSpan, string parameterName)
where T : struct
{
if (target.Length < minSpan.Length)
diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs
deleted file mode 100644
index 1b0bef314..000000000
--- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs
+++ /dev/null
@@ -1,205 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp
-{
- using System;
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
-
- ///
- /// Represents a contiguous region of a pinned managed array.
- /// The array is usually owned by a instance.
- ///
- ///
- /// is very similar to corefx System.Span<T>, and we try to maintain a compatible API.
- /// There are several differences though:
- /// - It's not possible to use it with stack objects or pointers to unmanaged memory, only with managed arrays.
- /// - It's possible to retrieve a reference to the array () so we can pass it to API-s like
- /// - It's possible to retrieve the pinned pointer. This enables optimized (unchecked) unsafe operations.
- /// - There is no bounds checking for performance reasons, only in debug mode. This makes an unsafe type!
- ///
- /// The type of elements of the array
- internal unsafe struct BufferSpan
- where T : struct
- {
- ///
- /// Initializes a new instance of the struct from a pinned array and an start.
- ///
- /// The pinned array
- /// The index at which to begin the span.
- /// The length
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan(T[] array, int start, int length)
- {
- GuardArray(array);
-
- DebugGuard.MustBeLessThanOrEqualTo(start, array.Length, nameof(start));
- DebugGuard.MustBeLessThanOrEqualTo(length, array.Length - start, nameof(length));
-
- this.Array = array;
- this.Length = length;
- this.Start = start;
- }
-
- ///
- /// Initializes a new instance of the struct from a pinned array and an start.
- ///
- /// The pinned array
- /// The index at which to begin the span.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan(T[] array, int start)
- {
- GuardArray(array);
- DebugGuard.MustBeLessThanOrEqualTo(start, array.Length, nameof(start));
-
- this.Array = array;
- this.Length = array.Length - start;
- this.Start = start;
- }
-
- ///
- /// Initializes a new instance of the struct from a pinned array.
- ///
- /// The pinned array
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan(T[] array)
- {
- GuardArray(array);
-
- this.Array = array;
- this.Start = 0;
- this.Length = array.Length;
- }
-
- ///
- /// Gets the backing array.
- ///
- public T[] Array { get; private set; }
-
- ///
- /// Gets the length of the
- ///
- public int Length { get; private set; }
-
- ///
- /// Gets the start inside
- ///
- public int Start { get; private set; }
-
- ///
- /// Gets the start inside in bytes.
- ///
- public int ByteOffset => this.Start * Unsafe.SizeOf();
-
- ///
- /// Returns a reference to specified element of the span.
- ///
- /// The index
- /// The reference to the specified element
- public ref T this[int index]
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- DebugGuard.MustBeLessThan(index, this.Length, nameof(index));
- ref T startRef = ref this.DangerousGetPinnableReference();
- return ref Unsafe.Add(ref startRef, index);
- }
- }
-
- ///
- /// Converts generic to a of bytes
- /// setting it's and to correct values.
- ///
- /// The span of bytes
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan AsBytes()
- {
- BufferSpan result = default(BufferSpan);
- result.Array = Unsafe.As(this.Array);
- result.Start = this.Start * Unsafe.SizeOf();
- result.Length = this.Length * Unsafe.SizeOf();
- return result;
- }
-
- ///
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
- /// would have been stored. Such a reference can be used for pinning but must never be dereferenced.
- ///
- /// The reference to the 0th element
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref T DangerousGetPinnableReference()
- {
- ref T origin = ref this.Array[0];
- return ref Unsafe.Add(ref origin, this.Start);
- }
-
- ///
- /// Forms a slice out of the given BufferSpan, beginning at 'start'.
- ///
- /// TThe index at which to begin this slice.
- /// The offseted (sliced) BufferSpan
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan Slice(int start)
- {
- DebugGuard.MustBeLessThan(start, this.Length, nameof(start));
-
- BufferSpan result = default(BufferSpan);
- result.Array = this.Array;
- result.Start = this.Start + start;
- result.Length = this.Length - start;
- return result;
- }
-
- ///
- /// Forms a slice out of the given BufferSpan, beginning at 'start'.
- ///
- /// The index at which to begin this slice.
- /// The desired length for the slice (exclusive).
- /// The sliced BufferSpan
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan Slice(int start, int length)
- {
- DebugGuard.MustBeLessThanOrEqualTo(start, this.Length, nameof(start));
- DebugGuard.MustBeLessThanOrEqualTo(length, this.Length - start, nameof(length));
-
- BufferSpan result = default(BufferSpan);
- result.Array = this.Array;
- result.Start = this.Start + start;
- result.Length = length;
- return result;
- }
-
- ///
- /// Clears `count` elements from the beginning of the span.
- ///
- /// The number of elements to clear
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Clear(int count)
- {
- DebugGuard.MustBeLessThanOrEqualTo(count, this.Length, nameof(count));
-
- // TODO: Use Unsafe.InitBlock(ref T) for small arrays, when it get's official
- System.Array.Clear(this.Array, this.Start, count);
- }
-
- ///
- /// Clears the the span
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Clear()
- {
- this.Clear(this.Length);
- }
-
- [Conditional("DEBUG")]
- private static void GuardArray(T[] array)
- {
- DebugGuard.NotNull(array, nameof(array));
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs
index b94b87255..629944ea1 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the Atkinson image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs
index 894b6e236..02d41c369 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the Burks image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs
index 5d0ecde6b..7a5fabdb3 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs
@@ -8,6 +8,7 @@ namespace ImageSharp.Dithering
using System.Numerics;
using System.Runtime.CompilerServices;
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs
index f7a93667f..6165da634 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs
index 60fef8121..6daeab32f 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs
index 4325438e0..0c0944d0e 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the Sierra2 image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs
index 25ea70d0a..2e2220846 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the Sierra3 image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs
index c7b1d214f..fe4c933a9 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the SierraLite image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs
index 93258c350..b04c16481 100644
--- a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs
+++ b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the Stucki image dithering algorithm.
///
diff --git a/src/ImageSharp/Dithering/Ordered/Bayer.cs b/src/ImageSharp/Dithering/Ordered/Bayer.cs
index 3792c3c02..ded17d1e1 100644
--- a/src/ImageSharp/Dithering/Ordered/Bayer.cs
+++ b/src/ImageSharp/Dithering/Ordered/Bayer.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering.Ordered
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the 4x4 Bayer dithering matrix.
///
diff --git a/src/ImageSharp/Dithering/Ordered/Ordered.cs b/src/ImageSharp/Dithering/Ordered/Ordered.cs
index ae75b87f2..1fd39eb8b 100644
--- a/src/ImageSharp/Dithering/Ordered/Ordered.cs
+++ b/src/ImageSharp/Dithering/Ordered/Ordered.cs
@@ -5,6 +5,8 @@
namespace ImageSharp.Dithering.Ordered
{
+ using ImageSharp.Memory;
+
///
/// Applies error diffusion based dithering using the 4x4 ordered dithering matrix.
///
diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs
index 917f57318..48d6c3f6a 100644
--- a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs
+++ b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Dithering.Ordered
{
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs
index 0ce233739..71472c00f 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs
@@ -8,6 +8,8 @@ namespace ImageSharp.Formats.Jpg
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+ using ImageSharp.Memory;
+
///
/// Encapsulates the implementation of processing "raw" -s into Jpeg image channels.
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs
index 920457a0c..342ce299c 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs
@@ -6,6 +6,8 @@ namespace ImageSharp.Formats.Jpg
{
using System.Runtime.CompilerServices;
+ using ImageSharp.Memory;
+
///
/// Represents an area of a Jpeg subimage (channel)
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs
index 2a9b0c6b2..7d2e6d441 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs
@@ -9,6 +9,8 @@ namespace ImageSharp.Formats.Jpg
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+ using ImageSharp.Memory;
+
///
/// Encapsulates the impementation of Jpeg SOS Huffman decoding. See JpegScanDecoder.md!
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs
index 86192318b..89e327f0d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs
@@ -7,6 +7,8 @@ namespace ImageSharp.Formats.Jpg
using System;
using System.Buffers;
+ using ImageSharp.Memory;
+
///
/// Represents an image made up of three color components (luminance, blue chroma, red chroma)
///
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 92607883d..9d9ecacfe 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -11,6 +11,7 @@ namespace ImageSharp.Formats
using System.Threading.Tasks;
using ImageSharp.Formats.Jpg;
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
index d3b32d977..db2189b3c 100644
--- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Formats
{
+ using System;
using System.Runtime.CompilerServices;
///
@@ -21,7 +22,7 @@ namespace ImageSharp.Formats
/// The previous scanline.
/// The bytes per pixel.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Decode(BufferSpan scanline, BufferSpan previousScanline, int bytesPerPixel)
+ public static void Decode(Span scanline, Span previousScanline, int bytesPerPixel)
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
@@ -55,7 +56,7 @@ namespace ImageSharp.Formats
/// The filtered scanline result.
/// The bytes per pixel.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Encode(BufferSpan scanline, BufferSpan previousScanline, BufferSpan result, int bytesPerPixel)
+ public static void Encode(Span scanline, Span previousScanline, Span result, int bytesPerPixel)
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
diff --git a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
index 87d794902..ee77d1a5e 100644
--- a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
@@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System;
using System.Runtime.CompilerServices;
+ using ImageSharp.Memory;
+
///
/// The None filter, the scanline is transmitted unmodified; it is only necessary to
/// insert a filter type byte before the data.
@@ -21,12 +23,12 @@ namespace ImageSharp.Formats
/// The scanline to encode
/// The filtered scanline result.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Encode(BufferSpan scanline, BufferSpan result)
+ public static void Encode(Span scanline, Span result)
{
// Insert a byte before the data.
result[0] = 0;
result = result.Slice(1);
- BufferSpan.Copy(scanline, result);
+ SpanHelper.Copy(scanline, result);
}
}
}
diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
index 4226596f8..ec12eca05 100644
--- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Formats
{
+ using System;
using System.Runtime.CompilerServices;
///
@@ -22,7 +23,7 @@ namespace ImageSharp.Formats
/// The previous scanline.
/// The bytes per pixel.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Decode(BufferSpan scanline, BufferSpan previousScanline, int bytesPerPixel)
+ public static void Decode(Span scanline, Span previousScanline, int bytesPerPixel)
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
@@ -57,7 +58,7 @@ namespace ImageSharp.Formats
/// The filtered scanline result.
/// The bytes per pixel.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Encode(BufferSpan scanline, BufferSpan previousScanline, BufferSpan result, int bytesPerPixel)
+ public static void Encode(Span scanline, Span previousScanline, Span result, int bytesPerPixel)
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
index d40f261ed..f81122ad2 100644
--- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Formats
{
+ using System;
using System.Runtime.CompilerServices;
///
@@ -20,7 +21,7 @@ namespace ImageSharp.Formats
/// The scanline to decode
/// The bytes per pixel.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Decode(BufferSpan scanline, int bytesPerPixel)
+ public static void Decode(Span scanline, int bytesPerPixel)
{
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
@@ -48,7 +49,7 @@ namespace ImageSharp.Formats
/// The filtered scanline result.
/// The bytes per pixel.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Encode(BufferSpan scanline, BufferSpan result, int bytesPerPixel)
+ public static void Encode(Span scanline, Span result, int bytesPerPixel)
{
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
index fa3ef57da..b89a3c5fc 100644
--- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Formats
{
+ using System;
using System.Runtime.CompilerServices;
///
@@ -20,7 +21,7 @@ namespace ImageSharp.Formats
/// The scanline to decode
/// The previous scanline.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Decode(BufferSpan scanline, BufferSpan previousScanline)
+ public static void Decode(Span scanline, Span previousScanline)
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
@@ -43,7 +44,7 @@ namespace ImageSharp.Formats
/// The previous scanline.
/// The filtered scanline result.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Encode(BufferSpan scanline, BufferSpan previousScanline, BufferSpan result)
+ public static void Encode(Span scanline, Span previousScanline, Span result)
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 13b4c1167..f8be0f6cc 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -12,6 +12,7 @@ namespace ImageSharp.Formats
using System.Linq;
using System.Runtime.CompilerServices;
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using static ComparableExtensions;
@@ -503,8 +504,8 @@ namespace ImageSharp.Formats
this.currentRowBytesRead = 0;
- BufferSpan scanSpan = this.scanline.Slice(0, bytesPerInterlaceScanline);
- BufferSpan prevSpan = this.previousScanline.Span.Slice(0, bytesPerInterlaceScanline);
+ Span scanSpan = this.scanline.Slice(0, bytesPerInterlaceScanline);
+ Span prevSpan = this.previousScanline.Span.Slice(0, bytesPerInterlaceScanline);
var filterType = (FilterType)scanSpan[0];
switch (filterType)
@@ -565,8 +566,8 @@ namespace ImageSharp.Formats
where TPixel : struct, IPixel
{
var color = default(TPixel);
- BufferSpan pixelBuffer = pixels.GetRowSpan(this.currentRow);
- var scanlineBuffer = new BufferSpan(defilteredScanline, 1);
+ Span pixelBuffer = pixels.GetRowSpan(this.currentRow);
+ var scanlineBuffer = new Span(defilteredScanline, 1);
switch (this.PngColorType)
{
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 44f1513ee..49c18db34 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -10,6 +10,8 @@ namespace ImageSharp.Formats
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Quantizers;
@@ -340,15 +342,15 @@ namespace ImageSharp.Formats
private void CollecTPixelBytes(PixelAccessor pixels, int row)
where TPixel : struct, IPixel
{
- BufferSpan rowSpan = pixels.GetRowSpan(row);
+ Span rowSpan = pixels.GetRowSpan(row);
if (this.bytesPerPixel == 4)
{
- PixelOperations.Instance.ToXyzwBytes(rowSpan, this.rawScanline, this.width);
+ PixelOperations.Instance.ToXyzwBytes(rowSpan, this.rawScanline, 0, this.width);
}
else
{
- PixelOperations.Instance.ToXyzBytes(rowSpan, this.rawScanline, this.width);
+ PixelOperations.Instance.ToXyzBytes(rowSpan, this.rawScanline, 0, this.width);
}
}
@@ -387,8 +389,8 @@ namespace ImageSharp.Formats
/// The
private Buffer GetOptimalFilteredScanline()
{
- BufferSpan scanSpan = this.rawScanline.Span;
- BufferSpan prevSpan = this.previousScanline.Span;
+ Span scanSpan = this.rawScanline.Span;
+ Span prevSpan = this.previousScanline.Span;
// Palette images don't compress well with adaptive filtering.
if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8)
@@ -442,7 +444,7 @@ namespace ImageSharp.Formats
/// The last variation sum
/// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private int CalculateTotalVariation(BufferSpan scanline, int lastSum)
+ private int CalculateTotalVariation(Span scanline, int lastSum)
{
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
int sum = 0;
diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs
index d5023c4ba..4fd9d26cb 100644
--- a/src/ImageSharp/Image/ImageBase{TPixel}.cs
+++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs
@@ -7,6 +7,8 @@ namespace ImageSharp
{
using System;
using System.Diagnostics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Processing;
diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs
index 1e46a672e..f4c7c7642 100644
--- a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs
+++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs
@@ -9,6 +9,8 @@ namespace ImageSharp
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
@@ -114,7 +116,7 @@ namespace ImageSharp
public ParallelOptions ParallelOptions { get; }
///
- BufferSpan IBuffer2D.Span => this.pixelBuffer;
+ Span IBuffer2D.Span => this.pixelBuffer;
private static PixelOperations Operations => PixelOperations.Instance;
@@ -250,7 +252,7 @@ namespace ImageSharp
/// The target pixel buffer accessor.
internal void CopyTo(PixelAccessor target)
{
- BufferSpan.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span);
+ SpanHelper.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span);
}
///
@@ -266,8 +268,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = area.GetRowSpan(y);
- BufferSpan destination = this.GetRowSpan(targetX, targetY + y);
+ Span source = area.GetRowSpan(y);
+ Span destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromZyxBytes(source, destination, width);
}
@@ -286,8 +288,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = area.GetRowSpan(y);
- BufferSpan destination = this.GetRowSpan(targetX, targetY + y);
+ Span source = area.GetRowSpan(y);
+ Span destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromZyxwBytes(source, destination, width);
}
@@ -306,8 +308,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = area.GetRowSpan(y);
- BufferSpan destination = this.GetRowSpan(targetX, targetY + y);
+ Span source = area.GetRowSpan(y);
+ Span destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromXyzBytes(source, destination, width);
}
@@ -326,8 +328,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = area.GetRowSpan(y);
- BufferSpan destination = this.GetRowSpan(targetX, targetY + y);
+ Span source = area.GetRowSpan(y);
+ Span destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromXyzwBytes(source, destination, width);
}
}
@@ -345,9 +347,11 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = this.GetRowSpan(sourceX, sourceY + y);
- BufferSpan destination = area.GetRowSpan(y);
- Operations.ToZyxBytes(source, destination, width);
+ Span source = this.GetRowSpan(sourceX, sourceY + y);
+ using (Buffer destination = new Buffer(area.Bytes))
+ {
+ Operations.ToZyxBytes(source, destination, y * area.RowStride, width);
+ }
}
}
@@ -364,9 +368,11 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = this.GetRowSpan(sourceX, sourceY + y);
- BufferSpan destination = area.GetRowSpan(y);
- Operations.ToZyxwBytes(source, destination, width);
+ Span source = this.GetRowSpan(sourceX, sourceY + y);
+ using (Buffer destination = new Buffer(area.Bytes))
+ {
+ Operations.ToZyxwBytes(source, destination, y * area.RowStride, width);
+ }
}
}
@@ -383,9 +389,11 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = this.GetRowSpan(sourceX, sourceY + y);
- BufferSpan destination = area.GetRowSpan(y);
- Operations.ToXyzBytes(source, destination, width);
+ Span source = this.GetRowSpan(sourceX, sourceY + y);
+ using (Buffer destination = new Buffer(area.Bytes))
+ {
+ Operations.ToXyzBytes(source, destination, y * area.RowStride, width);
+ }
}
}
@@ -402,9 +410,11 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
- BufferSpan source = this.GetRowSpan(sourceX, sourceY + y);
- BufferSpan destination = area.GetRowSpan(y);
- Operations.ToXyzwBytes(source, destination, width);
+ Span source = this.GetRowSpan(sourceX, sourceY + y);
+ using (Buffer destination = new Buffer(area.Bytes))
+ {
+ Operations.ToXyzwBytes(source, destination, y * area.RowStride, width);
+ }
}
}
diff --git a/src/ImageSharp/Image/PixelArea{TPixel}.cs b/src/ImageSharp/Image/PixelArea{TPixel}.cs
index 3dd187768..4ddfcadb7 100644
--- a/src/ImageSharp/Image/PixelArea{TPixel}.cs
+++ b/src/ImageSharp/Image/PixelArea{TPixel}.cs
@@ -8,6 +8,8 @@ namespace ImageSharp
using System;
using System.Diagnostics;
using System.IO;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
@@ -191,11 +193,11 @@ namespace ImageSharp
}
///
- /// Gets a to the row y.
+ /// Gets a to the row y.
///
/// The y coordinate
- /// The
- internal BufferSpan GetRowSpan(int y)
+ /// The
+ internal Span GetRowSpan(int y)
{
return this.byteBuffer.Slice(y * this.RowStride);
}
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index 0269e770f..6194be1bf 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -38,8 +38,9 @@
All
+
-
+
diff --git a/src/ImageSharp/Common/Memory/Buffer.cs b/src/ImageSharp/Memory/Buffer.cs
similarity index 88%
rename from src/ImageSharp/Common/Memory/Buffer.cs
rename to src/ImageSharp/Memory/Buffer.cs
index c26b8ea18..a894ea53a 100644
--- a/src/ImageSharp/Common/Memory/Buffer.cs
+++ b/src/ImageSharp/Memory/Buffer.cs
@@ -3,10 +3,9 @@
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
using System;
- using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -97,9 +96,9 @@ namespace ImageSharp
public T[] Array { get; private set; }
///
- /// Gets a to the backing buffer.
+ /// Gets a to the backing buffer.
///
- public BufferSpan Span => this;
+ public Span Span => this;
///
/// Returns a reference to specified element of the buffer.
@@ -117,13 +116,13 @@ namespace ImageSharp
}
///
- /// Converts to an .
+ /// Converts to an .
///
/// The to convert.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static implicit operator BufferSpan(Buffer buffer)
+ public static implicit operator Span(Buffer buffer)
{
- return new BufferSpan(buffer.Array, 0, buffer.Length);
+ return new Span(buffer.Array, 0, buffer.Length);
}
///
@@ -140,26 +139,26 @@ namespace ImageSharp
}
///
- /// Gets a to an offseted position inside the buffer.
+ /// Gets a to an offseted position inside the buffer.
///
/// The start
- /// The
+ /// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan Slice(int start)
+ public Span Slice(int start)
{
- return new BufferSpan(this.Array, start, this.Length - start);
+ return new Span(this.Array, start, this.Length - start);
}
///
- /// Gets a to an offseted position inside the buffer.
+ /// Gets a to an offsetted position inside the buffer.
///
/// The start
/// The length of the slice
- /// The
+ /// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferSpan Slice(int start, int length)
+ public Span Slice(int start, int length)
{
- return new BufferSpan(this.Array, start, length);
+ return new Span(this.Array, start, length);
}
///
@@ -210,7 +209,7 @@ namespace ImageSharp
}
///
- /// Clears the buffer, filling elements between 0 and -1 with default(T)
+ /// Clears the contents of this buffer.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear()
diff --git a/src/ImageSharp/Common/Memory/Buffer2D.cs b/src/ImageSharp/Memory/Buffer2D.cs
similarity index 98%
rename from src/ImageSharp/Common/Memory/Buffer2D.cs
rename to src/ImageSharp/Memory/Buffer2D.cs
index c4eb50700..e5ccfbd19 100644
--- a/src/ImageSharp/Common/Memory/Buffer2D.cs
+++ b/src/ImageSharp/Memory/Buffer2D.cs
@@ -3,9 +3,8 @@
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
- using System;
using System.Runtime.CompilerServices;
///
diff --git a/src/ImageSharp/Common/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs
similarity index 71%
rename from src/ImageSharp/Common/Memory/Buffer2DExtensions.cs
rename to src/ImageSharp/Memory/Buffer2DExtensions.cs
index 4c3cc4d40..51e558281 100644
--- a/src/ImageSharp/Common/Memory/Buffer2DExtensions.cs
+++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs
@@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
using System;
using System.Runtime.CompilerServices;
@@ -14,29 +14,29 @@ namespace ImageSharp
internal static class Buffer2DExtensions
{
///
- /// Gets a to the row 'y' beginning from the pixel at 'x'.
+ /// Gets a to the row 'y' beginning from the pixel at 'x'.
///
/// The buffer
/// The x coordinate (position in the row)
/// The y (row) coordinate
/// The element type
- /// The
+ /// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static BufferSpan GetRowSpan(this IBuffer2D buffer, int x, int y)
+ public static Span GetRowSpan(this IBuffer2D buffer, int x, int y)
where T : struct
{
return buffer.Span.Slice((y * buffer.Width) + x, buffer.Width - x);
}
///
- /// Gets a to the row 'y' beginning from the pixel at 'x'.
+ /// Gets a to the row 'y' beginning from the pixel at 'x'.
///
/// The buffer
/// The y (row) coordinate
/// The element type
- /// The
+ /// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static BufferSpan GetRowSpan(this IBuffer2D buffer, int y)
+ public static Span GetRowSpan(this IBuffer2D buffer, int y)
where T : struct
{
return buffer.Span.Slice(y * buffer.Width, buffer.Width);
diff --git a/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs b/src/ImageSharp/Memory/Fast2DArray{T}.cs
similarity index 96%
rename from src/ImageSharp/Common/Memory/Fast2DArray{T}.cs
rename to src/ImageSharp/Memory/Fast2DArray{T}.cs
index 401c83ce6..260c829e2 100644
--- a/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs
+++ b/src/ImageSharp/Memory/Fast2DArray{T}.cs
@@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
using System;
using System.Diagnostics;
@@ -94,11 +94,11 @@ namespace ImageSharp
}
///
- /// Performs an implicit conversion from a 2D array to a .
+ /// Performs an implicit conversion from a 2D array to a .
///
/// The source array.
///
- /// The represenation on the source data.
+ /// The represenation on the source data.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Fast2DArray(T[,] data)
diff --git a/src/ImageSharp/Common/Memory/IBuffer2D.cs b/src/ImageSharp/Memory/IBuffer2D.cs
similarity index 84%
rename from src/ImageSharp/Common/Memory/IBuffer2D.cs
rename to src/ImageSharp/Memory/IBuffer2D.cs
index 1ba08e49f..300c29a1b 100644
--- a/src/ImageSharp/Common/Memory/IBuffer2D.cs
+++ b/src/ImageSharp/Memory/IBuffer2D.cs
@@ -3,8 +3,10 @@
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
+ using System;
+
///
/// An interface that represents a pinned buffer of value type objects
/// interpreted as a 2D region of x elements.
@@ -24,8 +26,8 @@ namespace ImageSharp
int Height { get; }
///
- /// Gets a to the backing buffer.
+ /// Gets a to the backing buffer.
///
- BufferSpan Span { get; }
+ Span Span { get; }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs b/src/ImageSharp/Memory/PixelDataPool{T}.cs
similarity index 98%
rename from src/ImageSharp/Common/Memory/PixelDataPool{T}.cs
rename to src/ImageSharp/Memory/PixelDataPool{T}.cs
index 0ec367d24..a8b5501cc 100644
--- a/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs
+++ b/src/ImageSharp/Memory/PixelDataPool{T}.cs
@@ -3,9 +3,8 @@
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
- using System;
using System.Buffers;
using ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Memory/SpanHelper.cs
similarity index 82%
rename from src/ImageSharp/Common/Memory/BufferSpan.cs
rename to src/ImageSharp/Memory/SpanHelper.cs
index f8a5453a8..57b771591 100644
--- a/src/ImageSharp/Common/Memory/BufferSpan.cs
+++ b/src/ImageSharp/Memory/SpanHelper.cs
@@ -1,19 +1,18 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageSharp
+namespace ImageSharp.Memory
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
///
- /// Utility methods for
+ /// Utility methods for
///
- internal static class BufferSpan
+ internal static class SpanHelper
{
///
/// Fetches a from the beginning of the span.
@@ -22,7 +21,7 @@ namespace ImageSharp
/// The span to fetch the vector from
/// A reference to the beginning of the span
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref Vector FetchVector(this BufferSpan span)
+ public static ref Vector FetchVector(this Span span)
where T : struct
{
return ref Unsafe.As>(ref span.DangerousGetPinnableReference());
@@ -32,11 +31,11 @@ namespace ImageSharp
/// Copy 'count' number of elements of the same type from 'source' to 'dest'
///
/// The element type.
- /// The to copy elements from.
- /// The destination .
+ /// The to copy elements from.
+ /// The destination .
/// The number of elements to copy
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(BufferSpan source, BufferSpan destination, int count)
+ public static unsafe void Copy(Span source, Span destination, int count)
where T : struct
{
DebugGuard.MustBeLessThanOrEqualTo(count, source.Length, nameof(count));
@@ -48,6 +47,7 @@ namespace ImageSharp
int byteCount = Unsafe.SizeOf() * count;
// TODO: Use unfixed Unsafe.CopyBlock(ref T, ref T, int) for small blocks, when it gets available!
+ // This is now available. Check with Anton re intent. Do we replace both ifdefs?
fixed (byte* pSrc = &srcRef)
fixed (byte* pDest = &destRef)
{
@@ -64,10 +64,10 @@ namespace ImageSharp
/// Copy all elements of 'source' into 'destination'.
///
/// The element type.
- /// The to copy elements from.
- /// The destination .
+ /// The to copy elements from.
+ /// The destination .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Copy(BufferSpan source, BufferSpan destination)
+ public static void Copy(Span source, Span destination)
where T : struct
{
Copy(source, destination, source.Length);
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs
index ab3aee041..261a98674 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs
@@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders
{
using System;
using System.Numerics;
+
+ using ImageSharp.Memory;
using ImageSharp.PixelFormats;
///
@@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders
}
///
- public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount)
+ public override void Blend(Span destination, Span background, Span source, Span amount)
{
Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length));
Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
@@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders
using (Buffer buffer = new Buffer(destination.Length * 3))
{
- BufferSpan destinationSpan = buffer.Slice(0, destination.Length);
- BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length);
- BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
+ Span