Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@salarkhan
Copy link
Contributor

@salarkhan salarkhan commented Dec 16, 2024

Fixes: #84

Problem

I tried this with a number of different gifs, seems like it only happened with these stark black/white ones. In the specific case from the linked issue, white pixels from the witch silhouette were being incorrectly marked as transparent when they should remain opaque. The transparency is causing the previous frame's content to show through, creating the smearing effect.

in out
in out

Fix

So, we have a palette lookup table comprised of bit-crushed RGB values. For extreme colors like pure white (255,255,255), the crushed center calculation: uint32_t R_center = (R & 0xf8) | 4; meant taht for R=255, we'd get 252, aka a slightly different color than what we actually had.

When comparing colors for transparency optimization, the least_dist we got from palette matching might have been larger than it should have been (because we used approximated colors), making it more likely for the transparency choice to "win" the comparison.

By using the actual RGB values instead, we get more accurate color matching against the palette, which means least_dist is more likely to be small for exact color matches. This makes it less likely for the transparency optimization to incorrectly override a good palette color match, especially for extreme colors like pure white or black.

@salarkhan salarkhan requested a review from skidder December 16, 2024 18:26
@skidder
Copy link
Contributor

skidder commented Dec 16, 2024

lgtm!

@salarkhan salarkhan merged commit c2b5911 into master Dec 16, 2024
2 checks passed
@salarkhan salarkhan deleted the sk/gif-smear-crush branch December 16, 2024 18:53
@ace-dent
Copy link

ace-dent commented Apr 1, 2025

@salarkhan @skidder - any idea if this fix is now live in Production?
May have an issue, but based on direct testing with Discord website.

@skidder
Copy link
Contributor

skidder commented Apr 10, 2025

@salarkhan @skidder - any idea if this fix is now live in Production? May have an issue, but based on direct testing with Discord website.

Yes, this should have been out in production for a while. What sort of behavior have you seen? (also, thanks for chiming in here!)

@ace-dent
Copy link

@skidder - running test images through live Discord (on web), I find that dark / light colours are clipped to 5bits (as expected)- but still have +4 (|+4)- so the mid-point bias is applied. This means the darkest colour is rgb(4,4,4). I can raise a new issue and attach test images... but it may be expected behaviour?...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some .gifs are incorrectly "smearing"

4 participants