diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2015-12-10 15:26:01 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2015-12-10 15:26:01 +0000 |
commit | 3e1523d6a7c83d74673f5106ff87f7da465f467c (patch) | |
tree | 9a93d3b3df80e2593649101339780904808cc0a9 /src | |
parent | 6cd76000aa7875fcc7a74cce0ce31783fd82196d (diff) | |
download | imv-3e1523d6a7c83d74673f5106ff87f7da465f467c.tar.gz |
Make imv_loader_get_image more informative
Diffstat (limited to 'src')
-rw-r--r-- | src/loader.c | 11 | ||||
-rw-r--r-- | src/loader.h | 10 | ||||
-rw-r--r-- | src/main.c | 10 |
3 files changed, 19 insertions, 12 deletions
diff --git a/src/loader.c b/src/loader.c index 97ba8e4..22ed9be 100644 --- a/src/loader.c +++ b/src/loader.c @@ -81,14 +81,17 @@ void imv_loader_load_path(struct imv_loader *ldr, const char *path) pthread_mutex_unlock(&ldr->lock); } -FIBITMAP *imv_loader_get_image(struct imv_loader *ldr) +int imv_loader_get_image(struct imv_loader *ldr, FIBITMAP **out_bmp, + int *out_is_new_image) { - FIBITMAP *ret = NULL; + int ret = 0; pthread_mutex_lock(&ldr->lock); if(ldr->out_bmp) { - ret = ldr->out_bmp; + *out_bmp = ldr->out_bmp; ldr->out_bmp = NULL; + *out_is_new_image = ldr->out_is_new_image; + ret = 1; } pthread_mutex_unlock(&ldr->lock); @@ -250,6 +253,7 @@ static void *imv_loader_bg_new_img(void *data) FreeImage_Unload(ldr->out_bmp); } ldr->out_bmp = FreeImage_Clone(bmp); + ldr->out_is_new_image = 1; ldr->width = width; ldr->height = height; ldr->cur_frame = 0; @@ -364,6 +368,7 @@ static void *imv_loader_bg_next_frame(void *data) FreeImage_Unload(ldr->out_bmp); } ldr->out_bmp = FreeImage_Clone(ldr->bmp); + ldr->out_is_new_image = 0; pthread_mutex_unlock(&ldr->lock); return 0; diff --git a/src/loader.h b/src/loader.h index 5f5a85e..46a7b97 100644 --- a/src/loader.h +++ b/src/loader.h @@ -29,6 +29,7 @@ struct imv_loader { pthread_t bg_thread; char *path; FIBITMAP *out_bmp; + int out_is_new_image; char *out_err; FIMULTIBITMAP *mbmp; FIBITMAP *bmp; @@ -49,9 +50,12 @@ void imv_destroy_loader(struct imv_loader *img); /* Asynchronously load the given file */ void imv_loader_load_path(struct imv_loader *ldr, const char *path); -/* Returns image data if available. NULL if not. Caller is responsible for - * cleaning up the data returned. Each image is only returned once. */ -FIBITMAP *imv_loader_get_image(struct imv_loader *ldr); +/* Returns 1 if image data is available. 0 if not. Caller is responsible for + * cleaning up the data returned. Each image is only returned once. + * out_is_frame indicates whether the returned image is a new image, or just + * a new frame of an existing one. */ +int imv_loader_get_image(struct imv_loader *ldr, FIBITMAP **out_bmp, + int *out_is_frame); /* If a file failed to loadd, return the path to that file. Otherwise returns * NULL. Only returns the path once. Caller is responsible for cleaning up the @@ -275,8 +275,7 @@ int main(int argc, char** argv) unsigned int last_time; unsigned int current_time; - /* used to keep track of when the selected image has changed */ - int is_new_image = 1; + /* do we need to redraw the window? */ int need_redraw = 1; /* used to calculate when to skip to the next image in slideshow mode */ @@ -412,17 +411,16 @@ int main(int argc, char** argv) imv_loader_load_path(&ldr, current_path); view.playing = 1; - is_new_image = 1; } /* check if a new image is available to display */ - FIBITMAP *bmp = imv_loader_get_image(&ldr); - if(bmp) { + FIBITMAP *bmp; + int is_new_image; + if(imv_loader_get_image(&ldr, &bmp, &is_new_image)) { imv_texture_set_image(&tex, bmp); FreeImage_Unload(bmp); need_redraw = 1; if(is_new_image) { - is_new_image = 0; if(g_options.actual) { imv_viewport_scale_to_actual(&view, &tex); } else { |