|
|
|
@ -26,7 +26,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel> |
|
|
|
private readonly int maxColors; |
|
|
|
private readonly int bitDepth; |
|
|
|
private readonly Octree octree; |
|
|
|
private IMemoryOwner<TPixel>? paletteOwner; |
|
|
|
private IMemoryOwner<TPixel> paletteOwner; |
|
|
|
private ReadOnlyMemory<TPixel> palette; |
|
|
|
private EuclideanPixelMap<TPixel>? pixelMap; |
|
|
|
private readonly bool isDithering; |
|
|
|
@ -98,7 +98,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel> |
|
|
|
} |
|
|
|
|
|
|
|
int paletteIndex = 0; |
|
|
|
Span<TPixel> paletteSpan = this.paletteOwner!.GetSpan(); |
|
|
|
Span<TPixel> paletteSpan = this.paletteOwner.GetSpan(); |
|
|
|
|
|
|
|
// On very rare occasions, (blur.png), the quantizer does not preserve a
|
|
|
|
// transparent entry when palletizing the captured colors.
|
|
|
|
@ -112,7 +112,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel> |
|
|
|
} |
|
|
|
|
|
|
|
this.octree.Palletize(paletteSpan, max, ref paletteIndex); |
|
|
|
ReadOnlyMemory<TPixel> result = this.paletteOwner!.Memory[..paletteSpan.Length]; |
|
|
|
ReadOnlyMemory<TPixel> result = this.paletteOwner.Memory[..paletteSpan.Length]; |
|
|
|
|
|
|
|
// When called multiple times by QuantizerUtilities.BuildPalette
|
|
|
|
// this prevents memory churn caused by reallocation.
|
|
|
|
@ -157,8 +157,7 @@ public struct OctreeQuantizer<TPixel> : IQuantizer<TPixel> |
|
|
|
if (!this.isDisposed) |
|
|
|
{ |
|
|
|
this.isDisposed = true; |
|
|
|
this.paletteOwner?.Dispose(); |
|
|
|
this.paletteOwner = null; |
|
|
|
this.paletteOwner.Dispose(); |
|
|
|
this.pixelMap?.Dispose(); |
|
|
|
this.pixelMap = null; |
|
|
|
} |
|
|
|
|