Skip to content

Commit

Permalink
Add --min-dimension and --max-dimension options (closes #101)
Browse files Browse the repository at this point in the history
  • Loading branch information
derf committed Oct 13, 2012
1 parent 8caf865 commit 906ec65
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
git HEAD

* Add --min-dim and --max-dim options to only process images with certain
dimensions

Thu, 27 Sep 2012 16:48:48 +0200 Daniel Friesel <derf+feh@finalrewind.org>

* Fix segfault when doing lossless mirror/rotate and jpegexiforient is
Expand Down
22 changes: 22 additions & 0 deletions man/feh.pre
Expand Up @@ -397,13 +397,30 @@ of zero causes
.Nm
to try indefinitely. By default, magick support is disabled.
.
.It Cm --max-dimension Ar width No x Ar height
.
Only show images with width <=
.Ar width
and height <=
.Ar height .
If you only care about one parameter, set the other to either something large
or -1.
.
.It Cm -M , --menu-font Ar font
.
Use
.Ar font
.Pq truetype, with size, like Qq yudit/12
as menu font.
.
.It Cm --min-dimension Ar width No x Ar height
.
Only show images with width >=
.Ar width
and height >=
.Ar height .
If you only care about one parameter, set the other to 0.
.
.It Cm -m , --montage
.
Enable montage mode. Montage mode creates a new image consisting of a grid of
Expand Down Expand Up @@ -1463,6 +1480,11 @@ Same as above
.
Show some EXIF information, extracted by exifprobe/exifgrep
.
.It feh --action 'rm %F' -rl --max-dim 1000x800
.
Resursively remove all images with dimensions below or equal to 1000x800 pixels
from the current directory.
.
.El
.
.
Expand Down
10 changes: 9 additions & 1 deletion src/filelist.c
Expand Up @@ -281,6 +281,13 @@ gib_list *feh_file_info_preload(gib_list * list)
remove_list = gib_list_add_front(remove_list, l);
if (opt.verbose)
feh_display_status('x');
} else if (((unsigned int)file->info->width < opt.min_width)
|| ((unsigned int)file->info->width > opt.max_width)
|| ((unsigned int)file->info->height < opt.min_height)
|| ((unsigned int)file->info->height > opt.max_height)) {
remove_list = gib_list_add_front(remove_list, l);
if (opt.verbose)
feh_display_status('s');
} else if (opt.verbose)
feh_display_status('.');
}
Expand Down Expand Up @@ -375,7 +382,8 @@ int feh_cmp_format(void *file1, void *file2)
void feh_prepare_filelist(void)
{
if (opt.list || opt.customlist || (opt.sort > SORT_FILENAME)
|| opt.preload) {
|| opt.preload || opt.min_width || opt.min_height
|| (opt.max_width != UINT_MAX) || (opt.max_height != UINT_MAX)) {
/* For these sort options, we have to preload images */
filelist = feh_file_info_preload(filelist);
if (!gib_list_length(filelist))
Expand Down
13 changes: 11 additions & 2 deletions src/options.c
Expand Up @@ -60,6 +60,7 @@ void init_parse_options(int argc, char **argv)
opt.menu_font = estrdup(DEFAULT_MENU_FONT);
opt.font = NULL;
opt.menu_bg = estrdup(PREFIX "/share/feh/images/menubg_default.png");
opt.max_height = opt.max_width = UINT_MAX;

opt.start_list_at = NULL;
opt.jump_on_resort = 1;
Expand Down Expand Up @@ -300,15 +301,18 @@ static void feh_getopt_theme(int argc, char **argv)

static void feh_parse_option_array(int argc, char **argv, int finalrun)
{
int discard;
static char stropts[] =
"a:A:b:B:cC:dD:e:E:f:Fg:GhH:iIj:J:kK:lL:mM:nNo:O:pPqrR:sS:tT:uUvVwW:xXy:YzZ"
".@:^:~:):|:+:";
".@:^:~:):|:+:<:>:";

/* (*name, has_arg, *flag, val) See: struct option in getopts.h */
static struct option lopts[] = {
{"menu-bg" , 1, 0, ')'},
{"debug" , 0, 0, '+'},
{"scale-down" , 0, 0, '.'},
{"max-dimension" , 1, 0, '<'},
{"min-dimension" , 1, 0, '>'},
{"title-font" , 1, 0, '@'},
{"action" , 1, 0, 'A'},
{"image-bg" , 1, 0, 'B'},
Expand Down Expand Up @@ -398,7 +402,6 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
};
int optch = 0, cmdx = 0;

/* Now to pass some optionarinos */
while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != EOF) {
D(("Got option, getopt calls it %d, or %c\n", optch, optch));
switch (optch) {
Expand All @@ -412,6 +415,12 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
case '+':
opt.debug = 1;
break;
case '<':
XParseGeometry(optarg, &discard, &discard, &opt.max_width, &opt.max_height);
break;
case '>':
XParseGeometry(optarg, &discard, &discard, &opt.min_width, &opt.min_height);
break;
case '.':
opt.scale_down = 1;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/options.h
Expand Up @@ -109,6 +109,8 @@ struct __fehoptions {
int zoom_mode;
unsigned char adjust_reload;

unsigned int min_width, min_height, max_width, max_height;

unsigned char mode;
unsigned char paused;

Expand Down
31 changes: 28 additions & 3 deletions test/feh.t
Expand Up @@ -2,13 +2,14 @@
use strict;
use warnings;
use 5.010;
use Test::Command tests => 59;
use Test::Command tests => 71;

$ENV{HOME} = 'test';

my $feh = "src/feh";
my $images = 'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm '
. 'test/fail/gif test/fail/jpg test/fail/png test/fail/pnm';
my $images_ok = 'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm';
my $images_fail = 'test/fail/gif test/fail/jpg test/fail/png test/fail/pnm';
my $images = "${images_ok} ${images_fail}";

my $feh_name = $ENV{'PACKAGE'};

Expand Down Expand Up @@ -133,3 +134,27 @@ $cmd = Test::Command->new(cmd =>
$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_like($re_list_action);

$cmd = Test::Command->new(cmd => "$feh --list --min-dimension 20x20 $images_ok");

$cmd->exit_is_num(1);
$cmd->stdout_is_eq('');
$cmd->stderr_is_file('test/no-loadable-files');

$cmd = Test::Command->new(cmd => "$feh --list --max-dimension 10x10 $images_ok");

$cmd->exit_is_num(1);
$cmd->stdout_is_eq('');
$cmd->stderr_is_file('test/no-loadable-files');

$cmd = Test::Command->new(cmd => "$feh --list --min-dimension 16x16 $images_ok");

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd => "$feh --list --max-dimension 16x16 $images_ok");

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_is_eq('');
2 changes: 2 additions & 0 deletions test/no-loadable-files
@@ -0,0 +1,2 @@
feh: No loadable images specified.
See 'man feh' for detailed usage information

0 comments on commit 906ec65

Please sign in to comment.