|
|
|
@ -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<float> amount = source.MemoryManager.Allocate<float>(width)) |
|
|
|
using (BrushApplicator<TPixel> applicator = this.brush.CreateApplicator( |
|
|
|
source, |
|
|
|
sourceRectangle, |
|
|
|
this.options)) |
|
|
|
{ |
|
|
|
amount.Span.Fill(this.options.BlendPercentage); |
|
|
|
var solidBrush = this.brush as SolidBrush<TPixel>; |
|
|
|
|
|
|
|
// 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<float> amount = source.MemoryManager.Allocate<float>(width)) |
|
|
|
using (BrushApplicator<TPixel> 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); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|