diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
index f3ea81cf6..636f3a5a4 100644
--- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
@@ -112,9 +112,12 @@ namespace ImageSharp.Drawing.Brushes
this.source.Dispose();
}
- internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
+ ///
+ internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
- using (PinnedBuffer buffer = new PinnedBuffer(scanline))
+ DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
+
+ using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
{
BufferPointer slice = buffer.Slice(offset);
diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
index 55152d234..c718ce1f4 100644
--- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
@@ -144,9 +144,12 @@ namespace ImageSharp.Drawing.Brushes
// noop
}
- internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
+ ///
+ internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
- using (PinnedBuffer buffer = new PinnedBuffer(scanline))
+ DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
+
+ using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
{
BufferPointer slice = buffer.Slice(offset);
diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
index 679d87170..a4f1eeaed 100644
--- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
+++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
@@ -45,14 +45,17 @@ namespace ImageSharp.Drawing.Processors
///
/// Applies the opactiy weighting for each pixel in a scanline to the target based on the pattern contained in the brush.
///
- /// The a collection of opacity values between 0 and 1 to be merged with the burshed color value before being applied to the target.
+ /// The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target.
/// The number of pixels effected by this scanline.
/// The offset fromthe begining of the opacity data starts.
/// 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.
- internal virtual void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
+ /// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.
+ internal virtual void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
- using (PinnedBuffer buffer = new PinnedBuffer(scanline))
+ DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
+
+ using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
{
BufferPointer slice = buffer.Slice(offset);
diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
index 92e519161..cdfc23b91 100644
--- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
@@ -136,9 +136,12 @@ namespace ImageSharp.Drawing.Brushes
{
}
- internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
+ ///
+ internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
- using (PinnedBuffer buffer = new PinnedBuffer(scanline))
+ DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
+
+ using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
{
BufferPointer slice = buffer.Slice(offset);
diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
index bdac7fdc7..e3413328e 100644
--- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
@@ -84,9 +84,12 @@ namespace ImageSharp.Drawing.Brushes
// noop
}
- internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
+ ///
+ internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
- using (PinnedBuffer buffer = new PinnedBuffer(scanline))
+ DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
+
+ using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
{
BufferPointer slice = buffer.Slice(offset);