#! /usr/local/bin/perl ## move.cgi v0.1a (MOVE IMAGE) 2001.04.22 by techan # Image File Folder $imgdir = './'; # Image1 to be moved $image1 = 'fs1'; # Image2 to be moved (The size (width and height) of Image2 # must be the same as that of Image1.) $image2 = 'fs2'; # Window Size (Width, Height) @w_h = (300, 68); # mime type for MNG in your server $mime = 'video/x-mng'; # Ticks per second $tps = 1000; # The number of repeats for reciprocating motion (integer >=1) $repeat = 50; # Moving Pitch (pixels) (integer >=1) $interval = 1; # Framing Mode (1 - 4) $fr_mode = 4; # Direction of reciprocating motion (horizontal: 0, vertical: 1) $direction = 0; ## Main if ($ARGV[0] =~ s/([\d]+)//) { $interval = $1; } if ($ARGV[0] eq 'horizontal') { $direction = 0; } elsif ($ARGV[0] eq 'vertical') { $direction = 1; } &InitCrcTable; $r = "NG\r\n\x1a\n"; $sig_p = "\x89P".$r; $sig_m = "\x8aM".$r; # $sig_j = "\x8bJ".$r; # Check File $file = $imgdir.$image1.'.png'; $size = -s $file; open(IN, "< $file") || &Error(1); binmode(IN); read(IN, $sig, 8); if ($sig ne $sig_p) { close(IN); &Error(2); } read(IN, $img1, $size-8); close(IN); $file = $imgdir.$image2.'.png'; $size = -s $file; open(IN, "< $file") || &Error(1); binmode(IN); read(IN, $sig, 8); if ($sig ne $sig_p) { close(IN); &Error(2); } read(IN, $img2, $size-8); close(IN); $interval = int($interval); if ($interval < 1) { $interval = 1; } if ($direction == 0) { $x_c = unpack("N", substr($img1, 8, 4)); $loop = int(($w_h[0] - $x_c) / $interval); $x_move = $interval; $y_move = 0; } else { $y_c = unpack("N", substr($img1, 12, 4)); $loop = int(($w_h[1] - $y_c) / $interval); $x_move = 0; $y_move = $interval; } $|=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 0, # Layers (unspecified) 0, # Frames (unspecified) 0, # Time (unspecified) 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 $img1; undef($img1); # DEFI2 $data = 'DEFI'.pack("nC", 2, # Object_id: 2 bytes 1); # Do_not_show: 1 byte &OutputData; print $img2; undef($img2); # FRAM1 $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 0, # Change_sync_id_list: 1 byte 1); # Interframe_delay: 4 byte &OutputData; # SHOW1 $data = 'SHOW'.pack("n", 1); &OutputData; # LOOP0 $data = 'LOOP'.pack("CN", 0, # Nest_level: 1 byte $repeat); # Iteration_count: 4 bytes &OutputData; # LOOP1 $data = 'LOOP'.pack("CN", 1, # Nest_level: 1 byte $loop); # Iteration_count: 4 bytes &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; # FRAM2 $data = 'FRAM'; &OutputData; # SHOW2 $data = 'SHOW'.pack("n", 1); &OutputData; # ENDL1 $data = "ENDL\x01"; &OutputData; # LOOP2 $data = 'LOOP'.pack("CN", 2, # Nest_level: 1 byte $loop); # Iteration_count: 4 bytes # Termination_condition: 1 byte &OutputData; # MOVE2 $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; # FRAM3 $data = 'FRAM'; &OutputData; # SHOW3 $data = 'SHOW'.pack("n", 2); &OutputData; # ENDL2 $data = "ENDL\x02"; &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__