Coder Social home page Coder Social logo

mggif's Introduction

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 [email protected]: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

[2020-10-11] mgGIF is the fastest pure C# GIF decoder for Unity on github

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.