#include "AnimatedGif.h" using namespace ci; using namespace ci::app; using namespace std; void AnimatedGif::init( ci::DataSourceRef filePath, int frameRate ){ if( filePath ){ load( filePath ); } mFrameRate = frameRate; mCurrentFrame = 0; } void AnimatedGif::load( ci::DataSourceRef filePath ){ ci::ImageSource::Options options; options.index( 0 ); ImageSourceRef img = loadImage( filePath, options ); int count = img->getCount(); for( int i = 0; i < count; ++i ) { SurfaceRef frame = Surface::create( loadImage( filePath, options ) ); mGifFrames.push_back( frame ); options.index( options.getIndex() + 1 ); } } void AnimatedGif::update() { if( getElapsedFrames() % int( float( getFrameRate() ) / float( mFrameRate ) ) == 0 ){ mCurrentFrameTexture = gl::Texture::create( *mGifFrames[mCurrentFrame] ); mCurrentFrame++; mCurrentFrame %= mGifFrames.size(); } }