#! /usr/local/bin/perl ## scroll.cgi v0.6 (SCROLL IMAGE) 2001.04.21 by techan # Image File Folder $imgdir = './'; # Base Name of Images to be scrolled # (eg. If $image = 'news', filenames are 'news1.png', 'news2.png'...) $image = 'news'; # Do you want to display image at random ? (yes: 1, no: 0) $random = 1; # Number of Images to be scrolled (Integer >= 1) # (If $random = 1 and $number > 1, file is selected at random # within the range of not larger than $number. Otherwise, file # identified by $number is selected.) $number = 2; # Window Size (Width, Height) @w_h = (100, 32); # mime for MNG in your server $mime = 'video/x-mng'; # Ticks per second $tps = 1000; # The number of repeats for scrolling (integer >=1) $repeat = 2; # Image Scrolling Direction (left: 0, right: 1, up: 2, down: 3) $direction = 0; # Scrolling Interval (integer >=1) $interval = 1; # Framing Mode (1 - 4) # If transparent image is used, framing_mode should be 4 (or 3). $fr_mode = 4; ## Main if ($ARGV[0] =~ s/^n([\d]+)//) { $number = $1; $random = 0; } if ($ARGV[0] =~ s/([\d]+)//) { $interval = $1; } if ($ARGV[0] eq 'left') { $direction = 0; } elsif ($ARGV[0] eq 'right') { $direction = 1; } elsif ($ARGV[0] eq 'up') { $direction = 2; } elsif ($ARGV[0] eq 'down') { $direction = 3; } &InitCrcTable; $r = "NG\r\n\x1a\n"; $sig_p = "\x89P".$r; $sig_m = "\x8aM".$r; $sig_j = "\x8bJ".$r; if ($number > 1 && $random) { srand; $number = int(rand($number)) + 1; } # Check File $file = $imgdir.$image.$number.'.png'; if (-f $file) { $sig_r = $sig_p; } else { $file = $imgdir.$image.$number.'.jng'; if (-f $file) { $sig_r = $sig_j; } else { &Error(3); } } $size = -s $file; open(IN, "< $file") || &Error(1); binmode(IN); read(IN, $sig, 8); if ($sig ne $sig_r) { close(IN); &Error(2); } read(IN, $img, $size-8); close(IN); $interval = int($interval); if ($interval < 1) { $interval = 1; } if ($direction == 1) { $x_c = unpack("N", substr($img, 8, 4)); $y_c = 0; $loop = int($x_c / $interval); $x_c = - $x_c; $x_move = $interval; $y_move = 0; } elsif ($direction == 2) { $x_c = 0; $y_c = unpack("N", substr($img, 12, 4)); $loop = int($y_c / $interval); $x_move = 0; $y_move = - $interval; } elsif ($direction == 3) { $x_c = 0; $y_c = unpack("N", substr($img, 12, 4)); $loop = int($y_c / $interval); $y_c = - $y_c; $x_move = 0; $y_move = $interval; } else { $x_c = unpack("N", substr($img, 8, 4)); $y_c = 0; $loop = int($x_c / $interval); $x_move = - $interval; $y_move = 0; } if ($loop) { $loop -=1; } $x_back = - $x_move * $loop; $y_back = - $y_move * $loop; $ti = $loop * $repeat + $repeat + 1; $layers = $ti * 2 + 1; $|=1; print "Content-type: $mime\n\n"; binmode(STDOUT); # Signature print $sig_m; # MHDR $data = 'MHDR'.pack("N7", $w_h[0], # Width $w_h[1], # Height $tps, # Ticks per second $layers, # Layers $ti, # Frames $ti, # Time 767); # Simplicity &OutputData; # BACK $data = 'BACK'.pack("n3", 50000, # Red_background: 2 bytes 50000, # Green_background: 2 bytes 50000); # Blue_background: 2 bytes &OutputData; # DEFI1 $data = 'DEFI'.pack("nC", 1, # Object_id: 2 bytes 1); # Do_not_show: 1 byte &OutputData; print $img; undef($img); # CLON $data = 'CLON'.pack("n2C4N2", 1, # Source_id 2, # Clone_id 1, # Clone_type 1, # Do_not_show 0, # Concrete_flag 1, # Loca_delta_type $x_c, # X_location or delta_X_location (signed integer) $y_c); # Y_location or delta_Y_location (signed integer) &OutputData; # FRAM $data = 'FRAM'.pack("C6N", $fr_mode, # Framing_mode: 1 byte 0, # Null_Separator: 1 byte 1, # Change_interframe_delay: 1 byte 0, # Change_timeout_and_termination: 1 byte 0, # Change_layer_clipping_boundaries: 1 byte (No.) 0, # Change_sync_id_list: 1 byte 1); # Interframe_delay: 4 byte &OutputData; # SHOW $data = 'SHOW'.pack("n", 1); &OutputData; # LOOP0 $data = 'LOOP'.pack("CN", 0, # Nest_level: 1 byte $repeat); # Iteration_count: 4 bytes # Termination_condition: 1 byte &OutputData; # LOOP1 $data = 'LOOP'.pack("CN", 1, # Nest_level: 1 byte $loop); # Iteration_count: 4 bytes # Termination_condition: 1 byte &OutputData; # MOVE1 $data = 'MOVE'.pack("nnCNN", 1, # First_object: 2 bytes 2, # Last_object: 2 bytes 1, # Location_delta_type: 1 byte $x_move, # X_location or delta_X_location: 4 bytes (signed integer) $y_move); # Y_location or delta_Y_location: 4 bytes (signed integer) &OutputData; # FRAM $data = 'FRAM'; &OutputData; # SHOW $data = 'SHOW'.pack("nn", 1, 2); &OutputData; # ENDL1 $data = "ENDL\x01"; &OutputData; # MOVE2 $data = 'MOVE'.pack("nnCNN", 1, # First_object: 2 bytes 2, # Last_object: 2 bytes 1, # Location_delta_type: 1 byte $x_back, # X_location or delta_X_location: 4 bytes (signed integer) $y_back); # Y_location or delta_Y_location: 4 bytes (signed integer) &OutputData; # FRAM $data = 'FRAM'; &OutputData; # SHOW $data = 'SHOW'.pack("n", 1); &OutputData; # ENDL0 $data = "ENDL\0"; &OutputData; # MEND print "\0\0\0\0MEND! \xf7\xd5"; exit(0); sub Error { my $e = $_[0]; $black = "\0\0\0"; $red = "\xff\0\0"; $white = "\xff\xff\xff"; if ($e == 1) { $plte = $white.$black; } elsif ($e == 2) { $plte = $white.$red; } else { $plte = $red.$white; } $plte = "PLTE".$plte; $p = $sig_p; $p.="\0\0\0\rIHDR"; $p.="\0\0\0\x1e\0\0\0\x0c\x01\x03\0\0\0"; $p.="\x4f\xe0\x9f\x71"; $p.="\0\0\0\x06".$plte.&CalcCrc($plte); $p.="\0\0\0\x2eIDAT"; $p.="\x78\x9c\x63\x60\x40\x05\xbf\xcf\xcb\x7c\x60\x68\xd2\x58\xd4\x01"; $p.="\x21\x3e\x81\x88\xe6\xf3\x4a\x40\xb1\x2e\xa5\x05\x0c\x4d\x9e\x4a"; $p.="\x13\x18\x7e\x69\xcc\xe9\0\xab\x05\0\xb0\x88\x10\xb8"; $p.="\x57\x3a\0\xa1"; $p.="\0\0\0\0IEND\xaeB`\x82"; $|=1; print "Content-type: $mime\n"; print "Content-length: 121\n\n"; binmode(STDOUT); print $p; exit(1); } sub InitCrcTable { my $d; @crc_table = (); for (0 .. 255) { $d = $_; for (0 .. 7) { if ($d & 1) { $d = 0xedb88320 ^ (($d >> 1) & 0x7fffffff); } else { $d = ($d >> 1) & 0x7fffffff; } } $crc_table[$_] = $d; } } sub CalcCrc { my $data = $_[0]; my $c = 0xffffffff; foreach (unpack("C*", $data)) { $c = $crc_table[($c ^ $_) & 0xff] ^ (($c >> 8) & 0xffffff); } return(pack("N", ~$c)); } sub OutputData { print pack("N", length($data)-4).$data.&CalcCrc($data); undef($data); } __END__