diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs index 826f5f60a..f2054ee0d 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs @@ -90,16 +90,23 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes MemoryManager memoryManager = this.Target.MemoryManager; - using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) + if (this.Options.BlendPercentage == 1f) { - Span amountSpan = amountBuffer.Span; - - for (int i = 0; i < scanline.Length; i++) + this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, scanline); + } + else + { + using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) { - amountSpan[i] = scanline[i] * this.Options.BlendPercentage; - } + Span amountSpan = amountBuffer.Span; + + for (int i = 0; i < scanline.Length; i++) + { + amountSpan[i] = scanline[i] * this.Options.BlendPercentage; + } - this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); + this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); + } } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs index e4ef44564..0ef7db419 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Drawing.Brushes; @@ -49,38 +50,57 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors int minY = Math.Max(0, startY); int maxY = Math.Min(source.Height, endY); - // Reset offset if necessary. - if (minX > 0) - { - startX = 0; - } - - if (minY > 0) - { - startY = 0; - } - int width = maxX - minX; - using (IBuffer amount = source.MemoryManager.Allocate(width)) - using (BrushApplicator applicator = this.brush.CreateApplicator( - source, - sourceRectangle, - this.options)) - { - amount.Span.Fill(this.options.BlendPercentage); + var solidBrush = this.brush as SolidBrush; + // If there's no reason for blending, then avoid it. + if (solidBrush != null && this.options.BlendPercentage == 1f && solidBrush.Color.ToVector4().Z == 1f) + { Parallel.For( minY, maxY, configuration.ParallelOptions, y => - { - int offsetY = y - startY; - int offsetX = minX - startX; + { + int offsetY = y - startY; + int offsetX = minX - startX; + source.GetPixelRowSpan(y).Slice(minX, width).Fill(solidBrush.Color); + }); + } + else + { + // Reset offset if necessary. + if (minX > 0) + { + startX = 0; + } + + if (minY > 0) + { + startY = 0; + } + + using (IBuffer amount = source.MemoryManager.Allocate(width)) + using (BrushApplicator applicator = this.brush.CreateApplicator( + source, + sourceRectangle, + this.options)) + { + amount.Span.Fill(this.options.BlendPercentage); + + Parallel.For( + minY, + maxY, + configuration.ParallelOptions, + y => + { + int offsetY = y - startY; + int offsetX = minX - startX; - applicator.Apply(amount.Span, offsetX, offsetY); - }); + applicator.Apply(amount.Span, offsetX, offsetY); + }); + } } } }