Browse Source
Merge pull request #765 from cwensley/curtis/optimize-solid-fill-region
Optimize filling a region with a solid brush when antialias is off
af/merge-core
James Jackson-South
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
29 additions and
1 deletions
-
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs
|
|
|
@ -3,7 +3,7 @@ |
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Buffers; |
|
|
|
|
|
|
|
using SixLabors.ImageSharp.Advanced; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Primitives; |
|
|
|
@ -107,6 +107,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing |
|
|
|
Span<float> buffer = bBuffer.GetSpan(); |
|
|
|
Span<float> scanline = bScanline.GetSpan(); |
|
|
|
|
|
|
|
bool isSolidBrushWithoutBlending = this.IsSolidBrushWithoutBlending(out SolidBrush<TPixel> solidBrush); |
|
|
|
|
|
|
|
for (int y = minY; y < maxY; y++) |
|
|
|
{ |
|
|
|
if (scanlineDirty) |
|
|
|
@ -168,16 +170,30 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing |
|
|
|
{ |
|
|
|
if (!this.Options.Antialias) |
|
|
|
{ |
|
|
|
bool hasOnes = false; |
|
|
|
bool hasZeros = false; |
|
|
|
for (int x = 0; x < scanlineWidth; x++) |
|
|
|
{ |
|
|
|
if (scanline[x] >= 0.5) |
|
|
|
{ |
|
|
|
scanline[x] = 1; |
|
|
|
hasOnes = true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
scanline[x] = 0; |
|
|
|
hasZeros = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isSolidBrushWithoutBlending && hasOnes != hasZeros) |
|
|
|
{ |
|
|
|
if (hasOnes) |
|
|
|
{ |
|
|
|
source.GetPixelRowSpan(y).Slice(minX, scanlineWidth).Fill(solidBrush.Color); |
|
|
|
} |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -187,5 +203,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private bool IsSolidBrushWithoutBlending(out SolidBrush<TPixel> solidBrush) |
|
|
|
{ |
|
|
|
solidBrush = this.Brush as SolidBrush<TPixel>; |
|
|
|
|
|
|
|
if (solidBrush == null) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return this.Options.IsOpaqueColorWithoutBlending(solidBrush.Color); |
|
|
|
} |
|
|
|
} |
|
|
|
} |