summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-04-05 12:25:35 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-04-05 12:25:42 +0200
commitb7f13619d3a6a4fbd62dfa6da150e8f0bf571b7c (patch)
tree103850df1f3fa2728d09e20f7763dc72b4fab232 /src
parentf9af53cd8144714e75e3f95b9162882f4ee6334a (diff)
Use conversion cache for imlib2 and dcraw images
Diffstat (limited to 'src')
-rw-r--r--src/imlib.c50
-rw-r--r--src/options.c6
-rw-r--r--src/options.h2
3 files changed, 37 insertions, 21 deletions
diff --git a/src/imlib.c b/src/imlib.c
index 2eeb37d..8baa886 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -60,10 +60,7 @@ int xinerama_screen;
int num_xinerama_screens;
#endif /* HAVE_LIBXINERAMA */
-#ifdef HAVE_LIBCURL
-// TODO use cache for dcraw and magick conversion results as well
-gib_hash* http_cache = NULL;
-#endif
+gib_hash* conversion_cache = NULL;
int childpid = 0;
@@ -263,14 +260,14 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
file->ed = exif_get_data(tmpname);
#endif
}
- if ((image_source != SRC_HTTP) || (!opt.keep_http && !opt.use_http_cache))
+ if (!opt.use_conversion_cache && ((image_source != SRC_HTTP) || !opt.keep_http))
unlink(tmpname);
// keep_http already performs an add_file_to_rm_filelist call
- else if (opt.use_http_cache && !opt.keep_http)
+ else if (opt.use_conversion_cache && !opt.keep_http)
// add_file_to_rm_filelist duplicates tmpname
add_file_to_rm_filelist(tmpname);
- if (image_source != SRC_HTTP && !opt.use_http_cache)
+ if (image_source != SRC_HTTP && !opt.use_conversion_cache)
free(tmpname);
}
@@ -365,14 +362,12 @@ void feh_reload_image(winwidget w, int resize, int force_new)
if (force_new)
winwidget_free_image(w);
-#ifdef HAVE_LIBCURL
// if it's an external image, our own cache will also get in your way
char *sfn;
- if (opt.use_http_cache && (sfn = gib_hash_get(http_cache, FEH_FILE(w->file->data)->filename)) != NULL) {
+ if (opt.use_conversion_cache && (sfn = gib_hash_get(conversion_cache, FEH_FILE(w->file->data)->filename)) != NULL) {
free(sfn);
- gib_hash_set(http_cache, FEH_FILE(w->file->data)->filename, NULL);
+ gib_hash_set(conversion_cache, FEH_FILE(w->file->data)->filename, NULL);
}
-#endif
if ((feh_load_image(&tmp, FEH_FILE(w->file->data))) == 0) {
if (force_new)
@@ -450,6 +445,13 @@ static char *feh_dcraw_load_image(char *filename)
char *sfn;
int fd = -1;
+ if (opt.use_conversion_cache) {
+ if (!conversion_cache)
+ conversion_cache = gib_hash_new();
+ if ((sfn = gib_hash_get(conversion_cache, filename)) != NULL)
+ return sfn;
+ }
+
basename = strrchr(filename, '/');
if (basename == NULL)
@@ -500,6 +502,9 @@ static char *feh_dcraw_load_image(char *filename)
weprintf("%s - Conversion took too long, skipping", filename);
}
+ if ((sfn != NULL) && opt.use_conversion_cache)
+ gib_hash_set(conversion_cache, filename, sfn);
+
return sfn;
}
@@ -514,6 +519,13 @@ static char *feh_magick_load_image(char *filename)
int status;
char created_tempdir = 0;
+ if (opt.use_conversion_cache) {
+ if (!conversion_cache)
+ conversion_cache = gib_hash_new();
+ if ((sfn = gib_hash_get(conversion_cache, filename)) != NULL)
+ return sfn;
+ }
+
basename = strrchr(filename, '/');
if (basename == NULL)
@@ -632,6 +644,10 @@ static char *feh_magick_load_image(char *filename)
}
free(argv_fn);
+
+ if ((sfn != NULL) && opt.use_conversion_cache)
+ gib_hash_set(conversion_cache, filename, sfn);
+
return sfn;
}
@@ -671,10 +687,10 @@ static char *feh_http_load_image(char *url)
char *basename;
char *path = NULL;
- if (opt.use_http_cache) {
- if (!http_cache)
- http_cache = gib_hash_new();
- if ((sfn = gib_hash_get(http_cache, url)) != NULL)
+ if (opt.use_conversion_cache) {
+ if (!conversion_cache)
+ conversion_cache = gib_hash_new();
+ if ((sfn = gib_hash_get(conversion_cache, url)) != NULL)
return sfn;
}
@@ -750,8 +766,8 @@ static char *feh_http_load_image(char *url)
free(ebuff);
fclose(sfp);
- if (opt.use_http_cache)
- gib_hash_set(http_cache, url, sfn);
+ if (opt.use_conversion_cache)
+ gib_hash_set(conversion_cache, url, sfn);
return sfn;
} else {
weprintf("open url: fdopen failed:");
diff --git a/src/options.c b/src/options.c
index eb0fbe5..19f8db9 100644
--- a/src/options.c
+++ b/src/options.c
@@ -76,7 +76,7 @@ void init_parse_options(int argc, char **argv)
#ifdef HAVE_INOTIFY
opt.auto_reload = 1;
#endif /* HAVE_INOTIFY */
- opt.use_http_cache = 1;
+ opt.use_conversion_cache = 1;
feh_getopt_theme(argc, argv);
@@ -525,7 +525,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
break;
case 'R':
opt.reload = atof(optarg);
- opt.use_http_cache = 0;
+ opt.use_conversion_cache = 0;
#ifdef HAVE_INOTIFY
opt.auto_reload = 0;
#endif
@@ -831,7 +831,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
opt.x11_class = estrdup(optarg);
break;
case 250:
- opt.use_http_cache = 0;
+ opt.use_conversion_cache = 0;
break;
default:
break;
diff --git a/src/options.h b/src/options.h
index 74ef33f..f7bb202 100644
--- a/src/options.h
+++ b/src/options.h
@@ -49,7 +49,7 @@ struct __fehoptions {
unsigned char aspect;
unsigned char stretch;
unsigned char keep_http;
- unsigned char use_http_cache;
+ unsigned char use_conversion_cache;
unsigned char borderless;
unsigned char randomize;
unsigned char jump_on_resort;