Browse Source

Minor performance refactorings.

Moved the division out of the loop, division is expensive.
af/merge-core
woutware 8 years ago
parent
commit
8fc424a38a
  1. 10
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
  2. 6
      src/ImageSharp/Formats/Png/PngEncoderCore.cs

10
src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs

@ -100,6 +100,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
using (BasicArrayBuffer<float> scanline = source.MemoryManager.AllocateFake<float>(scanlineWidth))
{
bool scanlineDirty = true;
float subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / subpixelCount;
for (int y = minY; y < maxY; y++)
{
if (scanlineDirty)
@ -113,9 +115,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
scanlineDirty = false;
}
float subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / subpixelCount;
for (float subPixel = (float)y; subPixel < y + 1; subPixel += subpixelFraction)
float yPlusOne = y + 1;
for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction)
{
int pointsFound = region.Scan(subPixel + offset, buffer.Array, 0);
if (pointsFound == 0)
@ -197,8 +198,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
private static void QuickSort(Span<float> data)
{
int hi = Math.Min(data.Length - 1, data.Length - 1);
QuickSort(data, 0, hi);
QuickSort(data, 0, data.Length - 1);
}
private static void QuickSort(Span<float> data, int lo, int hi)

6
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -321,9 +321,6 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <returns>The <see cref="T:byte[]"/></returns>
private IManagedByteBuffer GetOptimalFilteredScanline()
{
Span<byte> scanSpan = this.rawScanline.Span;
Span<byte> prevSpan = this.previousScanline.Span;
// Palette images don't compress well with adaptive filtering.
if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8)
{
@ -331,6 +328,9 @@ namespace SixLabors.ImageSharp.Formats.Png
return this.result;
}
Span<byte> scanSpan = this.rawScanline.Span;
Span<byte> prevSpan = this.previousScanline.Span;
// This order, while different to the enumerated order is more likely to produce a smaller sum
// early on which shaves a couple of milliseconds off the processing time.
UpFilter.Encode(scanSpan, prevSpan, this.up.Span, out int currentSum);

Loading…
Cancel
Save