Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force-conversion option to skip imlib2 image loading and directly try to convert the image instead #786

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions man/feh.pre
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ digital cameras and similar.
If the ImageMagick convert binary is available,
.Nm
will use it to load file types such as svg, xcf, and otf.
Additionally
.Cm --force-conversion
can be used to skip the regular imlib2 image loading before trying to convert.
.
.Pp
.
Expand Down Expand Up @@ -339,6 +342,15 @@ zero causes
to try indefinitely.
Negative values restore the default by disabling conversion altogether.
.
.It Cm --force-conversion
.
Force image conversion and skip the regular imlib2 image loading.
If
.Cm --conversion-timeout
is not set or negative,
.Cm --conversion-timeout
will be set to zero.
.
.It Cm --class Ar class
.
Set the X11 class hint to
Expand Down
3 changes: 3 additions & 0 deletions src/help.raw
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ OPTIONS
-Y, --hide-pointer Hide the pointer
--conversion-timeout INT Load unknown files with dcraw or ImageMagick,
timeout after INT seconds (0: no timeout)
--force-conversion Force image conversion and skip the regular imlib2
image loading. Use conversion timeout of 0 if
timeout is not set or negative.
--min-dimension WxH Only show images with width >= W and height >= H
--max-dimension WxH Only show images with width <= W and height <= H
--scroll-step COUNT scroll COUNT pixels when movement key is pressed
Expand Down
13 changes: 12 additions & 1 deletion src/imlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ int feh_load_image(Imlib_Image * im, feh_file * file)

D(("filename is %s, image is %p\n", file->filename, im));

if (opt.force_conversion && opt.conversion_timeout < 0) {
D(("Conversion forced without conversion timeout! Setting timeout to zero (infinite).\n"));
opt.conversion_timeout = 0;
}

if (!file || !file->filename)
return 0;

Expand All @@ -348,7 +353,11 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
}
}
else {
if (feh_is_image(file, 0)) {
if (opt.force_conversion) {
/* Use unknown error for later processing of converted image */
err = IMLIB_LOAD_ERROR_UNKNOWN;
}
else if (feh_is_image(file, 0)) {
*im = imlib_load_image_with_error_return(file->filename, &err);
} else {
feh_err = LOAD_ERROR_MAGICBYTES;
Expand All @@ -360,12 +369,14 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
(err == IMLIB_LOAD_ERROR_UNKNOWN) ||
(err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT))) {
if (feh_file_is_raw(file->filename)) {
D(("Trying image conversion with dcraw.\n"));
image_source = SRC_DCRAW;
tmpname = feh_dcraw_load_image(file->filename);
if (!tmpname) {
feh_err = LOAD_ERROR_DCRAW;
}
} else {
D(("Trying image conversion with imagemagick.\n"));
image_source = SRC_MAGICK;
feh_err = LOAD_ERROR_IMLIB;
tmpname = feh_magick_load_image(file->filename);
Expand Down
4 changes: 4 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
{"cache-size" , 1, 0, OPTION_cache_size},
{"on-last-slide" , 1, 0, OPTION_on_last_slide},
{"conversion-timeout" , 1, 0, OPTION_conversion_timeout},
{"force-conversion" , 0, 0, OPTION_force_conversion},
{"version-sort" , 0, 0, OPTION_version_sort},
{"offset" , 1, 0, OPTION_offset},
#ifdef HAVE_INOTIFY
Expand Down Expand Up @@ -830,6 +831,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
case OPTION_conversion_timeout:
opt.conversion_timeout = atoi(optarg);
break;
case OPTION_force_conversion:
opt.force_conversion = 1;
break;
case OPTION_version_sort:
opt.version_sort = 1;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct __fehoptions {
double slideshow_delay;

signed int conversion_timeout;
int force_conversion;

Imlib_Font menu_fn;
};
Expand Down Expand Up @@ -250,6 +251,7 @@ OPTION_no_recursive,
OPTION_cache_size,
OPTION_on_last_slide,
OPTION_conversion_timeout,
OPTION_force_conversion,
OPTION_version_sort,
OPTION_offset,
OPTION_auto_reload,
Expand Down