Browse Source

Update EuclideanPixelMap{TPixel}.cs

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
69baffb35c
  1. 24
      src/ImageSharp/Processing/Processors/Dithering/EuclideanPixelMap{TPixel}.cs

24
src/ImageSharp/Processing/Processors/Dithering/EuclideanPixelMap{TPixel}.cs

@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public byte GetClosestColor(TPixel color, out TPixel match) public byte GetClosestColor(TPixel color, out TPixel match)
{ {
ReadOnlySpan<TPixel> paletteSpan = this.palette.Span; ReadOnlySpan<TPixel> paletteSpan = this.palette.Span;
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
return this.GetClosestColorSlow(color, paletteSpan, out match); return this.GetClosestColorSlow(color, paletteSpan, out match);
} }
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private byte GetClosestColorSlow(TPixel color, ReadOnlySpan<TPixel> palette, out TPixel match) private byte GetClosestColorSlow(TPixel color, ReadOnlySpan<TPixel> palette, out TPixel match)
{ {
// Loop through the palette and find the nearest match. // Loop through the palette and find the nearest match.
@ -59,19 +59,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
Vector4 candidate = this.vectorCache[i]; Vector4 candidate = this.vectorCache[i];
float distance = Vector4.DistanceSquared(vector, candidate); float distance = Vector4.DistanceSquared(vector, candidate);
// Greater... Move on. // Less than... assign.
if (leastDistance < distance) if (distance < leastDistance)
{ {
continue; index = i;
} leastDistance = distance;
index = i;
leastDistance = distance;
// And if it's an exact match, exit the loop // And if it's an exact match, exit the loop
if (distance == 0) if (distance == 0)
{ {
break; break;
}
} }
} }

Loading…
Cancel
Save