Fix GIF transparency handling and dither#3143
Merged
Merged
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
Fixes #3142
This pull request improves GIF encoding and palette handling, especially for animated images with transparency. It ensures fully transparent pixels are properly treated during dithering and quantization, fixes issues where transparent indices were not always reserved, and adds tests for a previously failing edge case (issue #3142). The changes also introduce a transparent color to the Werner palette for better compatibility.
GIF Transparency and Palette Handling Improvements:
src/ImageSharp/Color/Color.WernerPalette.cs)src/ImageSharp/Formats/Gif/GifEncoderCore.cs) [1] [2] [3] [4] [5] [6]src/ImageSharp/Processing/Processors/Dithering/ErrorDither.cs,src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs) [1] [2]Testing and Regression Coverage:
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs,tests/ImageSharp.Tests/TestImages.cs,tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue3142_Rgba32_issue_3142.gif/*) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Test Suite Improvements:
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs)SixLabors.ImageSharp.Processingto support new test cases. (tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs)