commit 561e99bf0060976cbd48295ee4da4b739e9baaad
parent 5a33326fc9a894f5798665fe68ed0684d1f09830
Author: Adam M <[email protected]>
Date: Sat, 7 Nov 2020 09:32:21 -0600
animate gifs at their declared speed at all sample rates
Diffstat:
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp
@@ -28,7 +28,8 @@ struct ComputerscareBlank : Module {
int currentFrame = 0;
int numFrames = 0;
int stepCounter = 0;
- int frameDelay=10000;
+ float frameDelay=.5;
+ int samplesDelay=10000;
int speed = 100000;
ComputerscareSVGPanel* panelRef;
@@ -57,7 +58,11 @@ struct ComputerscareBlank : Module {
}
void process(const ProcessArgs &args) override {
stepCounter++;
- if (stepCounter > frameDelay) {
+ samplesDelay = frameDelay * args.sampleRate;
+
+ if (stepCounter > samplesDelay) {
+ //DEBUG("samplesDelay: %i",samplesDelay);
+ //DEBUG("%f",args.sampleRate);
stepCounter = 0;
if(numFrames > 1) {
currentFrame ++;
@@ -95,10 +100,12 @@ struct ComputerscareBlank : Module {
currentFrame = 0;
}
void setFrameCount(int frameCount) {
+ DEBUG("setting frame count %i",frameCount);
numFrames=frameCount;
}
- void setFrameDelay(int frameDelayCentiseconds) {
- frameDelay=frameDelayCentiseconds;
+ void setFrameDelay(float frameDelaySeconds) {
+ DEBUG("setting frame delay %f",frameDelaySeconds);
+ frameDelay=frameDelaySeconds;
}
std::string getPath() {
//return numFrames > 0 ? paths[currentFrame] : "";
@@ -243,7 +250,7 @@ struct PNGDisplay : TransparentWidget {
gifBuddy = AnimatedGifBuddy(args.vg, modulePath.c_str());
img = gifBuddy.getHandle();
blankModule->setFrameCount(gifBuddy.getFrameCount());
- blankModule->setFrameDelay(gifBuddy.getFrameDelay());
+ blankModule->setFrameDelay(gifBuddy.getSecondsDelay());
nvgImageSize(args.vg, img, &imgWidth, &imgHeight);
imgRatio = ((float)imgWidth / (float)imgHeight);
diff --git a/src/animatedGif.hpp b/src/animatedGif.hpp
@@ -24,7 +24,7 @@ typedef struct gif_result_t {
-STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *frames, std::vector<unsigned char*> &framePointers)
+STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *frames, std::vector<unsigned char*> &framePointers,int &frameDelay)
{
FILE *f;
stbi__context s;
@@ -59,6 +59,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra
if (prev) prev->next = gr;
gr->delay = g.delay;
+ frameDelay=g.delay;
prev = gr;
gr = (gif_result*) stbi__malloc(sizeof(gif_result));
memset(gr, 0, sizeof(gif_result));
@@ -129,6 +130,7 @@ struct AnimatedGifBuddy {
int imageHandle;
bool initialized = false;
int numFrames = -1;
+ int frameDelay = 0;
AnimatedGifBuddy() {
}
@@ -147,8 +149,9 @@ struct AnimatedGifBuddy {
stbi_convert_iphone_png_to_rgb(1);
//img = stbi_load(filename, &w, &h, &n, 4);
framePointers = {};
- img = stbi_xload(filename, &w, &h, &frame, framePointers);
+ img = stbi_xload(filename, &w, &h, &frame, framePointers,frameDelay);
printf(filename);
+ printf("\nframe delay:%i\n",frameDelay);
printf("loaded %i frames\n", framePointers.size());
numFrames = (int) framePointers.size();
//printVector(framePointers);
@@ -158,7 +161,7 @@ struct AnimatedGifBuddy {
}
image = nvgCreateImageRGBA(ctx, w, h, imageFlags, img);
//stbi_image_free(img);
-
+
initialized = true;
return image;
}
@@ -172,7 +175,7 @@ struct AnimatedGifBuddy {
int getFrameCount() {
return numFrames;
}
- int getFrameDelay() {
- return 1764;
+ float getSecondsDelay() {
+ return ((float) frameDelay)/100;
}
};
\ No newline at end of file