diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | man/feh.pre | 12 | ||||
-rw-r--r-- | src/feh.h | 1 | ||||
-rw-r--r-- | src/filelist.c | 21 | ||||
-rw-r--r-- | src/imlib.c | 116 | ||||
-rw-r--r-- | src/slideshow.c | 2 | ||||
-rwxr-xr-x | test/feh.i | 2 | ||||
-rw-r--r-- | test/feh.t | 2 | ||||
-rw-r--r-- | test/scr/index_full_h400 | bin | 3666 -> 3180 bytes | |||
-rw-r--r-- | test/scr/index_full_w400 | bin | 2280 -> 2135 bytes |
10 files changed, 118 insertions, 41 deletions
@@ -7,6 +7,9 @@ git HEAD * feh --list now uses %S/%P to print image size and amount of pixels * Fix zoom_default key (caused blurry images in some cases due to a bad workaround) + * make --quiet and --verbose behave more like their documented way, never + ignore out of memory errors + * Use ImageMagick (convert) as loader for unsupported file formats Thu, 02 Feb 2012 21:04:06 +0100 Daniel Friesel <derf@finalrewind.org> diff --git a/man/feh.pre b/man/feh.pre index f5bfcba..0bdc4d0 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -110,6 +110,18 @@ can also list either all the loadable files in a filelist or all the unloadable files. Useful for preening a directory. . . +.Sh SUPPORTED FORMATS +. +.Nm +can open any format supported by Imlib2, most notably jpeg and png. +. +If the convert binary +.Pq supplied by ImageMagick +is available, it also has limited support for many other filetypes, such as +svg, xcf and otf. +. +For animated images, only the first frame is shown. +. .Sh OPTIONS . .Bl -tag -width indent @@ -144,7 +144,6 @@ void feh_draw_zoom(winwidget w); void feh_draw_checks(winwidget win); void cb_slide_timer(void *data); void cb_reload_timer(void *data); -char *feh_http_load_image(char *url); int feh_load_image_char(Imlib_Image * im, char *filename); void feh_draw_filename(winwidget w); #ifdef HAVE_LIBEXIF diff --git a/src/filelist.c b/src/filelist.c index 9756c27..34df6cf 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -215,15 +215,13 @@ void add_file_to_filelist_recursively(char *origpath, unsigned char level) } n = scandir(path, &de, file_selector_all, alphasort); if (n < 0) { - switch (errno) { - case ENOMEM: - if (!opt.quiet) - weprintf("Insufficient memory to scan directory %s:", path); - break; - default: - if (!opt.quiet) - weprintf("Failed to scan directory %s:", path); - } + switch (errno) { + case ENOMEM: + weprintf("Insufficient memory to scan directory %s:", path); + break; + default: + weprintf("Failed to scan directory %s:", path); + } } for (cnt = 0; cnt < n; cnt++) { @@ -275,9 +273,6 @@ gib_list *feh_file_info_preload(gib_list * list) feh_file *file = NULL; gib_list *remove_list = NULL; - if (opt.verbose) - fputs(PACKAGE " - preloading...\n", stdout); - for (l = list; l; l = l->next) { file = FEH_FILE(l->data); D(("file %p, file->next %p, file->name %s\n", l, l->next, file->name)); @@ -533,7 +528,7 @@ void feh_save_filelist() tmpname = feh_unique_filename("", "filelist"); - if (!opt.quiet) + if (opt.verbose) printf("saving filelist to filename '%s'\n", tmpname); feh_write_filelist(filelist, tmpname); diff --git a/src/imlib.c b/src/imlib.c index 197b8f5..1b17b49 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -59,6 +59,9 @@ int xinerama_screen; int num_xinerama_screens; #endif /* HAVE_LIBXINERAMA */ +static char *feh_http_load_image(char *url); +static char *feh_magick_load_image(char *filename); + #ifdef HAVE_LIBXINERAMA void init_xinerama(void) { @@ -127,48 +130,56 @@ int feh_load_image_char(Imlib_Image * im, char *filename) int feh_load_image(Imlib_Image * im, feh_file * file) { Imlib_Load_Error err; + enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK } image_source = SRC_IMLIB; + char *tmpname = NULL; + char *real_filename = NULL; D(("filename is %s, image is %p\n", file->filename, im)); if (!file || !file->filename) - return(0); + return 0; /* Handle URLs */ if ((!strncmp(file->filename, "http://", 7)) || (!strncmp(file->filename, "https://", 8)) || (!strncmp(file->filename, "ftp://", 6))) { - char *tmpname = NULL; - char *tempcpy; + image_source = SRC_HTTP; tmpname = feh_http_load_image(file->filename); + } + else + *im = imlib_load_image_with_error_return(file->filename, &err); + + if ((err == IMLIB_LOAD_ERROR_UNKNOWN) + || (err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT)) { + image_source = SRC_MAGICK; + tmpname = feh_magick_load_image(file->filename); + } + + if (image_source != SRC_IMLIB) { if (tmpname == NULL) - return(0); + return 0; + *im = imlib_load_image_with_error_return(tmpname, &err); if (im) { - /* load the info now, in case it's needed after we delete the - temporary image file */ - tempcpy = file->filename; + real_filename = file->filename; file->filename = tmpname; feh_file_info_load(file, *im); - file->filename = tempcpy; + file->filename = real_filename; #ifdef HAVE_LIBEXIF file->ed = exif_get_data(tmpname); -#endif +#endif } - if ((opt.slideshow) && (opt.reload == 0)) { - /* Http, no reload, slideshow. Let's keep this image on hand... */ + if ((opt.slideshow) && (opt.reload == 0) && (image_source != SRC_MAGICK)) { free(file->filename); file->filename = estrdup(tmpname); if (!opt.keep_http) add_file_to_rm_filelist(tmpname); - } else { - /* Don't cache the image if we're doing reload + http (webcams etc) */ - if (!opt.keep_http) - unlink(tmpname); } + else if ((image_source == SRC_MAGICK) || !opt.keep_http) + unlink(tmpname); + free(tmpname); - } else { - *im = imlib_load_image_with_error_return(file->filename, &err); } if ((err) || (!im)) { @@ -177,7 +188,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) reset_output = 1; } if (err == IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS) - eprintf("While loading %s - Out of file descriptors", file->filename); + eprintf("%s - Out of file descriptors while loading", file->filename); else if (!opt.quiet) { switch (err) { case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: @@ -187,7 +198,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) weprintf("%s - Directory specified for image filename", file->filename); break; case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: - weprintf("%s - No read access to directory", file->filename); + weprintf("%s - No read access", file->filename); break; case IMLIB_LOAD_ERROR_UNKNOWN: case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: @@ -235,9 +246,66 @@ int feh_load_image(Imlib_Image * im, feh_file * file) return(1); } +static char *feh_magick_load_image(char *filename) +{ + char argv_fd[12]; + char *basename; + char *tmpname; + char *sfn; + int fd = -1, devnull = -1; + int pid, status; + + basename = strrchr(filename, '/'); + + if (basename == NULL) + basename = filename; + else + basename++; + + tmpname = feh_unique_filename("/tmp/", basename); + + if (strlen(tmpname) > (NAME_MAX-6)) + tmpname[NAME_MAX-7] = '\0'; + + sfn = estrjoin("_", tmpname, "XXXXXX", NULL); + free(tmpname); + + fd = mkstemp(sfn); + + if (fd == -1) + return NULL; + + snprintf(argv_fd, sizeof(argv_fd), "png:fd:%d", fd); + + + if ((pid = fork()) == 0) { + + /* discard convert output */ + devnull = open("/dev/null", O_WRONLY); + dup2(devnull, 1); + dup2(devnull, 2); + + execlp("convert", "convert", filename, argv_fd, NULL); + exit(1); + } + else { + waitpid(pid, &status, 0); + if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) { + close(fd); + unlink(sfn); + sfn = NULL; + + if (!opt.quiet) + weprintf("%s - No loader for that file format", filename); + } + } + + return sfn; +} + #ifdef HAVE_LIBCURL -char *feh_http_load_image(char *url) +static char *feh_http_load_image(char *url) { CURL *curl; CURLcode res; @@ -257,15 +325,15 @@ char *feh_http_load_image(char *url) } else path = "/tmp/"; - basename = strrchr(url, '/') + 1; - tmpname = feh_unique_filename(path, basename); - curl = curl_easy_init(); if (!curl) { weprintf("open url: libcurl initialization failure"); return NULL; } + basename = strrchr(url, '/') + 1; + tmpname = feh_unique_filename(path, basename); + if (strlen(tmpname) > (NAME_MAX-6)) tmpname[NAME_MAX-7] = '\0'; @@ -1033,7 +1101,7 @@ void feh_edit_inplace_lossless(winwidget w, int op) if ((pid = fork()) < 0) { im_weprintf(w, "lossless %s: fork failed:", op_name); - return; + exit(1); } else if (pid == 0) { execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value, diff --git a/src/slideshow.c b/src/slideshow.c index a65d95e..a868a44 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -571,7 +571,7 @@ void slideshow_save_image(winwidget win) tmpname = feh_unique_filename("", "noname.png"); } - if (!opt.quiet) + if (opt.verbose) printf("saving image to filename '%s'\n", tmpname); /* XXX gib_imlib_save_image_with_error_return breaks with *.XXX and @@ -299,7 +299,7 @@ SendKeys('{HOM PGU}'); test_win_title($win, 'feh [96 of 100] - test/ok/png'); feh_stop(); -$win = feh_start('--thumbnails -H 300 -W 310 --thumb-title "%P [%l] %f"', +$win = feh_start('--thumbnails -H 300 -W 310 --thumb-title "feh [%l] %f"', 'test/ok/png test/ok/gif test/ok/jpg'); test_win_title($win, 'feh [thumbnail mode]'); ($width, $height) = (GetWindowPos($win))[2,3]; @@ -33,7 +33,7 @@ if (length($feh_name) == 0) { } my $re_warning = - qr{${feh_name} WARNING: test/fail/... \- No Imlib2 loader for that file format\n}; + qr{${feh_name} WARNING: test/fail/... \- No loader for that file format\n}; my $re_loadable = qr{test/ok/...}; my $re_unloadable = qr{test/fail/...}; my $re_list_action = qr{test/ok/... 16x16}; diff --git a/test/scr/index_full_h400 b/test/scr/index_full_h400 Binary files differindex 7bcf2ab..b351eb7 100644 --- a/test/scr/index_full_h400 +++ b/test/scr/index_full_h400 diff --git a/test/scr/index_full_w400 b/test/scr/index_full_w400 Binary files differindex 1bab972..6e54f0f 100644 --- a/test/scr/index_full_w400 +++ b/test/scr/index_full_w400 |