Skip to content

Quality loss when quantizing an image that already has (fewer than) 256 colors #2862

Discussion options

You must be logged in to vote

Man... Oh man... Have I spent some time on this. It turns out implementing such a thing but keeping it fast is hard!

Here's what I've come up with. It 1.4x - 2x slower than the current approach depending on the number of collisions but will give you your accuracy for the first 256 colors.

Proposed implementation
    /// <summary>
    /// A hybrid cache for color distance lookups that combines an exact-match dictionary with
    /// a fallback coarse lookup table.
    /// </summary>
    /// <remarks>
    /// This cache uses a fallback table with 1,048,576 bins, each storing a 2-byte value
    /// (approximately 2 MB total), while the exact-match dictionary is limited to 256 entries
    ///…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@pwitvoet
Comment options

@JimBobSquarePants
Comment options

Answer selected by pwitvoet
@pwitvoet
Comment options

@JimBobSquarePants
Comment options

@pwitvoet
Comment options

@JimBobSquarePants
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2861 on January 15, 2025 00:54.