From bcb9c0057a1d2b06bb707d4135261fed7268c490 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 21 Feb 2018 01:06:59 +0100 Subject: [PATCH] passing MemoryManager to pixel blenders --- .../Brushes/ImageBrush{TPixel}.cs | 2 +- .../Brushes/PatternBrush{TPixel}.cs | 8 +- .../Brushes/Processors/BrushApplicator.cs | 8 +- .../Brushes/RecolorBrush{TPixel}.cs | 8 +- .../Brushes/SolidBrush{TPixel}.cs | 7 +- .../Processors/DrawImageProcessor.cs | 7 +- src/ImageSharp/ApplyProcessors.cs | 1 - .../DefaultInternalImageProcessorContext.cs | 2 +- .../IImageProcessingContext{TPixel}.cs | 13 +- .../DefaultPixelBlenders.Generated.cs | 126 +++++++++--------- .../DefaultPixelBlenders.Generated.tt | 6 +- .../PixelFormats/PixelBlender{TPixel}.cs | 4 +- .../Processing/ColorMatrix/Lomograph.cs | 4 +- .../Processing/ColorMatrix/Polaroid.cs | 4 +- .../Processing/Effects/BackgroundColor.cs | 4 +- src/ImageSharp/Processing/Overlays/Glow.cs | 4 +- .../Processing/Overlays/Vignette.cs | 4 +- .../Effects/BackgroundColorProcessor.cs | 2 +- .../Processors/Overlays/GlowProcessor.cs | 2 +- .../Processors/Overlays/VignetteProcessor.cs | 2 +- .../Processing/Transforms/Resize.cs | 4 +- src/ImageSharp/Quantizers/Quantize.cs | 2 +- .../FakeImageOperationsProvider.cs | 2 +- .../PorterDuffFunctionsTests_TPixel.cs | 22 +-- 24 files changed, 132 insertions(+), 116 deletions(-) diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs index 6b3ce36fe..320c94c96 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs @@ -142,7 +142,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(this.source.MemoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs index 449a23da9..cc22b2639 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs @@ -152,8 +152,10 @@ namespace SixLabors.ImageSharp.Drawing.Brushes internal override void Apply(Span scanline, int x, int y) { int patternY = y % this.pattern.Height; - using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length)) + MemoryManager memoryManager = this.Target.MemoryManager; + + using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) + using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.Span; Span overlaySpan = overlay.Span; @@ -167,7 +169,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 68bc13ecb..d8ea43558 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -65,8 +65,10 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors /// 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) { - using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length)) + MemoryManager memoryManager = this.Target.MemoryManager; + + using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) + using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.Span; Span overlaySpan = overlay.Span; @@ -82,7 +84,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs index 37cba42c9..39afd965c 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -144,8 +144,10 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// internal override void Apply(Span scanline, int x, int y) { - using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) - using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length)) + MemoryManager memoryManager = this.Target.MemoryManager; + + using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) + using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.Span; Span overlaySpan = overlay.Span; @@ -162,7 +164,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes } Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - this.Blender.Blend(destinationRow, destinationRow, overlaySpan, amountSpan); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, overlaySpan, amountSpan); } } } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs index 90286cb6c..692889556 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs @@ -93,7 +93,9 @@ namespace SixLabors.ImageSharp.Drawing.Brushes { Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length); - using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) + MemoryManager memoryManager = this.Target.MemoryManager; + + using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.Span; @@ -102,11 +104,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes amountSpan[i] = scanline[i] * this.Options.BlendPercentage; } - this.Blender.Blend(destinationRow, destinationRow, this.Colors.Span, amountSpan); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); } } catch (Exception) { + // TODO: Why are we catching exceptions here silently ??? throw; } } diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 21e13d47a..54fb38ee9 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -84,7 +84,10 @@ namespace SixLabors.ImageSharp.Drawing.Processors maxY = Math.Min(this.Location.Y + this.Size.Height, maxY); int width = maxX - minX; - using (IBuffer amount = this.Image.GetConfiguration().MemoryManager.Allocate(width)) + + MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager; + + using (IBuffer amount = memoryManager.Allocate(width)) { amount.Span.Fill(this.Alpha); @@ -96,7 +99,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors { Span background = source.GetPixelRowSpan(y).Slice(minX, width); Span foreground = targetImage.GetPixelRowSpan(y - this.Location.Y).Slice(targetX, width); - this.blender.Blend(background, background, foreground, amount.Span); + this.blender.Blend(memoryManager, background, background, foreground, amount.Span); }); } } diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index 58a952c40..c4954ef0d 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -4,7 +4,6 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/DefaultInternalImageProcessorContext.cs index ac56d0277..d58f6236f 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/DefaultInternalImageProcessorContext.cs @@ -75,6 +75,6 @@ namespace SixLabors.ImageSharp return this.ApplyProcessor(processor, this.source.Bounds()); } - public MemoryManager GetMemoryManager() => this.source.GetConfiguration().MemoryManager; + public MemoryManager MemoryManager => this.source.GetConfiguration().MemoryManager; } } \ No newline at end of file diff --git a/src/ImageSharp/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/IImageProcessingContext{TPixel}.cs index 68b0a030a..b73337905 100644 --- a/src/ImageSharp/IImageProcessingContext{TPixel}.cs +++ b/src/ImageSharp/IImageProcessingContext{TPixel}.cs @@ -15,6 +15,12 @@ namespace SixLabors.ImageSharp public interface IImageProcessingContext where TPixel : struct, IPixel { + /// + /// Gets a reference to the used to allocate buffers + /// for this context. + /// + MemoryManager MemoryManager { get; } + /// /// Adds the processor to the current set of image operations to be applied. /// @@ -29,13 +35,6 @@ namespace SixLabors.ImageSharp /// The processor to apply /// The current operations class to allow chaining of operations. IImageProcessingContext ApplyProcessor(IImageProcessor processor); - - /// - /// Returns a reference to the used to allocate buffers - /// for this context. - /// - /// A to use for buffer allocations. - MemoryManager GetMemoryManager(); } /// diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 17f75898d..d3c6cf16c 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -26,7 +26,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders internal class Normal : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -39,13 +38,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -63,9 +62,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Multiply : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -78,13 +77,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -102,9 +101,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Add : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -117,13 +116,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -141,9 +140,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Substract : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -156,13 +155,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -180,9 +179,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Screen : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -195,13 +194,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -219,9 +218,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Darken : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -234,13 +233,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -258,9 +257,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Lighten : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -273,13 +272,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -297,9 +296,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Overlay : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -312,13 +311,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -336,9 +335,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class HardLight : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -351,13 +350,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -375,9 +374,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Src : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -390,13 +389,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -414,9 +413,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Atop : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -429,13 +428,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -453,9 +452,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Over : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -468,13 +467,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -492,9 +491,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class In : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -507,13 +506,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -531,9 +530,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Out : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -546,13 +545,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -570,9 +569,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Dest : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -585,13 +584,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -609,9 +608,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class DestAtop : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -624,13 +623,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -648,9 +647,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class DestOver : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -663,13 +662,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -687,9 +686,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class DestIn : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -702,13 +701,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -726,9 +725,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class DestOut : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -741,13 +740,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -765,9 +764,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Clear : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -780,13 +779,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -804,9 +803,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + internal class Xor : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -819,13 +818,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -843,5 +842,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + } } \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 75c6b2d81..eebee676f 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -68,7 +68,6 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders #> internal class <#=blender#> : PixelBlender { - /// /// Gets the static instance of this blender. /// @@ -81,13 +80,13 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(Span destination, Span background, Span source, Span amount) + public override void Blend(MemoryManager memoryManager, 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)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -105,6 +104,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } } + <# } diff --git a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs index 54cb09c28..666fb3891 100644 --- a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.PixelFormats { @@ -27,6 +28,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Blend 2 pixels together. /// + /// The /// The destination span. /// The background span. /// The source span. @@ -34,6 +36,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// A value between 0 and 1 indicating the weight of the second source vector. /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// - public abstract void Blend(Span destination, Span background, Span source, Span amount); + public abstract void Blend(MemoryManager memoryManager, Span destination, Span background, Span source, Span amount); } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index 96231e168..ca79841c7 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp public static IImageProcessingContext Lomograph(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel { - source.ApplyProcessor(new LomographProcessor(source.GetMemoryManager(), options)); + source.ApplyProcessor(new LomographProcessor(source.MemoryManager, options)); return source; } @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { - source.ApplyProcessor(new LomographProcessor(source.GetMemoryManager(), options), rectangle); + source.ApplyProcessor(new LomographProcessor(source.MemoryManager, options), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index 7cc0e2419..d12cc7612 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp public static IImageProcessingContext Polaroid(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel { - source.ApplyProcessor(new PolaroidProcessor(source.GetMemoryManager(), options)); + source.ApplyProcessor(new PolaroidProcessor(source.MemoryManager, options)); return source; } @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { - source.ApplyProcessor(new PolaroidProcessor(source.GetMemoryManager(), options), rectangle); + source.ApplyProcessor(new PolaroidProcessor(source.MemoryManager, options), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index 18caa67cc..22aad9ca6 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new BackgroundColorProcessor(source.GetMemoryManager(), color, options)); + => source.ApplyProcessor(new BackgroundColorProcessor(source.MemoryManager, color, options)); /// /// Replaces the background color of image with the given one. @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new BackgroundColorProcessor(source.GetMemoryManager(), color, options), rectangle); + => source.ApplyProcessor(new BackgroundColorProcessor(source.MemoryManager, color, options), rectangle); /// /// Replaces the background color of image with the given one. diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index a8994b18a..0c3552b4d 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp /// The . private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new GlowProcessor(source.GetMemoryManager(), color, radius, options), rectangle); + => source.ApplyProcessor(new GlowProcessor(source.MemoryManager, color, radius, options), rectangle); /// /// Applies a radial glow effect to an image. @@ -170,6 +170,6 @@ namespace SixLabors.ImageSharp /// The . private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new GlowProcessor(source.GetMemoryManager(), color, radius, options)); + => source.ApplyProcessor(new GlowProcessor(source.MemoryManager, color, radius, options)); } } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 3a691ed00..4b9f2f866 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -151,10 +151,10 @@ namespace SixLabors.ImageSharp private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new VignetteProcessor(source.GetMemoryManager(), color, radiusX, radiusY, options), rectangle); + => source.ApplyProcessor(new VignetteProcessor(source.MemoryManager, color, radiusX, radiusY, options), rectangle); private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new VignetteProcessor(source.GetMemoryManager(), color, radiusX, radiusY, options)); + => source.ApplyProcessor(new VignetteProcessor(source.MemoryManager, color, radiusX, radiusY, options)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs index e97495a3d..720b87691 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Processors Span destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width); // This switched color & destination in the 2nd and 3rd places because we are applying the target colour under the current one - blender.Blend(destination, colors.Span, destination, amount.Span); + blender.Blend(this.memoryManager, destination, colors.Span, destination, amount.Span); }); } } diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 85c592cea..9ab301718 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.Processing.Processors Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(destination, destination, rowColors.Span, amountsSpan); + this.blender.Blend(this.memoryManager, destination, destination, rowColors.Span, amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index d0943b27b..d47211f0c 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp.Processing.Processors Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(destination, destination, rowColors.Span, amountsSpan); + this.blender.Blend(this.memoryManager, destination, destination, rowColors.Span, amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index a3a62fa49..18def03e6 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(source.GetMemoryManager(), sampler, width, height, targetRectangle) { Compand = compand }, sourceRectangle)); + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(source.MemoryManager, sampler, width, height, targetRectangle) { Compand = compand }, sourceRectangle)); }); } @@ -233,7 +233,7 @@ namespace SixLabors.ImageSharp Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(source.GetMemoryManager(), sampler, width, height, targetRectangle) { Compand = compand })); + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(source.MemoryManager, sampler, width, height, targetRectangle) { Compand = compand })); }); } } diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index 0e3d806da..4052d4685 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp QuantizedImage quantized = quantizer.Quantize(img.Frames.RootFrame, maxColors); int palleteCount = quantized.Palette.Length - 1; - using (var pixels = new PixelAccessor(source.GetMemoryManager(), quantized.Width, quantized.Height)) + using (var pixels = new PixelAccessor(source.MemoryManager, quantized.Width, quantized.Height)) { Parallel.For( 0, diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index a1c199b16..c2ed7238d 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests return this; } - public MemoryManager GetMemoryManager() => this.source.GetConfiguration().MemoryManager; + public MemoryManager MemoryManager => this.source.GetConfiguration().MemoryManager; public struct AppliedOpperation { diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index b95f8fdf6..50babde69 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -12,6 +12,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { + using SixLabors.ImageSharp.Memory; + public class PorterDuffFunctionsTests_TPixel { private static Span AsSpan(T value) @@ -25,6 +27,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { new TestPixel(1,1,1,1), new TestPixel(0,0,0,.8f), .5f, new TestPixel(0.6f, 0.6f, 0.6f, 1) }, }; + private MemoryManager MemoryManager { get; } = Configuration.Default.MemoryManager; + [Theory] [MemberData(nameof(NormalBlendFunctionData))] public void NormalBlendFunction(TestPixel back, TestPixel source, float amount, TestPixel expected) @@ -49,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Normal().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Normal().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -88,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Multiply().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Multiply().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -127,7 +131,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Add().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Add().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -166,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Substract().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Substract().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -205,7 +209,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Screen().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Screen().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -244,7 +248,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Darken().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Darken().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -283,7 +287,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Lighten().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Lighten().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -322,7 +326,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Overlay().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Overlay().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -361,7 +365,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.HardLight().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.HardLight().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } }