summaryrefslogtreecommitdiffstats
path: root/Demo/sgi
diff options
context:
space:
mode:
authorcvs2svn <tools@python.org>2001-12-28 04:27:46 (GMT)
committercvs2svn <tools@python.org>2001-12-28 04:27:46 (GMT)
commit22768184cbbaa4bd6083c51c28183be7f4fc3d69 (patch)
tree38c0e4c1fcb64ef631a5737ca9bf469263e98be9 /Demo/sgi
parentbec5b362db9848e291219539a466b9e2c5fcbe25 (diff)
downloadcpython-22768184cbbaa4bd6083c51c28183be7f4fc3d69.zip
cpython-22768184cbbaa4bd6083c51c28183be7f4fc3d69.tar.gz
cpython-22768184cbbaa4bd6083c51c28183be7f4fc3d69.tar.bz2
This commit was manufactured by cvs2svn to create branch
'release22-maint'.
Diffstat (limited to 'Demo/sgi')
-rwxr-xr-xDemo/sgi/video/vcopy.py134
-rwxr-xr-xDemo/sgi/video/vinfo.py90
-rwxr-xr-xDemo/sgi/video/vtime.py106
3 files changed, 0 insertions, 330 deletions
diff --git a/Demo/sgi/video/vcopy.py b/Demo/sgi/video/vcopy.py
deleted file mode 100755
index d32bc1f..0000000
--- a/Demo/sgi/video/vcopy.py
+++ /dev/null
@@ -1,134 +0,0 @@
-# Copy a video file, interactively, frame-by-frame.
-
-import sys
-import getopt
-from gl import *
-from DEVICE import *
-import VFile
-import string
-import imageop
-
-def report(time, iframe):
- print 'Frame', iframe, ': t =', time
-
-def usage():
- sys.stderr.write('usage: vcopy [-t type] [-m treshold] [-a] infile outfile\n')
- sys.stderr.write('-t Convert to other type\n')
- sys.stderr.write('-a Automatic\n')
- sys.stderr.write('-m Convert grey to mono with treshold\n')
- sys.stderr.write('-d Convert grey to mono with dithering\n')
- sys.exit(2)
-
-def help():
- print 'Command summary:'
- print 'n get next image from input'
- print 'w write current image to output'
-
-def main():
- foreground()
- opts, args = getopt.getopt(sys.argv[1:], 't:am:d')
- if len(args) <> 2:
- usage()
- [ifile, ofile] = args
- print 'open film ', ifile
- ifilm = VFile.VinFile().init(ifile)
- print 'open output ', ofile
- ofilm = VFile.VoutFile().init(ofile)
-
- ofilm.setinfo(ifilm.getinfo())
-
- use_grabber = 0
- continuous = 0
- tomono = 0
- tomonodither = 0
- for o, a in opts:
- if o == '-t':
- ofilm.format = a
- use_grabber = 1
- if o == '-a':
- continuous = 1
- if o == '-m':
- if ifilm.format <> 'grey':
- print '-m only supported for greyscale'
- sys.exit(1)
- tomono = 1
- treshold = string.atoi(a)
- ofilm.format = 'mono'
- if o == '-d':
- if ifilm.format <> 'grey':
- print '-m only supported for greyscale'
- sys.exit(1)
- tomonodither = 1
- ofilm.format = 'mono'
-
- ofilm.writeheader()
- #
- prefsize(ifilm.width, ifilm.height)
- w = winopen(ifile)
- qdevice(KEYBD)
- qdevice(ESCKEY)
- qdevice(WINQUIT)
- qdevice(WINSHUT)
- print 'qdevice calls done'
- #
- help()
- #
- time, data, cdata = ifilm.getnextframe()
- ifilm.showframe(data, cdata)
- iframe = 1
- report(time, iframe)
- #
- while 1:
- if continuous:
- dev = KEYBD
- else:
- dev, val = qread()
- if dev in (ESCKEY, WINQUIT, WINSHUT):
- break
- if dev == REDRAW:
- reshapeviewport()
- elif dev == KEYBD:
- if continuous:
- c = '0'
- else:
- c = chr(val)
- #XXX Debug
- if c == 'R':
- c3i(255,0,0)
- clear()
- if c == 'G':
- c3i(0,255,0)
- clear()
- if c == 'B':
- c3i(0,0,255)
- clear()
- if c == 'w' or continuous:
- if use_grabber:
- data, cdata = ofilm.grabframe()
- if tomono:
- data = imageop.grey2mono(data, \
- ifilm.width, ifilm.height, \
- treshold)
- if tomonodither:
- data = imageop.dither2mono(data, \
- ifilm.width, ifilm.height)
- ofilm.writeframe(time, data, cdata)
- print 'Frame', iframe, 'written.'
- if c == 'n' or continuous:
- try:
- time,data,cdata = ifilm.getnextframe()
- ifilm.showframe(data, cdata)
- iframe = iframe+1
- report(time, iframe)
- except EOFError:
- print 'EOF'
- if continuous:
- break
- ringbell()
- elif dev == INPUTCHANGE:
- pass
- else:
- print '(dev, val) =', (dev, val)
- ofilm.close()
-
-main()
diff --git a/Demo/sgi/video/vinfo.py b/Demo/sgi/video/vinfo.py
deleted file mode 100755
index 7f98237..0000000
--- a/Demo/sgi/video/vinfo.py
+++ /dev/null
@@ -1,90 +0,0 @@
-from gl import *
-from GL import *
-from DEVICE import *
-import time
-import sys
-import getopt
-
-class Struct(): pass
-epoch = Struct()
-EndOfFile = 'End of file'
-bye = 'bye'
-
-def openvideo(filename):
- f = open(filename, 'r')
- line = f.readline()
- if not line: raise EndOfFile
- if line[:4] == 'CMIF': line = f.readline()
- x = eval(line[:-1])
- if len(x) == 3: w, h, pf = x
- else: w, h = x; pf = 2
- return f, w, h, pf
-
-def loadframe(f, w, h, pf):
- line = f.readline()
- if line == '':
- raise EndOfFile
- x = eval(line[:-1])
- if type(x) == type(0) or type(x) == type(0.0):
- tijd = x
- if pf == 0:
- size = w*h*4
- else:
- size = (w/pf) * (h/pf)
- else:
- tijd, size = x
- f.seek(size, 1)
- return tijd
-
-def main():
- delta = 0
- short = 0
- try:
- opts, names = getopt.getopt(sys.argv[1:], 'ds')
- except getopt.error, msg:
- sys.stderr.write(msg + '\n')
- sys.stderr.write('usage: vinfo [-d] [-s] [file] ...\n')
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-d': delta = 1 # print delta between frames
- elif opt == '-s': short = 1 # short: don't print times
- if names == []:
- names = ['film.video']
- for name in names:
- try:
- f, w, h, pf = openvideo(name)
- except:
- sys.stderr.write(name + ': cannot open\n')
- continue
- if pf == 0:
- size = w*h*4
- else:
- size = (w/pf) * (h/pf)
- print name, ':', w, 'x', h, '; pf =', pf, ', size =', size,
- if pf == 0:
- print '(color)',
- else:
- print '(' + `(w/pf)` + 'x' + `(h/pf)` + ')',
- if (w/pf)%4 <> 0: print '!!!',
- print
- num = 0
- try:
- otijd = 0
- while not short:
- try:
- tijd = loadframe(f, w, h, pf)
- if delta: print '\t' + `tijd-otijd`,
- else: print '\t' + `tijd`,
- otijd = tijd
- num = num + 1
- if num % 8 == 0:
- print
- except EndOfFile:
- raise bye
- except bye:
- pass
- if num % 8 <> 0:
- print
- f.close()
-
-main()
diff --git a/Demo/sgi/video/vtime.py b/Demo/sgi/video/vtime.py
deleted file mode 100755
index c333e57..0000000
--- a/Demo/sgi/video/vtime.py
+++ /dev/null
@@ -1,106 +0,0 @@
-#
-# Module vtime - Keep virtual time between two nodes.
-#
-# We try for synchronised clocks by sending a packet of the for
-# (1,mytime,0) to the other side, and waiting (at most) a second for
-# a reply. This reply has the form (2,mytime,histime), and we can
-# estimate the time difference by defining histime to be exactly half-way
-# between the time we sent our message and got our reply. We send a
-# final (3,mynewtime,histime) message to allow the other side to do the
-# same computations.
-#
-# Note that the protocol suffers heavily from the 2-army problem.
-# It'll have to do until I can read up on time-sync protocols, though.
-#
-from socket import *
-import time
-
-MSGSIZE = 100
-MSGTIMEOUT = 1000
-
-recv_timeout = 'receive timeout'
-bad_connect = 'Bad connection'
-
-def timeavg(a,b):
- return int((long(a)+b)/2L)
-def tryrecv(s):
- cnt = 0
- while 1:
- if s.avail():
- return s.recvfrom(MSGSIZE)
- time.millisleep(100)
- cnt = cnt + 100
- if cnt > MSGTIMEOUT:
- raise recv_timeout
-
-class VTime():
- def init(self,(client,host,port)):
- s = socket(AF_INET, SOCK_DGRAM)
- host = gethostbyname(host)
- localhost = gethostbyname(gethostname())
- raddr = (host,port)
- s.bind((localhost,port))
- if client:
- #
- # We loop here because we want the *second* measurement
- # for accuracy
- for loopct in (0,2):
- curtijd = time.millitimer()
- check = `(loopct,curtijd,0)`
- s.sendto(check,raddr)
- while 1:
- try:
- if loopct:
- data, other = s.recvfrom(MSGSIZE)
- else:
- data, other = tryrecv(s)
- newtijd = time.millitimer()
- if other <> raddr:
- print 'Someone else syncing to us: ', other
- raise bad_connect
- data = eval(data)
- if data[:2] == (loopct+1,curtijd):
- break
- if data[0] <> 2:
- print 'Illegal sync reply: ', data
- raise bad_connect
- except recv_timeout:
- curtijd = time.millitimer()
- check = `(loopct,curtijd,0)`
- s.sendto(check,raddr)
- histime = data[2]
- s.sendto(`(4,newtijd,histime)`,raddr)
- mytime = timeavg(curtijd,newtijd)
- #mytime = curtijd
- self.timediff = histime - mytime
- else:
- while 1:
- data,other = s.recvfrom(MSGSIZE)
- if other <> raddr:
- print 'Someone else syncing to us: ', other, ' Wanted ', raddr
- raise bad_connect
- data = eval(data)
- if data[0] in (0,2):
- curtijd = time.millitimer()
- s.sendto(`(data[0]+1,data[1],curtijd)`,raddr)
- elif data[0] == 4:
- newtijd = time.millitimer()
- histime = data[1]
- mytime = timeavg(curtijd,newtijd)
- #mytime = curtijd
- self.timediff = histime-mytime
- break
- else:
- print 'Funny data: ', data
- raise bad_connect
- return self
- #
- def his2mine(self,tijd):
- return tijd - self.timediff
- #
- def mine2his(self, tijd):
- return tijd + self.timediff
-
-def test(clt, host, port):
- xx = VTime().init(clt,host,port)
- print 'Time diff: ', xx.his2mine(0)