3 # vidwhacker, for xscreensaver. Copyright (c) 1998 Jamie Zawinski.
5 # This script grabs a frame of video, then uses various pbm filters to
6 # munge the image in random nefarious ways, then uses xv to put it on
7 # the root window. This works out really nicely if you just feed some
8 # random TV station into it...
10 # The video grabbing part is SGI-specific -- if you want to use this on
11 # another system, add a new clause to the grab() procedure.
14 # Process command-line args...
20 if [ "$1" = "-root" ]; then
25 if [ "$1" = "-verbose" ]; then
30 if [ "$1" != "" ]; then
31 echo "usage: $0 [-root] [-verbose]" >&2
38 if [ "$onroot" = true ]; then
39 xvargs="$xvargs -root -rmode 5 -quit"
41 xvargs="$xvargs -geom +0+0"
44 screen_width=`xdpyinfo | sed -n 's/.* dimensions: *\([0-9]*\).*/\1/p'`
49 tmp_rgb=$tmp-00000.rgb
55 rm -f $tmp_rgb $tmp_ppm $tmp_ppm2 $tmp_ppm3
59 # Grab a frame of video.
62 if [ `uname` = IRIX ]; then
64 # SGI's "vidtomem" returns an SGI RGB image of the default video input,
65 # and has stupid non-overridable ouput-file-naming conventions. So, let
66 # it write its file; and then convert it to a pgm.
69 sgitopnm $tmp_rgb > $tmp_ppm
70 # Cut off the close-captioning blips in the NTSC overscan region. YMMV.
71 # | pnmcut 12 7 695 477
74 echo "$0: don't know how to grab video on this OS." >&2
80 # I got this message from Marcus Herbert <rhoenie@chillout.org>.
81 # I'm not sure of the best way to make the presence of qcam be
82 # auto-detected, but here's what he said, FYI...
84 # i am using a black/white Connectix Qcam on linux and its very simple
85 # to adept the script:
87 # # qcam: Version 0.91
89 # # O -x width Set width
90 # # O y height Setheight
91 # # O B bpp Setbits per pixel
92 # # O W Auto-set white balance
93 # # O E "vals" Autoexposure mode, parameters required
94 # # O D Remove dark speckling
95 # # O s val Set scaling factor (1, 2, or 4)
97 # qcam -x 320 -y 240 -B 6 -W -E 1 -D -s 1 > $tmp_ppm
99 # You dont really need the parameters for qcam as it reads out a system
100 # config file where you store the values for brightnes, contrast and
101 # white balance. But with this parameters you are independant of the
102 # light ratios at the place the cam is set up.
104 # Other versions of qcam (0.7, 0.96..) don't support the autoexposure and
105 # auto- whitebalance commandline parameters. On such systems (and on
106 # color-qcam systems) a simple qcam > $tmp_ppm (or cqcam > $tmp_ppm) is
109 # I dont know about other systems but afaik fBSD uses the Qcam in this way:
111 # qcamcontrol -bla -foo -bar > picture.pgm
116 # Use perl to pick a random foreground/background color in pbm's syntax.
120 printf("#%02x%02x%02x-#%02x%02x%02x",
126 120+int(rand()*135))'
129 # Frobnicate the image in some random way.
133 N=`perl -e 'srand; print int(rand() * 10)'`
135 if [ "$verbose" = true ]; then
136 echo "mode $N..." >&2
140 ppmtopgm $tmp_ppm | pgmedge | pgmtoppm `randcolor` | ppmnorm
142 elif [ $N = 1 ]; then
147 elif [ $N = 2 ]; then
148 ppmtopgm $tmp_ppm | pgmoil | pgmtoppm `randcolor`
150 elif [ $N = 3 ]; then
151 ppmrelief $tmp_ppm | ppmtopgm | pgmedge | ppmrelief | ppmtopgm |
152 pgmedge | pnminvert | pgmtoppm `randcolor`
154 elif [ $N = 4 ]; then
155 ppmspread 71 $tmp_ppm > $tmp_ppm2
156 pnmarith -add $tmp_ppm $tmp_ppm2
158 elif [ $N = 5 ]; then
159 pnmflip -lr $tmp_ppm > $tmp_ppm2
160 pnmarith -multiply $tmp_ppm $tmp_ppm2 > $tmp_ppm3
161 pnmflip -tb $tmp_ppm3 | ppmnorm > $tmp_ppm2
162 pnmarith -multiply $tmp_ppm $tmp_ppm2
164 elif [ $N = 6 ]; then
165 N2=`perl -e 'srand; print int(rand() * 3)'`
167 pnmflip -lr $tmp_ppm > $tmp_ppm2
168 elif [ $N2 = 1 ]; then
169 pnmflip -tb $tmp_ppm > $tmp_ppm2
171 pnmflip -lr $tmp_ppm > $tmp_ppm2
172 pnmflip -tb $tmp_ppm2 > $tmp_ppm3
173 cp $tmp_ppm3 $tmp_ppm2
176 pnmarith -difference $tmp_ppm $tmp_ppm2
178 elif [ $N = 7 ]; then
181 ppmtopgm $tmp_ppm | pgmedge > $tmp_ppm2
182 pnmarith -difference $tmp_ppm $tmp_ppm2 > $tmp_ppm3
183 cp $tmp_ppm3 $tmp_ppm
187 elif [ $N = 8 ]; then
188 pnmflip -lr $tmp_ppm > $tmp_ppm2
189 pnmarith -multiply $tmp_ppm $tmp_ppm2 | ppmrelief | ppmnorm | pnminvert
191 elif [ $N = 9 ]; then
192 pnmflip -lr $tmp_ppm > $tmp_ppm2
193 pnmarith -subtract $tmp_ppm $tmp_ppm2 | ppmrelief | ppmtopgm | pgmedge
201 # Grab a frame and frob it. leave it in $tmp_ppm3.
206 while [ ! -f $tmp_ppm ]; do
211 frob | pnmscale -width $screen_width > $tmp_ppm3
212 rm -f $tmp_ppm $tmp_ppm2
218 if [ "$onroot" != true ]; then
219 trap "kill \$pid; clean; exit 1" 2 15
224 # Loop grabbing and frobbing images.
226 # If we're running on the root, run xv in the foreground (with -exit)
229 # If we're running in a window, spawn xv in the background; then when
230 # it's time to put up the new image, kill off the currently-running xv.
232 if [ "$verbose" = true ]; then
238 if [ "$pid" != "" ]; then
243 if [ ! -s $tmp_ppm3 ]; then
244 echo "$0: no image grabbed" >&2
247 pnmtosgi < $tmp_ppm3 > $tmp_ppm2
250 if [ "$onroot" = true ]; then
253 xv $xvargs $tmp_ppm2 &
257 #xv -geom =320x220 $tmp_ppm3 &