~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper-updates

« back to all changes in this revision

Viewing changes to hacks/vidwhacker

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2005-04-09 00:06:43 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050409000643-z0abtifbt9s20pcc
Tags: 4.21-3
Patch by Joachim Breitner to check more frequently if DPMS kicked in (closes: #303374, #286664).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl -w
2
 
# vidwhacker, for xscreensaver.  Copyright (c) 1998-2001 Jamie Zawinski.
 
2
# vidwhacker, for xscreensaver.  Copyright (c) 1998-2004 Jamie Zawinski.
3
3
#
4
4
# Permission to use, copy, modify, distribute, and sell this software and its
5
5
# documentation for any purpose is hereby granted without fee, provided that
21
21
use strict;
22
22
 
23
23
my $progname = $0; $progname =~ s@.*/@@g;
24
 
my $version = q{ $Revision: 1.18 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
 
24
my $version = q{ $Revision: 1.25 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
25
25
 
26
26
my $verbose = 0;
27
27
my $use_stdin = 0;
33
33
 
34
34
my $screen_width = -1;
35
35
 
36
 
 
37
 
 
38
 
# ####  This list was lifted from driver/xscreensaver-getimage-file
39
 
#
40
 
# These are programs that can be used to put an image file on the root
41
 
# window (including virtual root windows.)  The first one of these programs
42
 
# that exists on $PATH will be used (with the file name as the last arg.)
43
 
#
44
 
# If you add other programs to this list, please let me know!
45
 
#
46
 
my @displayer_programs = (
47
 
  "xv         -root -quit -viewonly -maxpect -noresetroot -quick24 -rmode 5" .
48
 
  "           -rfg black -rbg black",
49
 
  "xli        -quiet -fullscreen -onroot -border black",
50
 
  "xloadimage -quiet -fullscreen -onroot -center -border black",
51
 
  "chbg       -once -xscreensaver -max_grow 4",
52
 
 
53
 
# this lame program wasn't built with vroot.h:
54
 
# "xsri       -scale -keep-aspect -center-horizontal -center-vertical",
55
 
);
 
36
my $displayer = "xscreensaver-getimage -root -file";
 
37
 
 
38
 
 
39
# apparently some versions of netpbm call it "pamoil" instead of "pgmoil"...
 
40
#
 
41
my $pgmoil = (which("pamoil") ? "pamoil" : "pgmoil");
56
42
 
57
43
 
58
44
# List of interesting PPM filter pipelines.
68
54
my @filters = (
69
55
  "ppmtopgm FILE1 | pgmedge | pgmtoppm COLORS | ppmnorm",
70
56
  "ppmtopgm FILE1 | pgmenhance | pgmtoppm COLORS",
71
 
  "ppmtopgm FILE1 | pgmoil | pgmtoppm COLORS",
 
57
  "ppmtopgm FILE1 | $pgmoil | pgmtoppm COLORS",
72
58
  "ppmtopgm FILE1 | pgmbentley | pgmtoppm COLORS",
73
59
 
74
60
  "ppmrelief FILE1 | ppmtopgm | pgmedge | ppmrelief | ppmtopgm |" .
110
96
  " pnmflip -tb FILE3 | ppmnorm > FILE2 ; " .
111
97
  " pnmarith -multiply FILE1 FILE2",
112
98
 
113
 
  "ppmshift 30 FILE1 | ppmtopgm | pgmoil | pgmedge | " .
 
99
  "ppmshift 30 FILE1 | ppmtopgm | $pgmoil | pgmedge | " .
114
100
  "   pgmtoppm COLORS > FILE2 ; " .
115
101
  " pnmarith -difference FILE1 FILE2",
116
102
 
134
120
  exit 1;
135
121
}
136
122
 
137
 
# ####  Lifted from driver/xscreensaver-getimage-file
138
 
#
139
 
sub pick_displayer {
140
 
  my @names = ();
141
 
 
142
 
  foreach my $cmd (@displayer_programs) {
143
 
    $_ = $cmd;
144
 
    my ($name) = m/^([^ ]+)/;
145
 
    push @names, "\"$name\"";
146
 
    print STDERR "$progname: looking for $name...\n" if ($verbose > 2);
147
 
    foreach my $dir (split (/:/, $ENV{PATH})) {
148
 
      print STDERR "$progname:   checking $dir/$name\n" if ($verbose > 3);
149
 
      return $cmd if (-x "$dir/$name");
 
123
# Any files on this list will be deleted at exit.
 
124
#
 
125
my @all_tmpfiles = ();
 
126
 
 
127
sub exit_cleanup {
 
128
  print STDERR "$progname: delete tmp files\n" if ($verbose);
 
129
  unlink @all_tmpfiles;
 
130
}
 
131
 
 
132
sub signal_cleanup {
 
133
  my ($sig) = @_;
 
134
  print STDERR "$progname: caught SIG$sig\n" if ($verbose);
 
135
  exit 1;
 
136
}
 
137
 
 
138
sub init_signals {
 
139
 
 
140
  $SIG{HUP}  = \&signal_cleanup;
 
141
  $SIG{INT}  = \&signal_cleanup;
 
142
  $SIG{QUIT} = \&signal_cleanup;
 
143
  $SIG{ABRT} = \&signal_cleanup;
 
144
  $SIG{KILL} = \&signal_cleanup;
 
145
  $SIG{TERM} = \&signal_cleanup;
 
146
 
 
147
  # Need this so that if giftopnm dies, we don't die.
 
148
  $SIG{PIPE} = 'IGNORE';
 
149
}
 
150
 
 
151
END { exit_cleanup(); }
 
152
 
 
153
 
 
154
 
 
155
 
 
156
# returns the full path of the named program, or undef.
 
157
#
 
158
sub which {
 
159
  my ($prog) = @_;
 
160
  foreach (split (/:/, $ENV{PATH})) {
 
161
    if (-x "$_/$prog") {
 
162
      return $prog;
150
163
    }
151
164
  }
152
 
 
153
 
  $names[$#names] = "or " . $names[$#names];
154
 
  printf STDERR "$progname: none of: " . join (", ", @names) .
155
 
                " were found on \$PATH.\n";
156
 
  exit 1;
 
165
  return undef;
157
166
}
158
167
 
159
168
 
170
179
}
171
180
 
172
181
 
 
182
 
173
183
sub filter_subst {
174
184
  my ($filter, $width, $height, @tmpfiles) = @_;
175
185
  my $colors = randcolors();
201
211
 
202
212
  my $tmpdir = $ENV{TMPDIR};
203
213
  $tmpdir = "/tmp" unless $tmpdir;
204
 
  my $fn = sprintf("$tmpdir/vw.%04x", $$);
205
 
  my @files = ( "$fn", "$fn.1", "$fn.2", "$fn.3" );
 
214
  my $fn =  sprintf ("%s/vidwhacker-0-%08x", $tmpdir, rand(0xFFFFFFFF));
 
215
  my $fn1 = sprintf ("%s/vidwhacker-1-%08x", $tmpdir, rand(0xFFFFFFFF));
 
216
  my $fn2 = sprintf ("%s/vidwhacker-2-%08x", $tmpdir, rand(0xFFFFFFFF));
 
217
  my $fn3 = sprintf ("%s/vidwhacker-3-%08x", $tmpdir, rand(0xFFFFFFFF));
 
218
  my @files = ( "$fn", "$fn1", "$fn2", "$fn3" );
 
219
  push @all_tmpfiles, @files;
206
220
 
207
221
  my $n = int(rand($#filters+1));
208
222
  my $filter = $filters[$n];
315
329
 
316
330
    if ($do_file_p) {
317
331
 
318
 
      print STDERR "$progname: running \"$cmd\"\n" if ($verbose > 1);
 
332
      print STDERR "$progname: running: $cmd\n" if ($verbose > 1);
319
333
      my $fn = `$cmd`;
320
334
      $fn =~ s/\n$//s;
321
335
      error "didn't get a file?" if ($fn eq "");
324
338
 
325
339
      if    ($fn =~ m/\.gif/i)   { $cmd = "giftopnm < \"$fn\""; }
326
340
      elsif ($fn =~ m/\.jpe?g/i) { $cmd = "djpeg < \"$fn\""; }
 
341
      elsif ($fn =~ m/\.png/i)   { $cmd = "pngtopnm < \"$fn\""; }
 
342
      elsif ($fn =~ m/\.xpm/i)   { $cmd = "xpmtoppm < \"$fn\""; }
 
343
      elsif ($fn =~ m/\.bmp/i)   { $cmd = "bmptoppm < \"$fn\""; }
 
344
      elsif ($fn =~ m/\.tiff?/i) { $cmd = "tifftopnm < \"$fn\""; }
 
345
      elsif ($fn =~ m/\.p[bgp]m/i) { return `cat \"$fn\"`; }
327
346
      else {
328
347
        error "unrecognized file extension on $fn";
329
348
      }
330
349
 
331
 
      print STDERR "$progname: converting with \"$cmd\"\n" if ($verbose > 1);
 
350
      print STDERR "$progname: converting with: $cmd\n" if ($verbose > 1);
332
351
      $cmd .= " 2>/dev/null" unless ($verbose > 1);
333
352
      $ppm = `$cmd`;
334
353
 
335
354
    } else {
336
355
 
337
 
      print STDERR "$progname: running \"$cmd\"\n" if ($verbose > 1);
 
356
      print STDERR "$progname: running: $cmd\n" if ($verbose > 1);
338
357
      $ppm = `$cmd`;
339
358
      error "no data?" if ($ppm eq "");
340
359
      error "not a PPM file" unless ($ppm =~ m/^P\d\n/s);
362
381
    print $ppm;
363
382
 
364
383
  } else {
365
 
    my $displayer = pick_displayer();
366
 
 
367
384
    my $tmpdir = $ENV{TMPDIR};
368
385
    $tmpdir = "/tmp" unless $tmpdir;
369
 
    my $fn = sprintf("$tmpdir/vw.%04x", $$);
 
386
    my $fn =  sprintf ("%s/vidwhacker-%08x", $tmpdir, rand(0xFFFFFFFF));
370
387
    local *OUT;
371
388
    unlink $fn;
 
389
    push @all_tmpfiles, $fn;
372
390
    open (OUT, ">$fn") || error "writing $fn: $!";
373
391
    print OUT $ppm;
374
392
    close OUT;
379
397
      if ($verbose);
380
398
    system (@cmd);
381
399
 
 
400
    my $exit_value  = $? >> 8;
 
401
    my $signal_num  = $? & 127;
 
402
    my $dumped_core = $? & 128;
 
403
 
382
404
    unlink $fn;
 
405
 
 
406
    error ("$cmd[0]: core dumped!") if ($dumped_core);
 
407
    error ("$cmd[0]: signal $signal_num!") if ($signal_num);
 
408
    error ("$cmd[0]: exited with $exit_value!") if ($exit_value);
383
409
  }
384
410
}
385
411
 
394
420
    }
395
421
    $ppm = $stdin_ppm;
396
422
  } else {
397
 
    $ppm = get_ppm();
 
423
    my $max_err_count = 20;
 
424
    my $err_count = 0;
 
425
    while (!defined($ppm)) {
 
426
      $ppm = get_ppm();
 
427
      $err_count++ if (!defined ($ppm));
 
428
      error ("too many errors, too few images!")
 
429
        if ($err_count > $max_err_count);
 
430
    }
398
431
  }
399
432
 
400
433
  $ppm = frob_ppm ($ppm);
407
440
  print STDERR "VidWhacker, Copyright (c) 2001 Jamie Zawinski <jwz\@jwz.org>\n";
408
441
  print STDERR "            http://www.jwz.org/xscreensaver/";
409
442
  print STDERR "\n";
410
 
  print STDERR "usage: $0 [-display dpy] [-verbose] [-root | -window]\n";
411
 
  print STDERR "                  [-stdin] [-stdout] [-delay secs]\n";
412
 
  print STDERR "                  [-directory image_directory]\n";
 
443
  print STDERR "usage: $0 [-display dpy] [-verbose]\n";
 
444
  print STDERR "\t\t[-root | -window | -window-id 0xXXXXX ]\n";
 
445
  print STDERR "\t\t[-stdin] [-stdout] [-delay secs]\n";
 
446
  print STDERR "\t\t[-directory image_directory]\n";
413
447
  exit 1;
414
448
}
415
449
 
424
458
    elsif (m/^--?delay$/) { $delay = shift @ARGV; }
425
459
    elsif (m/^--?dir(ectory)?$/) { $imagedir = shift @ARGV; }
426
460
    elsif (m/^--?root$/) { }
 
461
    elsif (m/^--?window-id$/) {
 
462
      my $id = shift @ARGV;
 
463
      error ("unparsable window id: $id")
 
464
        unless ($id =~ m/^\d+$|^0x[\da-f]+$/i);
 
465
      $displayer =~ s/--?root\b/$id/ ||
 
466
        error ("unable to munge displayer: $displayer");
 
467
    }
427
468
    elsif (m/^--?window$/) {
428
469
      print STDERR "$progname: sorry, \"-window\" is unimplemented.\n";
429
470
      print STDERR "$progname: use \"-stdout\" and pipe to a displayer.\n";
433
474
    else { usage; }
434
475
  }
435
476
 
 
477
  init_signals();
 
478
 
436
479
  read_config;
437
480
 
438
481
  if (!$use_stdout) {