diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index aa0b2e9b23..95ac3fe298 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -100,6 +100,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors using (BasicArrayBuffer scanline = source.MemoryManager.AllocateFake(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 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 data, int lo, int hi) diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 777ee1f543..b95e102c76 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -321,9 +321,6 @@ namespace SixLabors.ImageSharp.Formats.Png /// The private IManagedByteBuffer GetOptimalFilteredScanline() { - Span scanSpan = this.rawScanline.Span; - Span 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 scanSpan = this.rawScanline.Span; + Span 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);