Skip to content

Commit

Permalink
Added duration property
Browse files Browse the repository at this point in the history
Removed aspect ratio property
Frame delay is 100ms if its set to under 20ms (same specs as Google Chrome)
  • Loading branch information
xavivives committed Mar 14, 2015
1 parent c27d259 commit 5881282
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ namespace ofxGIF

case GIF_DISPOSAL_UNSPECIFIED:
break;

}
}
else
Expand All @@ -201,7 +200,9 @@ namespace ofxGIF
}

pages.push_back(accumPx);
frameDurations.push_back(_duration );
if(_duration<=20)
_duration = 100;
frameDurations.push_back( _duration);
}

};
Expand Down
9 changes: 5 additions & 4 deletions src/ofxGifDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ void ofxGifDecoder::createGif(ofxGifType *currentGif, string filePath)
{
ofxGIF::fiGifLoader decoder;
decoder.load(gifPath);
int duration = 0;

int length =decoder.pages.size();
if(length>0)
{
currentGif->length = length;
currentGif->frames.resize(length);
currentGif->delays.resize(length);
currentGif->aspectRatio = 1;


for(int i=0; i < decoder.pages.size() ; i++)
{
currentGif->frames[i] = decoder.pages[i];
currentGif->delays[i] = decoder.frameDurations[i];
duration += decoder.frameDurations[i];
}

currentGif->duration = duration;
currentGif->width = currentGif->frames[0].getWidth();
currentGif->height = currentGif->frames[0].getHeight();
currentGif->status = "ok";
Expand All @@ -71,7 +72,7 @@ void ofxGifDecoder::createGif(ofxGifType *currentGif, string filePath)
currentGif->length = 0;
currentGif->frames.resize(0);
currentGif->delays.resize(0);
currentGif->aspectRatio = 1;
currentGif->duration = duration;
currentGif->width = 0;
currentGif->height = 0;
}
Expand Down
20 changes: 7 additions & 13 deletions src/ofxGifType.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
width = 0;
height = 0;
length = 0;
aspectRatio = 0;
delays.resize(0);
frames.resize(0);
duration = 0;
};


Expand All @@ -29,13 +29,12 @@
width = gif.width;
height = gif.height;
length = gif.length;
aspectRatio = gif.aspectRatio;
delays = gif.delays;
frames.resize(gif.length);
duration = gif.duration;

for(int i =0; i < gif.length; i++)
frames[i] = gif.frames[i];

};

//assignement operator
Expand All @@ -44,17 +43,15 @@
if(this == &gif)
return *this;


fileName = gif.fileName;

filePath = gif.filePath;
status = gif.status;
width = gif.width;
height = gif.height;
length = gif.length;
aspectRatio = gif.aspectRatio;
delays = gif.delays;
frames.resize(gif.length);
duration = gif.duration;


for(int i =0; i < gif.length; i++)
Expand All @@ -64,28 +61,25 @@
return *this;
}



string fileName;
string filePath;
string status; //Empty/Error/Ok
int width;
int height;
int length; //number of frames
float aspectRatio; //width/height
vector<ofPixels> frames; //all the frames
vector<int> delays; //delays per frame in ms
int duration; //total duration in ms
};

//desstructor

//destructor

struct RGBA
/*struct RGBA
{
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
};
};*/


0 comments on commit 5881282

Please sign in to comment.