diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2015-11-28 00:17:28 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2015-11-28 00:19:10 +0000 |
commit | 037185de6d1bd6d6250e3226c680d115e23693d0 (patch) | |
tree | 2c3ceb32198f9dbe34ae6081384b2cb2e6a83dd7 /src | |
parent | 8419a8a8e2bdc01aa37e475d3a83a2a4a9a4bdf8 (diff) | |
download | imv-037185de6d1bd6d6250e3226c680d115e23693d0.tar.gz |
Add some infrastructure for gif playback
Diffstat (limited to 'src')
-rw-r--r-- | src/loader.c | 27 | ||||
-rw-r--r-- | src/loader.h | 2 | ||||
-rw-r--r-- | src/main.c | 6 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/loader.c b/src/loader.c index 34641f1..404bbb5 100644 --- a/src/loader.c +++ b/src/loader.c @@ -102,16 +102,24 @@ char *imv_loader_get_error(struct imv_loader *ldr) void imv_loader_load_next_frame(struct imv_loader *ldr) { - pthread_mutex_lock(&ldr->lock); - /* TODO */ - pthread_mutex_unlock(&ldr->lock); + /* TODO kick off next frame thread */ } void imv_loader_time_passed(struct imv_loader *ldr, double dt) { + int get_frame = 0; pthread_mutex_lock(&ldr->lock); - /* TODO */ + if(ldr->num_frames > 1) { + ldr->frame_time -= dt; + if(ldr->frame_time < 0) { + get_frame = 1; + } + } pthread_mutex_unlock(&ldr->lock); + + if(get_frame) { + imv_loader_load_next_frame(); + } } void imv_loader_error_occurred(struct imv_loader *ldr) @@ -167,6 +175,7 @@ static void *imv_loader_bg_new_img(void *data) FIMULTIBITMAP *mbmp = NULL; FIBITMAP *bmp = NULL; int width, height; + int raw_frame_time = 100; /* default to 100 */ if(fmt == FIF_GIF) { mbmp = FreeImage_OpenMultiBitmap(FIF_GIF, path, @@ -191,7 +200,15 @@ static void *imv_loader_bg_new_img(void *data) width = FreeImage_GetWidth(frame); height = FreeImage_GetHeight(frame); bmp = FreeImage_ConvertTo32Bits(frame); + + /* get duration of first frame */ + FITAG *tag = NULL; + FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameTime", &tag); + if(FreeImage_GetTagValue(tag)) { + raw_frame_time = *(int*)FreeImage_GetTagValue(tag); + } FreeImage_UnlockPage(mbmp, frame, 0); + } else { FIBITMAP *image = FreeImage_Load(fmt, path, 0); free(path); @@ -231,7 +248,7 @@ static void *imv_loader_bg_new_img(void *data) ldr->cur_frame = 0; ldr->next_frame = 1; ldr->num_frames = num_frames; - ldr->frame_time = 0; + ldr->frame_time = (double)raw_frame_time * 0.0001; pthread_mutex_unlock(&ldr->lock); return 0; diff --git a/src/loader.h b/src/loader.h index 625dce5..7be7aa2 100644 --- a/src/loader.h +++ b/src/loader.h @@ -49,6 +49,6 @@ FIBITMAP *imv_loader_get_image(struct imv_loader *ldr); char *imv_loader_get_error(struct imv_loader *ldr); void imv_loader_load_next_frame(struct imv_loader *ldr); -/* void imv_loader_time_passed(struct imv_loader *ldr, double dt); */ +void imv_loader_time_passed(struct imv_loader *ldr, double dt); #endif @@ -390,6 +390,12 @@ int main(int argc, char** argv) } } + if(view.playing) { + double cur_time = SDL_GetTicks() / 1000.0; + double dt = cur_time - last_time; + last_time = SDL_GetTicks() / 1000.0; + imv_loader_time_passed(tex, dt); + } if(view.redraw) { if(g_options.solid_bg) { |