-
-
Notifications
You must be signed in to change notification settings - Fork 170
loader: Add support for gif #3975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for loading and animating GIF images in ThorVG's picture loader. The implementation provides two paths: an internal custom GIF decoder with LZW decompression, and support for using the external giflib library.
Key changes:
- Implements a complete GIF decoder with LZW decompression and frame compositing
- Adds animation support for GIF playback
- Integrates GIF format into the loader system with file extension and MIME type recognition
Reviewed Changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| meson.build | Adds gif_loader configuration option and support flag |
| meson_options.txt | Adds 'gif' to available loader choices |
| src/renderer/tvgLoader.cpp | Registers GIF file type and extension/MIME type mappings |
| src/loaders/meson.build | Adds conditional GIF loader build logic |
| src/loaders/gif/tvgGifDecoder.h | Defines internal GIF decoder structures and interface |
| src/loaders/gif/tvgGifDecoder.cpp | Implements LZW decompression and GIF parsing |
| src/loaders/gif/tvgGifLoader.h | Defines internal GIF loader class |
| src/loaders/gif/tvgGifLoader.cpp | Implements GIF loading and frame animation |
| src/loaders/gif/meson.build | Build configuration for internal GIF loader |
| src/loaders/external_gif/tvgGifLoader.h | Defines giflib-based loader class |
| src/loaders/external_gif/tvgGifLoader.cpp | Implements giflib-based GIF loading |
| src/loaders/external_gif/meson.build | Build configuration for external GIF loader |
| examples/GifAnimation.cpp | Example demonstrating GIF animation usage |
| examples/meson.build | Adds GIF animation example to build |
| examples/resources/image/test.gif | Test GIF asset for examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaced static_cast with reinterpret_cast for converting frame.pixels to uint32_t* in GifDecoder::load. This ensures correct pointer type conversion for pixel data.
Removed redundant conditional assignments for startX and startY in the compositeFrame method, setting them directly to 0 for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 20 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ac9b628 to
eec09a7
Compare
Replaces usage of uint8_t* with unsigned char* for memory allocation and casting in GIF loader implementations. This change ensures consistent type usage and resolves potential type mismatches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 15 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@BenjaminHalko Thanks, Could you please resolve the copilot comments? (you can close them if they are false-alarm) |
Refines GIF frame compositing to correctly handle the DISPOSE_PREVIOUS disposal mode, skipping drawing for frames with this mode during reset. Updates compositeFrame signatures to accept a 'draw' flag and applies this logic in both external and internal GIF loaders. Also updates example to use tvg::Result::Success for frame status check.
96562e5 to
42561d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Updated memory operations in tvgGifLoader.cpp to use size_t for buffer sizes, preventing overflow. Adjusted bounds calculations in tvgGifDecoder.cpp to avoid overflow when computing frame dimensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaced int and uint32_t types with size_t for buffer index calculations in tvgGifLoader.cpp and tvgGifDecoder.cpp to prevent potential overflow and improve type safety when handling large images.
|
@hermet OK, I think all the issues have been fixed 👍 |
|
feature target: thorvg v2.0 |
Adds support for loading the
.gifformat inpicture. You can useanimationto animate it as well.It also supports using
giflibas an external libraryissue: #3453