Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/mggif.git#upm

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **mgGIF** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/mggif.git#upm
```

[![pkglnk](https://www.pkglnk.dev/badge/mggif.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/mggif)

README

mgGIF

A unity library to parse a GIF file and extracts the images, just for fun

Butterfly

Installation

Copy Assets\mgGif\mgGif.cs to your project.

Alternatively, the upm branch can be pulled directly into the Packages directory, e.g.

git clone -b upm git@github.com:gwaredd/mgGif.git

Usage

Pass a byte[] of the GIF file and loop through results.


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 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

Comments

No comments yet. Be the first!