Update and simplify quantization color caches and tests#3107
Merged
JimBobSquarePants merged 2 commits intomainfrom Apr 7, 2026
Merged
Update and simplify quantization color caches and tests#3107JimBobSquarePants merged 2 commits intomainfrom
JimBobSquarePants merged 2 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This pull request replaces the
OctreeQuantizerwith a newHexadecatreeQuantizeras the default adaptive quantizer throughout the ImageSharp codebase. The change is applied across all encoder defaults, public APIs, and internal AOT compilation helpers. Additionally, the color matching cache modes have been simplified, and the Euclidean pixel map implementation has been optimized with SIMD acceleration for faster color matching.Quantizer replacement and encoder defaults:
The
HexadecatreeQuantizerreplacesOctreeQuantizeras the default adaptive quantizer in all public APIs, includingBmpEncoder,TiffEncoder, and image processing extension methods. All references, comments, and default assignments have been updated accordingly. [1] [2] [3] [4] [5] [6] [7] [8] [9]The implementation file
OctreeQuantizer.cshas been renamed and refactored asHexadecatreeQuantizer.cs, with improved documentation and class naming. [1] [2]AOT compilation and internal helpers:
All AOT compilation helpers and references in
AotCompilerTools.csnow useHexadecatreeQuantizerinstead ofOctreeQuantizer. [1] [2] [3]Unused or redundant pixel map cache strategies (such as
HybridCacheandNullCache) have been removed from AOT helpers and color matching mode selection. [1] src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.csL180-R257, [2]Color matching and palette lookup improvements:
The Euclidean pixel map's color matching implementation is now SIMD-accelerated using
Vector128, significantly speeding up palette lookups for large palettes. The distance calculation has been changed fromfloattointfor efficiency. (src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.csR6-R7, src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.csL74-R175, src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.csL114-R196)The
Exactcolor matching mode now usesAccurateCacheinstead ofNullCache, and theHybridmode has been removed for simplification. (src/ImageSharp/Processing/Processors/Quantization/ColorMatchingMode.csL18-R19, src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.csL180-R257)These changes modernize and optimize the quantization pipeline, improve performance, and simplify the API surface for users and maintainers.