Make imv_loader_get_image more informative
This commit is contained in:
parent
6cd76000aa
commit
3e1523d6a7
11
src/loader.c
11
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;
|
||||
|
|
10
src/loader.h
10
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
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue