├── .gitignore ├── README.md ├── assets ├── Newtons_cradle_animation_book_2.gif ├── Transparent.gif ├── brown.gif └── giphy.gif ├── cinderblock.png ├── cinderblock.xml ├── samples └── BasicSample │ ├── include │ └── Resources.h │ ├── resources │ ├── CinderApp.icns │ └── cinder_app_icon.ico │ ├── src │ └── BasicSampleApp.cpp │ ├── vc2013 │ ├── BasicSample.sln │ ├── BasicSample.vcxproj │ ├── BasicSample.vcxproj.filters │ └── Resources.rc │ └── xcode │ ├── BasicSample.xcodeproj │ └── project.pbxproj │ ├── BasicSample_Prefix.pch │ └── Info.plist └── src ├── ciAnimatedGif.cpp └── ciAnimatedGif.h /.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]uild/ 2 | [Oo]bj/ 3 | *.o 4 | [Dd]ebug*/ 5 | [Rr]elease*/ 6 | *.mode* 7 | *.app/ 8 | *.pyc 9 | .svn/ 10 | *.log 11 | test/ 12 | *.db 13 | *.opendb 14 | 15 | # IDE-specific ignore patterns 16 | 17 | *.pbxuser 18 | *.perspective 19 | *.perspectivev3 20 | *.mode1v3 21 | *.mode2v3 22 | 23 | #XCode 24 | xcuserdata 25 | *.xcworkspace 26 | 27 | #vs 28 | *.sdf 29 | *.opensdf 30 | *.suo 31 | *.pdb 32 | *.ilk 33 | *.aps 34 | ipch/ 35 | 36 | #OSX 37 | .DS_Store 38 | *.swp 39 | *~.nib 40 | # Thumbnails 41 | ._* 42 | 43 | #Windows 44 | Thumbs.db 45 | *.tlog 46 | *.sdf 47 | Desktop.ini 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ciAnimatedGif 2 | A library for playing back Animated Gifs in Cinder 0.9.0 3 | 4 | ### Why 5 | Gifs are a common enough format that I am often asked to include them in projects despite the format being pretty old fashioned and not particularly suited to desktop applications. They are unique in that each frame can have it's own timing between frames. Since there wasn't a simple library I found that could handle this, the block was born. 6 | 7 | ### Setup 8 | Setup is super easy, simply add the files to your project, or use TinderBox when you set up your project initially. 9 | 10 | The code itself is very easy, just load and then draw. When you call draw, the update will be called automatically. If you don't want to draw it, feel free to call update manually. 11 | 12 | ``` 13 | ciAnimatedGifRef mGif; 14 | mGif = ciAnimatedGif::create( loadAsset("someGif.gif") ); 15 | mGif->draw(); 16 | ``` 17 | 18 | If a gif uses a global palette (which is not guaranteed, but common) you can also access it with `mGif->getPalette();` which will return a `std::vector`. 19 | 20 | See the sample project for use, and check out [http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html](http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html) for more information about what is under the hood of a gif. 21 | 22 | Find the official spec [here](https://www.w3.org/Graphics/GIF/spec-gif89a.txt). 23 | 24 | Icon from [icons8](https://icons8.com/). -------------------------------------------------------------------------------- /assets/Newtons_cradle_animation_book_2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/assets/Newtons_cradle_animation_book_2.gif -------------------------------------------------------------------------------- /assets/Transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/assets/Transparent.gif -------------------------------------------------------------------------------- /assets/brown.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/assets/brown.gif -------------------------------------------------------------------------------- /assets/giphy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/assets/giphy.gif -------------------------------------------------------------------------------- /cinderblock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/cinderblock.png -------------------------------------------------------------------------------- /cinderblock.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | src/*.h 15 | src/*.cpp 16 | 17 | src 18 | 19 | -------------------------------------------------------------------------------- /samples/BasicSample/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/BasicSample/resources/CinderApp.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/samples/BasicSample/resources/CinderApp.icns -------------------------------------------------------------------------------- /samples/BasicSample/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwhitney/ciAnimatedGif/f97bf2c5fb48d34c109ae1484f7572a2f66603ef/samples/BasicSample/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /samples/BasicSample/src/BasicSampleApp.cpp: -------------------------------------------------------------------------------- 1 | #include "cinder/app/App.h" 2 | #include "cinder/app/RendererGl.h" 3 | #include "cinder/gl/gl.h" 4 | 5 | #include "ciAnimatedGif.h" 6 | 7 | using namespace ci; 8 | using namespace ci::app; 9 | using namespace std; 10 | 11 | class BasicSampleApp : public App { 12 | public: 13 | void setup() override; 14 | void keyDown( KeyEvent event) override; 15 | void mouseDown( MouseEvent event ) override; 16 | void fileDrop( FileDropEvent event) override; 17 | void update() override; 18 | void draw() override; 19 | 20 | ciAnimatedGifRef mGif; 21 | bool bDrawPalette = false; 22 | }; 23 | 24 | void BasicSampleApp::setup() 25 | { 26 | // from https://en.wikipedia.org/wiki/File:Newtons_cradle_animation_book_2.gif 27 | mGif = ciAnimatedGif::create( loadAsset("Newtons_cradle_animation_book_2.gif") ); 28 | } 29 | 30 | void BasicSampleApp::keyDown(cinder::app::KeyEvent event) 31 | { 32 | if( event.getChar() == 'p'){ 33 | bDrawPalette = !bDrawPalette; 34 | } 35 | } 36 | 37 | void BasicSampleApp::mouseDown( MouseEvent event ) 38 | { 39 | if(mGif){ 40 | mGif->seek(0.0); 41 | } 42 | } 43 | 44 | void BasicSampleApp::fileDrop(cinder::app::FileDropEvent event) 45 | { 46 | mGif = ciAnimatedGif::create( loadFile(event.getFile(0)) ); 47 | } 48 | 49 | void BasicSampleApp::update() 50 | { 51 | } 52 | 53 | void BasicSampleApp::draw() 54 | { 55 | gl::clear( Color( 0, 0, 0 ) ); 56 | 57 | mGif->draw(); 58 | 59 | if( bDrawPalette ){ 60 | auto palette = mGif->getPalette(); 61 | for( int i=0; i 2 | 3 | 4 | Debug 5 | Win32 6 | 7 | 8 | Release 9 | Win32 10 | 11 | 12 | 13 | {BB872B6B-960D-44EC-8BA0-506A596238A1} 14 | BasicSample 15 | Win32Proj 16 | 17 | 18 | 19 | Application 20 | false 21 | v120 22 | Unicode 23 | true 24 | 25 | 26 | Application 27 | true 28 | v120 29 | Unicode 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(SolutionDir)$(Configuration)\ 43 | $(Configuration)\ 44 | true 45 | $(SolutionDir)$(Configuration)\ 46 | $(Configuration)\ 47 | false 48 | 49 | 50 | 51 | Disabled 52 | ..\include;"..\..\..\..\..\include";..\..\..\src 53 | WIN32;_WIN32_WINNT=0x0601;_WINDOWS;NOMINMAX;_DEBUG;%(PreprocessorDefinitions) 54 | true 55 | EnableFastChecks 56 | MultiThreadedDebug 57 | 58 | Level3 59 | EditAndContinue 60 | true 61 | 62 | 63 | "..\..\..\..\..\include";..\include 64 | 65 | 66 | cinder-$(PlatformToolset)_d.lib;OpenGL32.lib;%(AdditionalDependencies) 67 | "..\..\..\..\..\lib\msw\$(PlatformTarget)" 68 | true 69 | Windows 70 | false 71 | 72 | MachineX86 73 | LIBCMT;LIBCPMT 74 | 75 | 76 | 77 | 78 | ..\include;"..\..\..\..\..\include";..\..\..\src 79 | WIN32;_WIN32_WINNT=0x0601;_WINDOWS;NOMINMAX;NDEBUG;%(PreprocessorDefinitions) 80 | MultiThreaded 81 | 82 | Level3 83 | ProgramDatabase 84 | true 85 | 86 | 87 | true 88 | 89 | 90 | "..\..\..\..\..\include";..\include 91 | 92 | 93 | cinder-$(PlatformToolset).lib;OpenGL32.lib;%(AdditionalDependencies) 94 | "..\..\..\..\..\lib\msw\$(PlatformTarget)" 95 | false 96 | true 97 | Windows 98 | true 99 | 100 | false 101 | 102 | MachineX86 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /samples/BasicSample/vc2013/BasicSample.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 5 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 6 | 7 | 8 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 9 | h;hpp;hxx;hm;inl;inc;xsd 10 | 11 | 12 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 13 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 14 | 15 | 16 | {AE790298-52E7-4090-BD19-875591A90A45} 17 | 18 | 19 | {D3D69323-10E8-45B1-8B7D-F1CDA3E0901E} 20 | 21 | 22 | {78BABB8E-C099-4E03-9948-E7C0E54E8A27} 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Blocks\ciGif\src 37 | 38 | 39 | Blocks\ciGif\src 40 | 41 | 42 | 43 | 44 | Header Files 45 | 46 | 47 | 48 | 49 | Resource Files 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /samples/BasicSample/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /samples/BasicSample/xcode/BasicSample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 006D720419952D00008149E2 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 006D720219952D00008149E2 /* AVFoundation.framework */; }; 11 | 006D720519952D00008149E2 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 006D720319952D00008149E2 /* CoreMedia.framework */; }; 12 | 0091D8F90E81B9330029341E /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0091D8F80E81B9330029341E /* OpenGL.framework */; }; 13 | 00B784B30FF439BC000DE1D7 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B784AF0FF439BC000DE1D7 /* Accelerate.framework */; }; 14 | 00B784B40FF439BC000DE1D7 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B784B00FF439BC000DE1D7 /* AudioToolbox.framework */; }; 15 | 00B784B50FF439BC000DE1D7 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B784B10FF439BC000DE1D7 /* AudioUnit.framework */; }; 16 | 00B784B60FF439BC000DE1D7 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B784B20FF439BC000DE1D7 /* CoreAudio.framework */; }; 17 | 00B9955A1B128DF400A5C623 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B995581B128DF400A5C623 /* IOKit.framework */; }; 18 | 00B9955B1B128DF400A5C623 /* IOSurface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B995591B128DF400A5C623 /* IOSurface.framework */; }; 19 | 5323E6B20EAFCA74003A9687 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5323E6B10EAFCA74003A9687 /* CoreVideo.framework */; }; 20 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 21 | 85427E1D6E6B4E42B86591D9 /* ciAnimatedGif.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 199009B2745C4069B7A42DDB /* ciAnimatedGif.cpp */; }; 22 | 529009A3DCAB4FC6A269FA46 /* ciAnimatedGif.h in Headers */ = {isa = PBXBuildFile; fileRef = B683F26A567E45FE81D08328 /* ciAnimatedGif.h */; }; 23 | 24498402C80E43C5BD149255 /* BasicSample_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 3C806731C1CF4A4F9527B591 /* BasicSample_Prefix.pch */; }; 24 | 46BDF906BE4B4AB4AED099E8 /* CinderApp.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0798083CF9704049B6DC5049 /* CinderApp.icns */; }; 25 | D592A023DF8E4A558FBE945E /* Resources.h in Headers */ = {isa = PBXBuildFile; fileRef = A99C92336FC54FD5AA0AC32A /* Resources.h */; }; 26 | F12D25C7E19543A29F7B9359 /* BasicSampleApp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9970C72A286D45DEB18436EE /* BasicSampleApp.cpp */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 006D720219952D00008149E2 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 31 | 006D720319952D00008149E2 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; 32 | 0091D8F80E81B9330029341E /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = ""; }; 33 | 00B784AF0FF439BC000DE1D7 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; }; 34 | 00B784B00FF439BC000DE1D7 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 35 | 00B784B10FF439BC000DE1D7 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; 36 | 00B784B20FF439BC000DE1D7 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; 37 | 00B995581B128DF400A5C623 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; }; 38 | 00B995591B128DF400A5C623 /* IOSurface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOSurface.framework; path = System/Library/Frameworks/IOSurface.framework; sourceTree = SDKROOT; }; 39 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 40 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 41 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 42 | 5323E6B10EAFCA74003A9687 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = /System/Library/Frameworks/CoreVideo.framework; sourceTree = ""; }; 43 | 8D1107320486CEB800E47090 /* BasicSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BasicSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 9970C72A286D45DEB18436EE /* BasicSampleApp.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.cpp; path = ../src/BasicSampleApp.cpp; sourceTree = ""; name = BasicSampleApp.cpp; }; 45 | A99C92336FC54FD5AA0AC32A /* Resources.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ../include/Resources.h; sourceTree = ""; name = Resources.h; }; 46 | 0798083CF9704049B6DC5049 /* CinderApp.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = ../resources/CinderApp.icns; sourceTree = ""; name = CinderApp.icns; }; 47 | 9213796A1B484ECF88BC286D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; name = Info.plist; }; 48 | 3C806731C1CF4A4F9527B591 /* BasicSample_Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = "\"\""; path = BasicSample_Prefix.pch; sourceTree = ""; name = BasicSample_Prefix.pch; }; 49 | B683F26A567E45FE81D08328 /* ciAnimatedGif.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ../../../src/ciAnimatedGif.h; sourceTree = ""; name = ciAnimatedGif.h; }; 50 | 199009B2745C4069B7A42DDB /* ciAnimatedGif.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.cpp; path = ../../../src/ciAnimatedGif.cpp; sourceTree = ""; name = ciAnimatedGif.cpp; }; 51 | /* End PBXFileReference section */ 52 | 53 | /* Begin PBXFrameworksBuildPhase section */ 54 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | 006D720419952D00008149E2 /* AVFoundation.framework in Frameworks */, 59 | 006D720519952D00008149E2 /* CoreMedia.framework in Frameworks */, 60 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, 61 | 0091D8F90E81B9330029341E /* OpenGL.framework in Frameworks */, 62 | 5323E6B20EAFCA74003A9687 /* CoreVideo.framework in Frameworks */, 63 | 00B784B30FF439BC000DE1D7 /* Accelerate.framework in Frameworks */, 64 | 00B784B40FF439BC000DE1D7 /* AudioToolbox.framework in Frameworks */, 65 | 00B784B50FF439BC000DE1D7 /* AudioUnit.framework in Frameworks */, 66 | 00B784B60FF439BC000DE1D7 /* CoreAudio.framework in Frameworks */, 67 | 00B9955A1B128DF400A5C623 /* IOKit.framework in Frameworks */, 68 | 00B9955B1B128DF400A5C623 /* IOSurface.framework in Frameworks */, 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXFrameworksBuildPhase section */ 73 | 74 | /* Begin PBXGroup section */ 75 | 080E96DDFE201D6D7F000001 /* Source */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 9970C72A286D45DEB18436EE /* BasicSampleApp.cpp */, 79 | ); 80 | name = Source; 81 | sourceTree = ""; 82 | }; 83 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 006D720219952D00008149E2 /* AVFoundation.framework */, 87 | 006D720319952D00008149E2 /* CoreMedia.framework */, 88 | 00B784AF0FF439BC000DE1D7 /* Accelerate.framework */, 89 | 00B784B00FF439BC000DE1D7 /* AudioToolbox.framework */, 90 | 00B784B10FF439BC000DE1D7 /* AudioUnit.framework */, 91 | 00B784B20FF439BC000DE1D7 /* CoreAudio.framework */, 92 | 5323E6B10EAFCA74003A9687 /* CoreVideo.framework */, 93 | 0091D8F80E81B9330029341E /* OpenGL.framework */, 94 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, 95 | 00B995581B128DF400A5C623 /* IOKit.framework */, 96 | 00B995591B128DF400A5C623 /* IOSurface.framework */, 97 | ); 98 | name = "Linked Frameworks"; 99 | sourceTree = ""; 100 | }; 101 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */, 105 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */, 106 | ); 107 | name = "Other Frameworks"; 108 | sourceTree = ""; 109 | }; 110 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 8D1107320486CEB800E47090 /* BasicSample.app */, 114 | ); 115 | name = Products; 116 | sourceTree = ""; 117 | }; 118 | 29B97314FDCFA39411CA2CEA /* BasicSample */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 01B97315FEAEA392516A2CEA /* Blocks */, 122 | 29B97315FDCFA39411CA2CEA /* Headers */, 123 | 080E96DDFE201D6D7F000001 /* Source */, 124 | 29B97317FDCFA39411CA2CEA /* Resources */, 125 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 126 | 19C28FACFE9D520D11CA2CBB /* Products */, 127 | ); 128 | name = BasicSample; 129 | sourceTree = ""; 130 | }; 131 | EC60939AB23945AFBB8337FC /* src */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | B683F26A567E45FE81D08328 /* ciAnimatedGif.h */, 135 | 199009B2745C4069B7A42DDB /* ciAnimatedGif.cpp */, 136 | ); 137 | name = src; 138 | sourceTree = ""; 139 | }; 140 | E2BBCDD6135C43A8807A00F1 /* ciGif */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | EC60939AB23945AFBB8337FC /* src */, 144 | ); 145 | name = ciGif; 146 | sourceTree = ""; 147 | }; 148 | 01B97315FEAEA392516A2CEA /* Blocks */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | E2BBCDD6135C43A8807A00F1 /* ciGif */, 152 | ); 153 | name = Blocks; 154 | sourceTree = ""; 155 | }; 156 | 29B97315FDCFA39411CA2CEA /* Headers */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | A99C92336FC54FD5AA0AC32A /* Resources.h */, 160 | 3C806731C1CF4A4F9527B591 /* BasicSample_Prefix.pch */, 161 | ); 162 | name = Headers; 163 | sourceTree = ""; 164 | }; 165 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 0798083CF9704049B6DC5049 /* CinderApp.icns */, 169 | 9213796A1B484ECF88BC286D /* Info.plist */, 170 | ); 171 | name = Resources; 172 | sourceTree = ""; 173 | }; 174 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 175 | isa = PBXGroup; 176 | children = ( 177 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 178 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, 179 | ); 180 | name = Frameworks; 181 | sourceTree = ""; 182 | }; 183 | /* End PBXGroup section */ 184 | 185 | /* Begin PBXNativeTarget section */ 186 | 8D1107260486CEB800E47090 /* BasicSample */ = { 187 | isa = PBXNativeTarget; 188 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "BasicSample" */; 189 | buildPhases = ( 190 | 8D1107290486CEB800E47090 /* Resources */, 191 | 8D11072C0486CEB800E47090 /* Sources */, 192 | 8D11072E0486CEB800E47090 /* Frameworks */, 193 | ); 194 | buildRules = ( 195 | ); 196 | dependencies = ( 197 | ); 198 | name = BasicSample; 199 | productInstallPath = "$(HOME)/Applications"; 200 | productName = BasicSample; 201 | productReference = 8D1107320486CEB800E47090 /* BasicSample.app */; 202 | productType = "com.apple.product-type.application"; 203 | }; 204 | /* End PBXNativeTarget section */ 205 | 206 | /* Begin PBXProject section */ 207 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 208 | isa = PBXProject; 209 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "BasicSample" */; 210 | compatibilityVersion = "Xcode 3.2"; 211 | developmentRegion = English; 212 | hasScannedForEncodings = 1; 213 | knownRegions = ( 214 | English, 215 | Japanese, 216 | French, 217 | German, 218 | ); 219 | mainGroup = 29B97314FDCFA39411CA2CEA /* BasicSample */; 220 | projectDirPath = ""; 221 | projectRoot = ""; 222 | targets = ( 223 | 8D1107260486CEB800E47090 /* BasicSample */, 224 | ); 225 | }; 226 | /* End PBXProject section */ 227 | 228 | /* Begin PBXResourcesBuildPhase section */ 229 | 8D1107290486CEB800E47090 /* Resources */ = { 230 | isa = PBXResourcesBuildPhase; 231 | buildActionMask = 2147483647; 232 | files = ( 233 | 46BDF906BE4B4AB4AED099E8 /* CinderApp.icns in Resources */, 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | }; 237 | /* End PBXResourcesBuildPhase section */ 238 | 239 | /* Begin PBXSourcesBuildPhase section */ 240 | 8D11072C0486CEB800E47090 /* Sources */ = { 241 | isa = PBXSourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | F12D25C7E19543A29F7B9359 /* BasicSampleApp.cpp in Sources */, 245 | 85427E1D6E6B4E42B86591D9 /* ciAnimatedGif.cpp in Sources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | /* End PBXSourcesBuildPhase section */ 250 | 251 | /* Begin XCBuildConfiguration section */ 252 | C01FCF4B08A954540054247B /* Debug */ = { 253 | isa = XCBuildConfiguration; 254 | buildSettings = { 255 | COMBINE_HIDPI_IMAGES = YES; 256 | DEAD_CODE_STRIPPING = YES; 257 | COPY_PHASE_STRIP = NO; 258 | GCC_DYNAMIC_NO_PIC = NO; 259 | GCC_INLINES_ARE_PRIVATE_EXTERN = YES; 260 | GCC_OPTIMIZATION_LEVEL = 0; 261 | GCC_PREPROCESSOR_DEFINITIONS = ( 262 | "DEBUG=1", 263 | "$(inherited)", 264 | ); 265 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 266 | GCC_PREFIX_HEADER = BasicSample_Prefix.pch; 267 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 268 | INFOPLIST_FILE = Info.plist; 269 | INSTALL_PATH = "$(HOME)/Applications"; 270 | OTHER_LDFLAGS = "\"$(CINDER_PATH)/lib/libcinder_d.a\""; 271 | PRODUCT_BUNDLE_IDENTIFIER = "org.libcinder.${PRODUCT_NAME:rfc1034identifier}"; 272 | PRODUCT_NAME = BasicSample; 273 | SYMROOT = ./build; 274 | WRAPPER_EXTENSION = app; 275 | }; 276 | name = Debug; 277 | }; 278 | C01FCF4C08A954540054247B /* Release */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | COMBINE_HIDPI_IMAGES = YES; 282 | DEAD_CODE_STRIPPING = YES; 283 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 284 | GCC_FAST_MATH = YES; 285 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO; 286 | GCC_INLINES_ARE_PRIVATE_EXTERN = YES; 287 | GCC_OPTIMIZATION_LEVEL = 3; 288 | GCC_PREPROCESSOR_DEFINITIONS = ( 289 | "NDEBUG=1", 290 | "$(inherited)", 291 | ); 292 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 293 | GCC_PREFIX_HEADER = BasicSample_Prefix.pch; 294 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 295 | INFOPLIST_FILE = Info.plist; 296 | INSTALL_PATH = "$(HOME)/Applications"; 297 | OTHER_LDFLAGS = "\"$(CINDER_PATH)/lib/libcinder.a\""; 298 | PRODUCT_BUNDLE_IDENTIFIER = "org.libcinder.${PRODUCT_NAME:rfc1034identifier}"; 299 | PRODUCT_NAME = BasicSample; 300 | STRIP_INSTALLED_PRODUCT = YES; 301 | SYMROOT = ./build; 302 | WRAPPER_EXTENSION = app; 303 | }; 304 | name = Release; 305 | }; 306 | C01FCF4F08A954540054247B /* Debug */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ALWAYS_SEARCH_USER_PATHS = NO; 310 | CINDER_PATH = "../../../../.."; 311 | CLANG_CXX_LANGUAGE_STANDARD = "c++11"; 312 | CLANG_CXX_LIBRARY = "libc++"; 313 | ENABLE_TESTABILITY = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 315 | GCC_WARN_UNUSED_VARIABLE = YES; 316 | HEADER_SEARCH_PATHS = "\"$(CINDER_PATH)/include\""; 317 | MACOSX_DEPLOYMENT_TARGET = 10.8; 318 | ONLY_ACTIVE_ARCH = YES; 319 | SDKROOT = macosx; 320 | USER_HEADER_SEARCH_PATHS = ( 321 | "\"$(CINDER_PATH)/include\" ../include", 322 | ../../../src, 323 | ); 324 | }; 325 | name = Debug; 326 | }; 327 | C01FCF5008A954540054247B /* Release */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ALWAYS_SEARCH_USER_PATHS = NO; 331 | CINDER_PATH = "../../../../.."; 332 | CLANG_CXX_LANGUAGE_STANDARD = "c++11"; 333 | CLANG_CXX_LIBRARY = "libc++"; 334 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 335 | GCC_WARN_UNUSED_VARIABLE = YES; 336 | HEADER_SEARCH_PATHS = "\"$(CINDER_PATH)/include\""; 337 | MACOSX_DEPLOYMENT_TARGET = 10.8; 338 | SDKROOT = macosx; 339 | USER_HEADER_SEARCH_PATHS = ( 340 | "\"$(CINDER_PATH)/include\" ../include", 341 | ../../../src, 342 | ); 343 | }; 344 | name = Release; 345 | }; 346 | /* End XCBuildConfiguration section */ 347 | 348 | /* Begin XCConfigurationList section */ 349 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "BasicSample" */ = { 350 | isa = XCConfigurationList; 351 | buildConfigurations = ( 352 | C01FCF4B08A954540054247B /* Debug */, 353 | C01FCF4C08A954540054247B /* Release */, 354 | ); 355 | defaultConfigurationIsVisible = 0; 356 | defaultConfigurationName = Release; 357 | }; 358 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "BasicSample" */ = { 359 | isa = XCConfigurationList; 360 | buildConfigurations = ( 361 | C01FCF4F08A954540054247B /* Debug */, 362 | C01FCF5008A954540054247B /* Release */, 363 | ); 364 | defaultConfigurationIsVisible = 0; 365 | defaultConfigurationName = Release; 366 | }; 367 | /* End XCConfigurationList section */ 368 | }; 369 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 370 | } 371 | -------------------------------------------------------------------------------- /samples/BasicSample/xcode/BasicSample_Prefix.pch: -------------------------------------------------------------------------------- 1 | #if defined( __cplusplus ) 2 | #include "cinder/Cinder.h" 3 | 4 | #include "cinder/app/App.h" 5 | 6 | #include "cinder/gl/gl.h" 7 | 8 | #include "cinder/CinderMath.h" 9 | #include "cinder/Matrix.h" 10 | #include "cinder/Vector.h" 11 | #include "cinder/Quaternion.h" 12 | #endif 13 | -------------------------------------------------------------------------------- /samples/BasicSample/xcode/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | CinderApp.icns 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2015 __MyCompanyName__. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/ciAnimatedGif.cpp: -------------------------------------------------------------------------------- 1 | #include "ciAnimatedGif.h" 2 | 3 | using namespace ci; 4 | using namespace ci::app; 5 | using namespace std; 6 | 7 | ciAnimatedGif::ciAnimatedGif(ci::DataSourceRef data) 8 | { 9 | parseMetadata(data); 10 | 11 | ci::ImageSource::Options options; 12 | options.index( 0 ); 13 | 14 | ImageSourceRef img = loadImage( data, options ); 15 | int numFrames = img->getCount(); 16 | 17 | for( int i = 0; i < numFrames; ++i ) { 18 | SurfaceRef frame = Surface::create( loadImage(data, options) ); 19 | mFrameList.push_back( gl::Texture::create(*frame) ); 20 | options.index( options.getIndex() + 1 ); 21 | } 22 | 23 | mCurFrame = 0; 24 | play(); 25 | } 26 | 27 | void ciAnimatedGif::play() 28 | { 29 | mNextFrameTime = getElapsedSeconds() + mFrameTimes[mCurFrame]; 30 | } 31 | 32 | void ciAnimatedGif::seek(float pct) 33 | { 34 | mCurFrame = (mFrameList.size() - 1) * glm::clamp(pct, 0.0f, 1.0f); 35 | } 36 | 37 | void ciAnimatedGif::parseMetadata(ci::DataSourceRef data) 38 | { 39 | BufferRef buffer = data->getBuffer(); 40 | uint8_t * inPtr = (uint8_t *)buffer->getData(); 41 | 42 | // HEADER BLOCK (must start with GIF) 43 | char header[6]; 44 | memcpy(&header, inPtr, 6); 45 | mHeader = std::string(header); 46 | if( mHeader.substr(0,3) != "GIF" ){ 47 | throw new Exception("This is not a valid animated gif file."); 48 | } 49 | 50 | // LOGICAL SCREEN DESCRIPTOR 51 | canvasWidth = *(inPtr + 6) | *(inPtr + 7) << 8; // Not guaranteed to be accurate. Often returns 0 52 | canvasHeight = *(inPtr + 8) | *(inPtr + 9) << 8; // Not guaranteed to be accurate. Often returns 0 53 | 54 | uint8_t packed = *(inPtr + 10); 55 | 56 | bool hasGlobalColorTable = (packed & 0x01); 57 | if(hasGlobalColorTable){ 58 | int mask = (1 << 6) | (1 << 5) | (1 << 4); 59 | int n = (mask & packed) >> 4; 60 | int numColorBytes = 3 * pow(2, n + 1); 61 | 62 | uint8_t *colPtr = inPtr + 13; 63 | 64 | for( int i=0; igetSize(); i++){ 72 | if( *(inPtr + i) == 0x21 ){ // it's an extension 73 | if( *(inPtr + i + 1) == 0xF9 && *(inPtr + i + 7) == 0x00){ // it's a graphics control label 74 | uint8_t byte1 = *(inPtr + i + 4); 75 | uint8_t byte2 = *(inPtr + i + 5); 76 | 77 | uint16_t sum = byte1 | (byte2 << 8); // this represents the delay in hundreths of a second 78 | if( sum == 0.0 ){ 79 | sum = 10; // if no delay specificed, put a default delay of 0.1 secs between frames 80 | } 81 | 82 | mFrameTimes.push_back( (float)sum / 100.0f ); 83 | } 84 | } 85 | } 86 | } 87 | 88 | void ciAnimatedGif::printBit(uint8_t byte) 89 | { 90 | cout << ((byte >> 7) & 0x1) 91 | << ((byte >> 6) & 0x1) 92 | << ((byte >> 5) & 0x1) 93 | << ((byte >> 4) & 0x1) 94 | << ((byte >> 3) & 0x1) 95 | << ((byte >> 2) & 0x1) 96 | << ((byte >> 1) & 0x1) 97 | << ((byte) & 0x1) 98 | << endl; 99 | } 100 | 101 | void ciAnimatedGif::update() 102 | { 103 | while( getElapsedSeconds() > mNextFrameTime ){ 104 | ++mCurFrame; 105 | if( mCurFrame >= mFrameList.size() ){ 106 | mCurFrame = 0; 107 | } 108 | 109 | mNextFrameTime += mFrameTimes[glm::clamp(mCurFrame, 0, mFrameTimes.size()-1)]; 110 | } 111 | mCurTex = mFrameList[mCurFrame]; 112 | } 113 | 114 | void ciAnimatedGif::draw() 115 | { 116 | update(); 117 | 118 | gl::draw(mCurTex); 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/ciAnimatedGif.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cinder/app/App.h" 4 | #include "cinder/gl/gl.h" 5 | 6 | namespace cinder { 7 | 8 | using ciAnimatedGifRef = std::shared_ptr; 9 | 10 | class ciAnimatedGif { 11 | public: 12 | ciAnimatedGif() = delete; 13 | ciAnimatedGif(ci::DataSourceRef data); 14 | 15 | static ciAnimatedGifRef create(ci::DataSourceRef data){ return std::make_shared(data); } 16 | static ciAnimatedGifRef create( const cinder::fs::path &path){ return ciAnimatedGif::create( (cinder::DataSourceRef)cinder::DataSourcePath::create( path )); } 17 | 18 | void update(); 19 | void draw(); 20 | void play(); 21 | void seek( float pct ); 22 | 23 | const std::vector getPalette(){ return mColorList; }; 24 | 25 | ci::gl::TextureRef getTexture(){ return mCurTex; } 26 | 27 | protected: 28 | 29 | void parseMetadata(ci::DataSourceRef data); 30 | void printBit(uint8_t byte); 31 | 32 | std::vector mFrameList; 33 | std::vector mFrameTimes; 34 | 35 | double mNextFrameTime = -1; 36 | int mCurFrame = -1; 37 | ci::gl::TextureRef mCurTex = nullptr; 38 | 39 | std::string mHeader; 40 | 41 | uint16_t canvasWidth, canvasHeight; 42 | bool hasGlobalColorTable = false; 43 | std::vector mColorList; 44 | }; 45 | 46 | } --------------------------------------------------------------------------------