#!/usr/local/bin/perl

# Written by Ch. Tronche (http://tronche.com/)
# Copyright by the author. This is unmaintained, no-warranty free software. 
# Please use freely. It is appreciated (but by no means mandatory) to
# acknowledge the author's contribution. Thank you.
# Started on Sun Mar  9 17:11:07 1997

use strict 'refs';
use strict 'subs';
use integer;

$_ = $ENV{'QUERY_STRING'};
$zoom = /\bzoom=([128])\b/o ? $1 : 4;
$resolution = /\bresolution=([128])\b/o ? $1 : 4;
$sound = /\bsound=([01])\b/o ? $1 : 0;

$effectiveResolution = $resolution < $zoom ? $zoom : $resolution;

$width = 768 / $zoom;
$height = 576 / $zoom;
$higheres = $effectiveResolution / 2;
$loweres  = $effectiveResolution * 2;
$higherzoom = $zoom / 2;
$lowerzoom = $zoom * 2;

$clock = $effectiveResolution > 8 ? '&clock' : '';

print <<END;
Content-Type: text/html

<HTML>
<HEAD>
<TITLE>Christophe Tronche's office live</TITLE>
</HEAD>

<BODY>

<H1 ALIGN=center>Christophe Tronche's office live</H1>

<TABLE WIDTH="100%">
<TR>
<TH VALIGN=top>
END

    if ($lowerzoom <= 8) {
	print "<A HREF=\"live.cgi?zoom=$lowerzoom&resolution=$resolution&sound=$sound\">",
	"<IMG SRC=\"/images/left.gif\" WIDTH=31 HEIGHT=31 BORDER=0> Zoom ",
	"<FONT SIZE=-1>down</FONT></A>\n";
    }

print <<END;
<TH ROWSPAN=2><A HREF="live-naked.cgi?zoom=$zoom&resolution=$effectiveResolution"><IMG SRC="http://tronche.lri.fr:8002/$effectiveResolution$clock" WIDTH=$width HEIGHT=$height BORDER=5></A>
<TH VALIGN=top>
END
    if ($higherzoom) {
	print "<A HREF=\"live.cgi?zoom=$higherzoom&resolution=$resolution&sound=$sound\">",
	"Zoom <FONT SIZE=+1>UP</FONT> <IMG SRC=\"/images/right.gif\" WIDTH=31 HEIGHT=31 BORDER=0></A>\n";
    }

    print "<TR>\n<TH VALIGN=bottom>";
   
    if ($loweres <= 8) {
	print "<A HREF=\"live.cgi?zoom=$zoom&resolution=$loweres&sound=$sound\"><IMG SRC=\"/images/left.gif\" WIDTH=31 HEIGHT=31 BORDER=0> Lower res</A>\n";
    }

    print "<TH VALIGN=bottom>";

    if ($effectiveResolution > $zoom) {
	print "<A HREF=\"live.cgi?zoom=$zoom&resolution=$higheres&sound=$sound\">Higher res <IMG SRC=\"/images/right.gif\" WIDTH=31 HEIGHT=31 BORDER=0></A>\n";
    }

    print "</TABLE>\n";

################################################################################

     $irix = $ENV{'HTTP_USER_AGENT'} =~ /\bIRIX\b/o;

     if ($sound) {
	 print "\n<EMBED SRC=\"http://tronche.lri.fr:8001/8000\"";
	 print ' PLUGINSPAGE="/internet/plugins/sgi-audio-basic/"' if ($irix);
	 print ">\n";
     }

     if ($irix) {
	 if ($sound) {
	     $nextSound = 0;
	     $nextSoundText = 'off';
	 } else {
	     $nextSound = 1;
	     $nextSoundText = 'on';
	 }
	 print <<END

<P>
<A HREF="live.cgi?zoom=$zoom&resolution=$resolution&sound=$nextSound"><H3 ALIGN=center>Turn SOUND $nextSoundText</H3></A>
<P>
END
     }
    
################################################################################

    print <<END;
<P>
You're now seeing my office live, provided that your browser can handle animated 
<A HREF="/web-directory/science-and-technology/computer/graphics/gif.html">GIF</A>
(such as <A HREF="http://home.netscape.com/">Netscape</A>).

<P>

The frame rate depends on the speed on your path.
END

    print <<END if $effectiveResolution == $zoom;

<P>

You may get a better quality by clicking on the image. 
The reason is that Netscape needs some colors to render the arrows, but will use
the full color palette if only the picture is present.

<P>

<I><!A HREF="/mediaspace/real-time-movies/">More real-time pictures<!/A></I>

END

    print <<END;
<HR>
<ADDRESS>
<A HREF="http://tronche.com/">Christophe Tronche</A>, <A HREF="mailto:ch@tronche.com">ch@tronche.com</A>
</ADDRESS>
</BODY>
</HTML>

END
