Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gwaredd/mggif
A unity library to parse GIF files and extract the images as textures
https://github.com/gwaredd/mggif
gif unity
Last synced: about 2 months ago
JSON representation
A unity library to parse GIF files and extract the images as textures
- Host: GitHub
- URL: https://github.com/gwaredd/mggif
- Owner: gwaredd
- License: mit
- Created: 2020-08-19T20:01:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-08-29T11:58:03.000Z (over 1 year ago)
- Last Synced: 2024-10-21T22:52:40.911Z (2 months ago)
- Topics: gif, unity
- Language: C#
- Homepage:
- Size: 9.27 MB
- Stars: 124
- Watchers: 3
- Forks: 25
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mgGIF
> A unity library to parse a GIF file and extracts the images, just for fun![Butterfly](https://gwaredd.github.io/mgGif/butterfly.gif)
## Installation
Copy [Assets\mgGif\mgGif.cs](https://github.com/gwaredd/mgGif/blob/master/Assets/mgGif/mgGif.cs) to your project.
Alternatively, the [upm](https://github.com/gwaredd/mgGif/tree/upm) branch can be pulled directly into the `Packages` directory, e.g.
```
git clone -b upm [email protected]:gwaredd/mgGif.git
```## Usage
Pass a `byte[]` of the GIF file and loop through results.
```cs
byte[] data = File.ReadAllBytes( "some.gif" );
using( var decoder = new MG.GIF.Decoder( data ) )
{
var img = decoder.NextImage();while( img != null )
{
Texture2D tex = img.CreateTexture();
int delay = img.Delay;
img = decoder.NextImage();
}
}
```See [AnimatedTextures.cs](https://github.com/gwaredd/mgGif/blob/main/Assets/Scenes/Scripts/AnimatedTextures.cs) for an example
**NB:** For speed the decoder will reuse buffers between each `NextImage()` call. If you need to keep the raw image data then ensure you `Clone()` it first.
For an additional performance improvement, uncomment `mgGIF_UNSAFE` at the top of the file and allow unsafe code compilation in the assembly.
## Benchmarks
Benchmarks of the time to decode three test animations using different libraries.
| Library | Editor | Mono | IL2CPP |
|-----------------------|-----------|----------|------------|
| UniGif | 7321 ms | 3790 ms | 3178 ms |
| Unity-GifDecoder | 365 ms | 123 ms | 88 ms |
| mgGif | 247 ms | 112 ms | 80 ms |
| mgGif (Unsafe Mode) | 280 ms | 106 ms | 70 ms |