Last active
December 7, 2015 20:46
-
-
Save gregkepler/71ece81a37397d55e088 to your computer and use it in GitHub Desktop.
Revisions
-
gregkepler revised this gist
Nov 19, 2015 . No changes.There are no files selected for viewing
-
gregkepler revised this gist
Nov 19, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ void AnimatedGifsApp::setup() mGif = make_shared<AnimatedGif>( loadAsset( gif ), 30 ); // or // mGif = make_shared<AnimatedGif>(); // mGif->load( loadAsset( gif ) ); // mGif->setFrameRate( 60 ); } -
gregkepler created this gist
Nov 19, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #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(); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #include "cinder/app/AppBase.h" #include "cinder/Surface.h" #include "cinder/ImageIo.h" #include "cinder/gl/Texture.h" typedef std::shared_ptr<class AnimatedGif> AnimatedGifRef; class AnimatedGif { public: AnimatedGif(){ init( nullptr ); }; AnimatedGif( ci::DataSourceRef filePath ){ init( filePath ); }; AnimatedGif( ci::DataSourceRef filePath, int frameRate ){ init( filePath, frameRate ); }; ~AnimatedGif() {}; void load( ci::DataSourceRef filePath ); void update(); ci::gl::TextureRef getCurrentFrame() { return mCurrentFrameTexture; }; void setFrameRate( int frameRate ) { mFrameRate = frameRate; }; private: std::vector<ci::SurfaceRef> mGifFrames; int mCurrentFrame; int mFrameRate; ci::gl::TextureRef mCurrentFrameTexture; void init( ci::DataSourceRef filePath = nullptr, int frameRate = 60 ); }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #include "cinder/app/App.h" #include "cinder/app/RendererGl.h" #include "cinder/gl/gl.h" #include "cinder/gl/Texture.h" #include "cinder/Log.h" #include "AnimatedGif.h" using namespace ci; using namespace ci::app; using namespace std; class AnimatedGifsApp : public App { public: void setup() override; void update() override; void draw() override; AnimatedGifRef mGif; }; void AnimatedGifsApp::setup() { std::string gif = "animated_gif.gif"; // simple animated gif class mGif = make_shared<AnimatedGif>( loadAsset( gif ), 30 ); // or // mGif = make_shared<AnimatedGif>(); // mGif->load( loadAsset( gif ) ); // mGif->setFrameRate( 60 ); } void AnimatedGifsApp::update() { mGif->update(); } void AnimatedGifsApp::draw() { gl::clear( Color( 0, 0, 0 ) ); gl::draw( mGif->getCurrentFrame() ); } CINDER_APP( AnimatedGifsApp, RendererGl )