Skip to content

Update and simplify quantization color caches and tests#3107

Merged
JimBobSquarePants merged 2 commits intomainfrom
js/quantizer-cache
Apr 7, 2026
Merged

Update and simplify quantization color caches and tests#3107
JimBobSquarePants merged 2 commits intomainfrom
js/quantizer-cache

Conversation

@JimBobSquarePants
Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This pull request replaces the OctreeQuantizer with a new HexadecatreeQuantizer as 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 HexadecatreeQuantizer replaces OctreeQuantizer as the default adaptive quantizer in all public APIs, including BmpEncoder, 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.cs has been renamed and refactored as HexadecatreeQuantizer.cs, with improved documentation and class naming. [1] [2]

AOT compilation and internal helpers:

  • All AOT compilation helpers and references in AotCompilerTools.cs now use HexadecatreeQuantizer instead of OctreeQuantizer. [1] [2] [3]

  • Unused or redundant pixel map cache strategies (such as HybridCache and NullCache) 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 from float to int for 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 Exact color matching mode now uses AccurateCache instead of NullCache, and the Hybrid mode 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.

@JimBobSquarePants JimBobSquarePants added enhancement area:quantizers breaking Signifies a binary breaking change. labels Apr 7, 2026
@JimBobSquarePants JimBobSquarePants merged commit b6c4bb8 into main Apr 7, 2026
12 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/quantizer-cache branch April 7, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:quantizers breaking Signifies a binary breaking change. enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant