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

Skip to content

Conversation

@skidder
Copy link
Contributor

@skidder skidder commented Apr 12, 2025

This PR implements support for the "Restore to Previous" disposal method in GIF decoding, addressing issue #234. The implementation stores the previous frame's content in a buffer to enable proper restoration when DISPOSE_PREVIOUS is encountered, and changes the default disposal method for unspecified frames to DISPOSE_NONE per the GIF89a specification (section 23):

            iv) Disposal Method - Indicates the way in which the graphic is to
            be treated after being displayed.

            Values :    0 -   No disposal specified. The decoder is
                              not required to take any action.
                        1 -   Do not dispose. The graphic is to be left
                              in place.
                        2 -   Restore to background color. The area used by the
                              graphic must be restored to the background color.
                        3 -   Restore to previous. The decoder is required to
                              restore the area overwritten by the graphic with
                              what was there prior to rendering the graphic.
                     4-7 -    To be defined.

While this increases memory usage by width * height * 4 bytes, it's a reasonable tradeoff for correct behavior and matches modern browser implementations. Tested with the sample GIF from the issue using GIF Inspector.

skidder added 3 commits April 12, 2025 07:21
- Replace raw pointer with std::vector for safer memory management
- Add BYTES_PER_PIXEL constant to replace magic number 4
- Improve documentation of edge case handling with detailed comments
- Explicitly document handling of frames with negative offsets and bounds clipping
@skidder skidder marked this pull request as ready for review April 21, 2025 16:04
@skidder skidder merged commit 2cb03a6 into master Apr 29, 2025
5 checks passed
@skidder skidder deleted the skidder/additional-gif-disposal-methods branch April 29, 2025 16:32
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.

3 participants