use strict;
my $progname = $0; $progname =~ s@.*/@@g;
-my $version = q{ $Revision: 1.17 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
+my $version = q{ $Revision: 1.21 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
my $verbose = 0;
my $use_stdin = 0;
# "xsri -scale -keep-aspect -center-horizontal -center-vertical",
);
+# apparently some versions of netpbm call it "pamoil" instead of "pgmoil"...
+#
+my $pgmoil = (which("pamoil") ? "pamoil" : "pgmoil");
+
# List of interesting PPM filter pipelines.
# In this list, the following magic words may be used:
my @filters = (
"ppmtopgm FILE1 | pgmedge | pgmtoppm COLORS | ppmnorm",
"ppmtopgm FILE1 | pgmenhance | pgmtoppm COLORS",
- "ppmtopgm FILE1 | pgmoil | pgmtoppm COLORS",
+ "ppmtopgm FILE1 | $pgmoil | pgmtoppm COLORS",
"ppmtopgm FILE1 | pgmbentley | pgmtoppm COLORS",
"ppmrelief FILE1 | ppmtopgm | pgmedge | ppmrelief | ppmtopgm |" .
" pnmflip -tb FILE3 | ppmnorm > FILE2 ; " .
" pnmarith -multiply FILE1 FILE2",
- "ppmshift 30 FILE1 | ppmtopgm | pgmoil | pgmedge | " .
+ "ppmshift 30 FILE1 | ppmtopgm | $pgmoil | pgmedge | " .
" pgmtoppm COLORS > FILE2 ; " .
" pnmarith -difference FILE1 FILE2",
}
+# returns the full path of the named program, or undef.
+#
+sub which {
+ my ($prog) = @_;
+ foreach (split (/:/, $ENV{PATH})) {
+ if (-x "$_/$prog") {
+ return $prog;
+ }
+ }
+ return undef;
+}
+
+
# Choose random foreground and background colors
#
sub randcolors {
local *IN;
open (IN, "<$conf") || error "reading $conf: $!";
while (<IN>) {
- if (!$imagedir && m/^imageDirectory:\s+([^\s]+)\s*$/i) { $imagedir = $1; }
+ if (!$imagedir && m/^imageDirectory:\s+(.*)\s*$/i) { $imagedir = $1; }
elsif (m/^grabVideoFrames:\s+true\s*$/i) { $video_p = 1; }
elsif (m/^grabVideoFrames:\s+false\s*$/i) { $video_p = 0; }
elsif (m/^chooseRandomImages:\s+true\s*$/i) { $file_p = 1; }
$file_p = 1 if $had_dir;
+ $imagedir = undef unless ($imagedir && $imagedir ne '');
if (!$file_p && !$video_p) {
# error "neither grabVideoFrames nor chooseRandomImages are set\n\t" .
my $v = ($verbose <= 1 ? "" : "-" . ("v" x ($verbose-1)));
my $cmd;
if ($do_file_p) {
- $cmd = "xscreensaver-getimage-file $v --name $imagedir";
+ $cmd = "xscreensaver-getimage-file $v --name \"$imagedir\"";
} else {
$cmd = "xscreensaver-getimage-video $v --stdout";
}
if ($do_file_p) {
- print STDERR "$progname: running \"$cmd\"\n" if ($verbose > 1);
+ print STDERR "$progname: running: $cmd\n" if ($verbose > 1);
my $fn = `$cmd`;
$fn =~ s/\n$//s;
error "didn't get a file?" if ($fn eq "");
print STDERR "$progname: selected file $fn\n" if ($verbose > 1);
- if ($fn =~ m/\.gif/i) { $cmd = "giftopnm < $fn"; }
- elsif ($fn =~ m/\.jpe?g/i) { $cmd = "djpeg < $fn"; }
+ if ($fn =~ m/\.gif/i) { $cmd = "giftopnm < \"$fn\""; }
+ elsif ($fn =~ m/\.jpe?g/i) { $cmd = "djpeg < \"$fn\""; }
+ elsif ($fn =~ m/\.png/i) { $cmd = "pngtopnm < \"$fn\""; }
+ elsif ($fn =~ m/\.xpm/i) { $cmd = "xpmtoppm < \"$fn\""; }
+ elsif ($fn =~ m/\.bmp/i) { $cmd = "bmptoppm < \"$fn\""; }
+ elsif ($fn =~ m/\.tiff?/i) { $cmd = "tifftopnm < \"$fn\""; }
+ elsif ($fn =~ m/\.p[bgp]m/i) { return `cat \"$fn\"`; }
else {
error "unrecognized file extension on $fn";
}
- print STDERR "$progname: converting with \"$cmd\"\n" if ($verbose > 1);
+ print STDERR "$progname: converting with: $cmd\n" if ($verbose > 1);
$cmd .= " 2>/dev/null" unless ($verbose > 1);
$ppm = `$cmd`;
} else {
- print STDERR "$progname: running \"$cmd\"\n" if ($verbose > 1);
+ print STDERR "$progname: running: $cmd\n" if ($verbose > 1);
$ppm = `$cmd`;
error "no data?" if ($ppm eq "");
error "not a PPM file" unless ($ppm =~ m/^P\d\n/s);
}
$ppm = $stdin_ppm;
} else {
- $ppm = get_ppm();
+ my $max_err_count = 20;
+ my $err_count = 0;
+ while (!defined($ppm)) {
+ $ppm = get_ppm();
+ $err_count++ if (!defined ($ppm));
+ error ("too many errors, too few images!")
+ if ($err_count > $max_err_count);
+ }
}
$ppm = frob_ppm ($ppm);
read_config;
if (!$use_stdout) {
- $_ = `xdpyinfo 2>-`;
+ $_ = `xdpyinfo 2>&-`;
($screen_width) =~ m/ dimensions: +(\d+)x(\d+) pixels/;
$screen_width = 800 unless $screen_width > 0;
}