summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xDemo/pdist/new1
-rwxr-xr-xDemo/sgi/video/IN.py54
-rwxr-xr-xDemo/sgi/video/Makefile7
-rwxr-xr-xDemo/sgi/video/Vrecc.py281
-rwxr-xr-xDemo/sgi/video/cam.py129
-rwxr-xr-xDemo/sgi/video/camcorder.py266
-rwxr-xr-xDemo/sgi/video/colorsys.py106
-rwxr-xr-xDemo/sgi/video/i2v.c80
-rwxr-xr-xDemo/sgi/video/makemovie.py218
-rwxr-xr-xDemo/sgi/video/squash.c130
-rwxr-xr-xDemo/sgi/video/squash2.c72
-rwxr-xr-xDemo/sgi/video/statit.py115
-rwxr-xr-xDemo/sgi/video/syncaudio.py94
-rwxr-xr-xDemo/sgi/video/tomono.c165
-rwxr-xr-xDemo/sgi/video/tv.py79
-rwxr-xr-xDemo/sgi/video/v2i.c79
-rwxr-xr-xDemo/sgi/video/video.py218
-rwxr-xr-xDemo/sgi/video/vpregs.py28
-rwxr-xr-xLib/builtin.py3
-rwxr-xr-xLib/macstat.py83
-rwxr-xr-xLib/persist.py297
-rw-r--r--Python/pythonmain.c211
22 files changed, 0 insertions, 2716 deletions
diff --git a/Demo/pdist/new b/Demo/pdist/new
deleted file mode 100755
index 9daeafb..0000000
--- a/Demo/pdist/new
+++ /dev/null
@@ -1 +0,0 @@
-test
diff --git a/Demo/sgi/video/IN.py b/Demo/sgi/video/IN.py
deleted file mode 100755
index ffc2852..0000000
--- a/Demo/sgi/video/IN.py
+++ /dev/null
@@ -1,54 +0,0 @@
-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_TCP = 6
-IPPROTO_EGP = 8
-IPPROTO_PUP = 12
-IPPROTO_UDP = 17
-IPPROTO_IDP = 22
-IPPROTO_TP = 29
-IPPROTO_XTP = 36
-IPPROTO_EON = 80
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-INADDR_ANY = 0x00000000
-INADDR_BROADCAST = 0xffffffff
-INADDR_LOOPBACK = 0x7F000001
-INADDR_UNSPEC_GROUP = 0xe0000000
-INADDR_ALLHOSTS_GROUP = 0xe0000001
-INADDR_MAX_LOCAL_GROUP = 0xe00000ff
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 7
-IP_TOS = 8
-IP_TTL = 9
-IP_RECVOPTS = 10
-IP_RECVRETOPTS = 11
-IP_RECVDSTADDR = 12
-IP_RETOPTS = 13
-IP_MULTICAST_IF = 2
-IP_MULTICAST_TTL = 3
-IP_MULTICAST_LOOP = 4
-IP_ADD_MEMBERSHIP = 5
-IP_DROP_MEMBERSHIP = 6
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
diff --git a/Demo/sgi/video/Makefile b/Demo/sgi/video/Makefile
deleted file mode 100755
index 266ea52..0000000
--- a/Demo/sgi/video/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-all: v2i i2v
-
-v2i: v2i.o
- $(CC) v2i.o -limage -o v2i
-
-i2v: i2v.o
- $(CC) i2v.o -limage -o i2v
diff --git a/Demo/sgi/video/Vrecc.py b/Demo/sgi/video/Vrecc.py
deleted file mode 100755
index 6a539f8..0000000
--- a/Demo/sgi/video/Vrecc.py
+++ /dev/null
@@ -1,281 +0,0 @@
-#! /ufs/guido/bin/sgi/python-405
-#! /ufs/guido/bin/sgi/python
-
-# Capture a continuous CMIF movie using the Indigo video library and board
-
-
-# Usage:
-#
-# makemovie [-r rate] [-w width] [moviefile]
-
-
-# Options:
-#
-# -r rate : capture 1 out of every 'rate' frames (default 1)
-# -w width : initial window width (default interactive placement)
-# -d : drop fields if needed
-# -g bits : greyscale (2, 4 or 8 bits)
-# -G : 2-bit greyscale dithered
-# -m : monochrome dithered
-# -M value : monochrome tresholded with value
-# -f : Capture fields (in stead of frames)
-# -n number : Capture 'number' fields (default 60)
-#
-# moviefile : here goes the movie data (default film.video);
-# the format is documented in cmif-film.ms
-
-
-# User interface:
-#
-# Start the application. Resize the window to the desired movie size.
-# Press the left mouse button to start recording, release it to end
-# recording. You can record as many times as you wish, but each time
-# you overwrite the output file(s), so only the last recording is
-# kept.
-#
-# Press ESC or select the window manager Quit or Close window option
-# to quit. If you quit before recording anything, the output file(s)
-# are not touched.
-
-
-import sys
-sys.path.append('/ufs/guido/src/video')
-import sv, SV
-import VFile
-import gl, GL, DEVICE
-import al, AL
-import time
-import posix
-import getopt
-import string
-import imageop
-import sgi
-
-# Main program
-
-def main():
- format = SV.RGB8_FRAMES
- rate = 1
- width = 0
- drop = 0
- mono = 0
- grey = 0
- greybits = 0
- monotreshold = -1
- fields = 0
- number = 60
-
- opts, args = getopt.getopt(sys.argv[1:], 'r:w:dg:mM:Gfn:')
- for opt, arg in opts:
- if opt == '-r':
- rate = string.atoi(arg)
- if rate < 2:
- sys.stderr.write('-r rate must be >= 2\n')
- sys.exit(2)
- elif opt == '-w':
- width = string.atoi(arg)
- elif opt == '-d':
- drop = 1
- elif opt == '-g':
- grey = 1
- greybits = string.atoi(arg)
- if not greybits in (2,4,8):
- print 'Only 2, 4 or 8 bit greyscale supported'
- elif opt == '-G':
- grey = 1
- greybits = -2
- elif opt == '-m':
- mono = 1
- elif opt == '-M':
- mono = 1
- monotreshold = string.atoi(arg)
- elif opt == '-f':
- fields = 1
- elif opt == '-n':
- number = string.atoi(arg)
-
- if args[2:]:
- sys.stderr.write('usage: Vrec [options] [file]\n')
- sys.exit(2)
-
- if args:
- filename = args[0]
- else:
- filename = 'film.video'
-
- v = sv.OpenVideo()
- # Determine maximum window size based on signal standard
- param = [SV.BROADCAST, 0]
- v.GetParam(param)
- if param[1] == SV.PAL:
- x = SV.PAL_XMAX
- y = SV.PAL_YMAX
- elif param[1] == SV.NTSC:
- x = SV.NTSC_XMAX
- y = SV.NTSC_YMAX
- else:
- print 'Unknown video standard', param[1]
- sys.exit(1)
-
- gl.foreground()
- gl.maxsize(x, y)
- gl.keepaspect(x, y)
- gl.stepunit(8, 6)
- if width:
- gl.prefsize(width, width*3/4)
- win = gl.winopen(filename)
- if width:
- gl.maxsize(x, y)
- gl.keepaspect(x, y)
- gl.stepunit(8, 6)
- gl.winconstraints()
- x, y = gl.getsize()
- print x, 'x', y
-
- v.SetSize(x, y)
-
- if drop:
- param = [SV.FIELDDROP, 1, SV.GENLOCK, SV.GENLOCK_OFF]
- else:
- param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
- if mono or grey:
- param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1]
- else:
- param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0]
- v.SetParam(param)
-
- v.BindGLWindow(win, SV.IN_REPLACE)
-
- gl.qdevice(DEVICE.LEFTMOUSE)
- gl.qdevice(DEVICE.WINQUIT)
- gl.qdevice(DEVICE.WINSHUT)
- gl.qdevice(DEVICE.ESCKEY)
-
- print 'Press left mouse to start recording'
-
- while 1:
- dev, val = gl.qread()
- if dev == DEVICE.LEFTMOUSE:
- if val == 1:
- info = format, x, y, number, rate
- record(v, info, filename, mono, grey, \
- greybits, monotreshold, fields)
- elif dev == DEVICE.REDRAW:
- # Window resize (or move)
- x, y = gl.getsize()
- print x, 'x', y
- v.SetSize(x, y)
- v.BindGLWindow(win, SV.IN_REPLACE)
- elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
- # Quit
- v.CloseVideo()
- gl.winclose(win)
- break
-
-
-# Record until the mouse is released (or any other GL event)
-# XXX audio not yet supported
-
-def record(v, info, filename, mono, grey, greybits, monotreshold, fields):
- import thread
- format, x, y, number, rate = info
- fps = 59.64 # Fields per second
- # XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
- tpf = 1000.0 / fps # Time per field in msec
- #
- # Go grab
- #
- gl.wintitle('(rec) ' + filename)
- try:
- ninfo, data, bitvec = v.CaptureBurst(info)
- except sv.error, arg:
- print 'CaptureBurst failed:', arg
- print 'info:', info
- gl.wintitle(filename)
- return
- gl.wintitle('(save) '+ filename)
- #
- # Check results
- #
- if info <> ninfo:
- print 'Sorry, format changed.'
- print 'Wanted:',info
- print 'Got :',ninfo
- gl.wintitle(filename)
- return
- # print bitvec
- if x*y*number <> len(data):
- print 'Funny data length: wanted',x,'*',y,'*', number,'=',\
- x*y*number,'got',len(data)
- gl.wintitle(filename)
- return
- #
- # Save
- #
- if filename:
- #
- # Construct header and write it
- #
- vout = VFile.VoutFile().init(filename)
- if mono:
- vout.format = 'mono'
- elif grey and greybits == 8:
- vout.format = 'grey'
- elif grey:
- vout.format = 'grey'+`abs(greybits)`
- else:
- vout.format = 'rgb8'
- vout.width = x
- vout.height = y
- if fields:
- vout.packfactor = (1,-2)
- else:
- print 'Sorry, can only save fields at the moment'
- gl.wintitle(filename)
- return
- vout.writeheader()
- #
- # Compute convertor, if needed
- #
- convertor = None
- if grey:
- if greybits == 2:
- convertor = imageop.grey2grey2
- elif greybits == 4:
- convertor = imageop.grey2grey4
- elif greybits == -2:
- convertor = imageop.dither2grey2
- fieldsize = x*y/2
- nskipped = 0
- realframeno = 0
- tpf = 1000 / 50.0 #XXXX
- for frameno in range(0, number*2):
- if frameno <> 0 and \
- bitvec[frameno] == bitvec[frameno-1]:
- nskipped = nskipped + 1
- continue
- #
- # Save field.
- # XXXX Works only for fields and top-to-bottom
- #
- start = frameno*fieldsize
- field = data[start:start+fieldsize]
- if convertor:
- field = convertor(field, x, y)
- elif mono and monotreshold >= 0:
- field = imageop.grey2mono(field, x, y, \
- 1, monotreshold)
- elif mono:
- field = imageop.dither2mono(field, x, y)
- vout.writeframe(int(realframeno*tpf), field, None)
- print 'Skipped',nskipped,'duplicate frames'
- vout.close()
-
- gl.wintitle('(done) ' + filename)
-
-# Don't forget to call the main program
-
-try:
- main()
-except KeyboardInterrupt:
- print '[Interrupt]'
diff --git a/Demo/sgi/video/cam.py b/Demo/sgi/video/cam.py
deleted file mode 100755
index fa8966f..0000000
--- a/Demo/sgi/video/cam.py
+++ /dev/null
@@ -1,129 +0,0 @@
-import sys
-from socket import *
-from gl import *
-from GL import *
-from DEVICE import *
-from time import millitimer
-
-HS = 40 # Header size (must be same as in tv.py)
-
-# Rely on UDP packet (de)fragmentation for smoother images
-# (Changed for broadcast)
-MAX = 16000
-
-PF = 2 # Default packfactor
-
-# Default receiver station is voorn.
-# Kwik has no yellow pages, so...
-HOST = '192.16.201.121'
-PORT = 5555
-
-if sys.argv[1:]:
- PF = eval(sys.argv[1])
-
-if sys.argv[2:]:
- HOST = sys.argv[2]
- if HOST == 'all':
- HOST = '<broadcast>'
- MAX = 1400
-
-PF2 = PF*PF
-
-def main():
- centerx, centery = 400, 300
-
- foreground()
- wid = winopen('cam')
- RGBmode()
- doublebuffer()
- gconfig()
- qdevice(ESCKEY)
-
- w, h = getsize()
- ortho2(0, w, 0, h)
- w = w/PF*PF
- h = h/PF*PF
-
- readsource(SRC_FRAMEGRABBER)
-
- s = socket(AF_INET, SOCK_DGRAM)
- if HOST == '<broadcast>':
- s.allowbroadcast(1)
- addr = HOST, PORT
-
- bytesperline = w/PF2
- linesperchunk = MAX/bytesperline
- linesperchunk = linesperchunk/PF*PF
- nchunks = (h+linesperchunk-1)/linesperchunk
-
- print 'MAX=', MAX,
- print 'linesperchunk=', linesperchunk,
- print 'nchunks=', nchunks,
- print 'w=', w, 'h=', h
-
- x1, x2 = 0, w-1
-
- t1 = millitimer()
- nframes = 0
- fps = 0
-
- msg = ''
-
- while 1:
- while qtest():
- dev, val = qread()
- if dev == REDRAW:
- reshapeviewport()
- w, h = getsize()
- ortho2(0, w, 0, h)
- w = w/PF*PF
- h = h/PF*PF
-
- bytesperline = w/PF2
- linesperchunk = MAX/bytesperline
- linesperchunk = linesperchunk/PF*PF
- nchunks = (h+linesperchunk-1)/linesperchunk
-
- print 'MAX=', MAX,
- print 'linesperchunk=', linesperchunk,
- print 'nchunks=', nchunks,
- print 'w=', w, 'h=', h
-
- x1, x2 = 0, w-1
-
- fps = 0
-
- elif dev == ESCKEY:
- winclose(wid)
- return
-
- readsource(SRC_FRAMEGRABBER)
-
- nframes = nframes+1
- if nframes >= fps:
- t2 = millitimer()
- if t2 <> t1:
- fps = int(10000.0*nframes/(t2-t1)) * 0.1
- msg = `fps` + ' frames/sec'
- t1 = t2
- nframes = 0
-
- RGBcolor(255,255,255)
- cmov2i(9,9)
- charstr(msg)
-
- swapbuffers()
- rectcopy(centerx-w/2, centery-w/2, centerx+w/2, centery+w/2, 0, 0)
-
- for i in range(nchunks):
- y1 = i*linesperchunk
- y2 = y1 + linesperchunk-1
- if y2 >= h: y2 = h-1
- data = lrectread(x1, y1, x2, y2)
- data2 = packrect(x2-x1+1, y2-y1+1, PF, data)
- prefix = `w, h, PF, x1, y1, x2, y2`
- prefix = prefix + ' ' * (HS-len(prefix))
- data3 = prefix + data2
- s.sendto(data3, addr)
-
-main()
diff --git a/Demo/sgi/video/camcorder.py b/Demo/sgi/video/camcorder.py
deleted file mode 100755
index 9b7618c..0000000
--- a/Demo/sgi/video/camcorder.py
+++ /dev/null
@@ -1,266 +0,0 @@
-from gl import *
-from GL import *
-from DEVICE import *
-import time
-import sys
-import getopt
-import socket
-import posix
-import vtime
-
-# Preallocation parameter
-PREALLOC = 4 # Megabyte
-
-# Sync audio parameters
-SYNCPORT = 10000
-CTLPORT = 10001
-
-from vpregs import *
-
-class Struct(): pass
-epoch = Struct()
-
-def getvideosize():
- w = getvideo(VP_WIDTH)
- h = getvideo(VP_HEIGHT)
- print 'WIDTH,HEIGHT:', w, h
- print 'GB{X,Y}ORG:', getvideo(VP_GBXORG), getvideo(VP_GBYORG)
- print 'FB{X,Y}ORG:', getvideo(VP_FBXORG), getvideo(VP_FBYORG)
- x = 0
- y = 0
- return x,y,w,h
-
-framelist = []
-
-def prealloc(w, h):
- nbytes = w*h*4
- limit = PREALLOC*1024*1024
- total = 0
- list = []
- print 'Prealloc to', PREALLOC, 'Megabytes...'
- while total+nbytes <= limit:
- list.append('x'*nbytes)
- total = total + nbytes
- print 'Done.'
-
-def grabframe(f,x,y,w,h,pf):
- readsource(SRC_FRONT)
- if pf:
- w = w/pf*pf
- h = h/pf*pf
- data = lrectread(x,y,x+w-1,y+h-1)
- t = time.millitimer()-epoch.epoch
- framelist.append(data, t)
- readsource(SRC_FRAMEGRABBER)
-
-def saveframes(f, w, h, pf):
- for data, t in framelist:
- if pf:
- w = w/pf*pf
- h = h/pf*pf
- data = packrect(w,h,pf,data)
- f.write(`t` + ',' + `len(data)` + '\n')
- f.write(data)
- framelist[:] = []
-
-def saveframe(f,x,y,w,h,pf, notime):
- readsource(SRC_FRONT)
- if pf:
- w = w/pf*pf
- h = h/pf*pf
- data = lrectread(x,y,x+w-1,y+h-1)
- if pf: data = packrect(w,h,pf,data)
- if notime: t = 0
- else: t = time.millitimer()-epoch.epoch
- f.write(`t` + ',' + `len(data)` + '\n')
- f.write(data)
- readsource(SRC_FRAMEGRABBER)
-
-def drawframe(x,y,w,h,col):
- drawmode(OVERDRAW)
- color(col)
- bgnline()
- v2i(x-1,y-1) ; v2i(x+w,y-1); v2i(x+w,y+h); v2i(x-1,y+h); v2i(x-1,y-1)
- endline()
- drawmode(NORMALDRAW)
-
-def usage():
- sys.stderr.write('Usage: camcorder ' + \
- '[-c] [-p packfactor] [-a audiomachine [-s]] [outputfile]\n')
- sys.exit(2)
-
-def wrheader(f, w, h, pf):
- f.write('CMIF video 1.0\n')
- f.write(`w,h,pf` + '\n')
- print 'width,height,pf:', w, h, pf,
- if pf == 0: pf = 4
- print '(i.e.,', w*h*pf, 'bytes/frame)'
-
-def main():
- foreground()
- pf = 2
- ausync = 0
- austart = 0
- optlist, args = getopt.getopt(sys.argv[1:],'ca:sp:')
- for opt, arg in optlist:
- if opt == '-c':
- pf = 0
- elif opt == '-a':
- ausync = 1
- aumachine = arg
- elif opt == '-s':
- austart = 1
- elif opt == '-p':
- pf = int(eval(arg))
- else:
- usage()
- if args:
- if len(args) > 1:
- print 'Too many arguments'
- usage()
- filename = args[0]
- else:
- filename = 'film.video'
- if austart:
- if not ausync:
- print 'Cannot use -s without -a'
- usage()
- print 'Starting audio recorder...'
- posix.system('rsh '+aumachine+' syncrecord '+socket.gethostname()+' &')
- if ausync:
- print 'Syncing to audio recorder...'
- globtime = vtime.VTime().init(1,aumachine,SYNCPORT)
- ctl = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
- ctl.bind((socket.gethostname(),CTLPORT))
- aua = (socket.gethostbyname(aumachine), CTLPORT)
- print 'Done.'
- vidx, vidy, w, h = getvideosize()
- #prefsize(w,h)
- winx, winy = 1280-w-10, 1024-h-30
- prefposition(winx,winx+w-1,winy,winy+h-1)
- win = winopen(filename)
- f = open(filename, 'w')
- w, h = getsize()
- realw, realh = w, h
- ####doublebuffer()
- RGBmode()
- gconfig()
- qdevice(LEFTMOUSE)
- qdevice(RKEY)
- qdevice(SKEY)
- qdevice(CKEY)
- qdevice(PKEY)
- qdevice(ESCKEY)
- qdevice(WINQUIT)
- qdevice(WINSHUT)
- inrunning = 1
- outrunning = 0
- stop = 'stop'
- readsource(SRC_FRAMEGRABBER)
- mousing = 0
- epoch.epoch = time.millitimer()
- stoptime = epoch.epoch
- sizewritten = 0
- x, y = realw/4, realh/4
- w, h = w/2, h/2
- prealloc(w, h)
- try:
- drawframe(x,y,w,h,1)
- nframe = 0
- num = 0
- while 1:
- insingle = 0
- outsingle = 0
- if mousing:
- drawframe(x,y,w,h,0)
- ox, oy = getorigin()
- if sizewritten:
- x = getvaluator(MOUSEX)-ox
- y = getvaluator(MOUSEY)-oy
- else:
- w = getvaluator(MOUSEX)-x-ox
- h = getvaluator(MOUSEY)-y-oy
- drawframe(x,y,w,h,1)
- if qtest() or \
- not (mousing or inrunning or insingle or outrunning or outsingle):
- ev, val = qread()
- if ev == LEFTMOUSE and val == 1:
- drawframe(x,y,w,h,0)
- mousing = 1
- ox, oy = getorigin()
- x = getvaluator(MOUSEX)-ox
- y = getvaluator(MOUSEY)-oy
- elif ev == LEFTMOUSE and val == 0:
- if h < 0:
- y, h = y+h, -h
- if w < 0:
- x, w = x+w, -w
- mousing = 0
- if not sizewritten:
- wrheader(f, w, h, pf)
- sizewritten = 1
- prealloc(w, h)
- elif ev == RKEY and val == 1:
- if not inrunning:
- ringbell()
- else:
- outrunning = 1
- wasstopped = time.millitimer() - stoptime
- epoch.epoch = epoch.epoch + wasstopped
- nframe = 0
- starttime = time.millitimer()
- if ausync:
- ctl.sendto(`(1,starttime)`, aua)
- elif ev == PKEY and val == 1 and outrunning:
- outrunning = 0
- stoptime = time.millitimer()
- if ausync:
- ctl.sendto(`(0,stoptime)`, aua)
- fps = nframe * 1000.0 / (time.millitimer()-starttime)
- print 'Recorded', nframe,
- print 'frames at', 0.1*int(fps*10),'frames/sec'
- print 'Saving...'
- saveframes(f, w, h, pf)
- print 'Done.'
- elif ev == PKEY and val == 1 and not outrunning:
- outsingle = 1
- elif ev == CKEY and val == 1:
- inrunning = 1
- elif ev == SKEY and val == 1:
- if outrunning:
- ringbell()
- elif inrunning:
- inrunning = 0
- else:
- insingle = 1
- elif ev in (ESCKEY, WINQUIT, WINSHUT):
- if ausync:
- ctl.sendto(`(2,time.millitimer())`, aua)
- raise stop
- elif ev == REDRAW:
- drawframe(x,y,w,h,0)
- reshapeviewport()
- drawframe(x,y,w,h,1)
- if inrunning or insingle:
- if outrunning:
- rectcopy(vidx+x,vidy+y,vidx+x+w-1,vidy+y+h-1,x,y)
- else:
- rectcopy(vidx,vidy,vidx+realw-1,vidx+realh-1,0,0)
- ####swapbuffers()
- if outrunning or outsingle:
- nframe = nframe + 1
- if not sizewritten:
- wrheader(f, w, h, pf)
- sizewritten = 1
- if outrunning:
- grabframe(f, x, y, w, h, pf)
- else:
- saveframe(f, x, y, w, h, pf, outsingle)
- except stop:
- pass
- finally:
- drawmode(OVERDRAW)
- color(0)
- clear()
-
-main()
diff --git a/Demo/sgi/video/colorsys.py b/Demo/sgi/video/colorsys.py
deleted file mode 100755
index dd3a033..0000000
--- a/Demo/sgi/video/colorsys.py
+++ /dev/null
@@ -1,106 +0,0 @@
-#
-# Module color - do color conversions
-#
-
-ONE_THIRD=1.0/3.0
-ONE_SIXTH=1.0/6.0
-TWO_THIRD=2.0/3.0
-
-def rgb_to_yiq(r,g,b):
- y = 0.3*r + 0.59*g + 0.11*b
- i = 0.6*r - 0.28*g - 0.32*b
- q = 0.21*r- 0.52*g + 0.31*b
- return (y,i,q)
-def yiq_to_rgb(y,i,q):
- r = y + 0.948262*i + 0.624013*q
- g = y - 0.276066*i - 0.639810*q
- b = y - 1.105450*i + 1.729860*q
- if r < 0.0: r = 0.0
- if g < 0.0: g = 0.0
- if b < 0.0: b = 0.0
- if r > 1.0: r = 1.0
- if g > 1.0: g = 1.0
- if b > 1.0: b = 1.0
- return (r,g,b)
-
-def _v(m1,m2,hue):
- if hue >= 1.0: hue = hue - 1.0
- if hue < 0.0: hue = hue + 1.0
- if hue < ONE_SIXTH:
- return m1 + (m2-m1)*hue*6.0
- if hue < 0.5:
- return m2
- if hue < TWO_THIRD:
- return m1 + (m2-m1)*(TWO_THIRD-hue)*6.0
- return m1
-
-def rgb_to_hls(r,g,b):
- maxc = max(r,g,b)
- minc = min(r,g,b)
- l = (minc+maxc)/2.0
- if minc == maxc:
- return 0.0, l, 0.0
- if l <= 0.5:
- s = (maxc-minc)/(maxc+minc)
- else:
- s = (maxc-minc)/(2-maxc-minc)
- rc = (maxc-r)/(maxc-minc)
- gc = (maxc-g)/(maxc-minc)
- bc = (maxc-b)/(maxc-minc)
- if r == maxc:
- h = bc-gc
- elif g == maxc:
- h = 2.0+rc-bc
- else:
- h = 4.0+gc-rc
- h = h/6.0
- if h < 0.0:
- h = h + 1.0
- return h,l,s
-def hls_to_rgb(h,l,s):
- if s == 0.0:
- return l,l,l
- if l <= 0.5:
- m2 = l * (1.0+s)
- else:
- m2 = l+s-(l*s)
- m1 = 2.0*l - m2
- return (_v(m1,m2,h+ONE_THIRD), _v(m1,m2,h), _v(m1,m2,h-ONE_THIRD))
-
-def rgb_to_hsv(r,g,b):
- maxc = max(r,g,b)
- minc = min(r,g,b)
- v = maxc
- if minc == maxc:
- return 0.0, 0.0, v
- s = (maxc-minc)/maxc
- rc = (maxc-r)/(maxc-minc)
- gc = (maxc-g)/(maxc-minc)
- bc = (maxc-b)/(maxc-minc)
- if r == maxc:
- h = bc-gc
- elif g == maxc:
- h = 2.0+rc-bc
- else:
- h = 4.0+gc-rc
- h = h/6.0
- if h < 0.0:
- h = h + 1.0
- return h,s,v
-def hsv_to_rgb(h,s,v):
- if s == 0.0:
- return v,v,v
- i = int(h*6.0)
- f = (h*6.0)-i
- p = v*(1.0-s)
- q = v*(1.0-s*f)
- t = v*(1.0-s*(1.0-f))
- if i in (0,6): return v,t,p
- if i == 1: return q,v,p
- if i == 2: return p,v,t
- if i == 3: return p,q,v
- if i == 4: return t,p,v
- if i == 5: return v,p,q
- print i, h, f
- print h, s, v
- raise 'Bad color'
diff --git a/Demo/sgi/video/i2v.c b/Demo/sgi/video/i2v.c
deleted file mode 100755
index 21dfabe..0000000
--- a/Demo/sgi/video/i2v.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * i2v -- image-to-video.
- * Convert an SGI image file to a format that is immediately usable
- * by lrectwrite.
- * The header of the file contains a description (in ASCII)
- * padded to 8196 byte for fast access of the rest of the file.
- *
- * Based upon "showimg.c" by Paul Haeberli.
- * --Guido van Rossum, CWI, Amsterdam
- */
-#include <stdio.h>
-#include <gl/gl.h>
-#include <gl/device.h>
-#include <gl/image.h>
-
-unsigned short rs[8192];
-unsigned short gs[8192];
-unsigned short bs[8192];
-
-IMAGE *image;
-int xsize, ysize, zsize;
-FILE *fp;
-
-char header[100];
-char *progname = "i2v";
-
-main(argc,argv)
-int argc;
-char **argv;
-{
- int y;
- if (argc > 0) progname = argv[0];
- if( argc != 3 ) {
- fprintf(stderr, "usage: %s infile outfile\n", progname);
- exit(2);
- }
- if( (image=iopen(argv[1],"r")) == NULL ) {
- fprintf(stderr, "%s: can't open input file %s\n",progname, argv[1]);
- exit(1);
- }
- xsize = image->xsize;
- ysize = image->ysize;
- zsize = image->zsize;
- if ((fp = fopen(argv[2], "w")) == NULL) {
- fprintf(stderr,"%s: can't open output file %s\n", progname, argv[2]);
- exit(1);
- }
- fprintf(fp, "CMIF video 1.0\n");
- fprintf(fp, "(%d, %d, %d)\n", xsize, ysize, 0);
- fprintf(fp, "0, %ld\n", (long)xsize * (long)ysize * sizeof(long));
- fflush(fp);
- for(y = 0; y < ysize; y++) {
- if(zsize<3) {
- getrow(image, rs, y, 0);
- writepacked(xsize, rs, rs, rs);
- } else {
- getrow(image, rs, y, 0);
- getrow(image, gs, y, 1);
- getrow(image, bs, y, 2);
- writepacked(xsize, rs, gs, bs);
- }
- }
- exit(0);
-}
-
-writepacked(n, rsptr, gsptr, bsptr)
- int n;
- short *rsptr, *gsptr, *bsptr;
-{
- long parray[8192];
- long *pptr = parray;
- int i = n;
- while (--i >= 0) {
- *pptr++ = *rsptr++ | (*gsptr++<<8) | (*bsptr++<<16);
- }
- if (fwrite((char *) parray, sizeof(long), n, fp) != n) {
- perror("fwrite");
- exit(1);
- }
-}
diff --git a/Demo/sgi/video/makemovie.py b/Demo/sgi/video/makemovie.py
deleted file mode 100755
index 5cb41cd..0000000
--- a/Demo/sgi/video/makemovie.py
+++ /dev/null
@@ -1,218 +0,0 @@
-#! /ufs/guido/bin/sgi/python
-#! /ufs/guido/src/video/py
-
-# Capture a CMIF movie using the Indigo video library and board
-
-
-# Usage:
-#
-# makemovie [-q queuesize] [-t recordtime] [-a] [moviefile [audiofile]]
-
-
-# Options:
-#
-# -q queuesize : set the capture queue size (default and max 16)
-# -t recordtime : set the record time in seconds (default 5 seconds)
-# -a : record audio as well
-# moviefile : here goes the movie data (default film.video);
-# the format is documented in cmif-film.ms
-# audiofile : with -a, here goes the audio data (default film.aiff);
-# audio data is recorded in AIFF format, using the
-# input sampling rate, source and volume set by the
-# audio panel, in mono, 8 bits/sample
-
-
-# User interface:
-#
-# Start the application. Resize the window to the desired movie size.
-# Click the left mouse button to start recording (recording starts
-# when you release the mouse button). Recording time is specified by
-# the -t option (XXX this should change).
-#
-# Press ESC or select the window manager Quit or Close window option
-# to quit. (You can do this without recording -- then the output
-# files are untouched.)
-#
-# (It is possible to record more than once; but this doesn't set the
-# time stamps correctly yet, and doesn't work at all with audio. So
-# don't use.)
-
-
-# XXX To do:
-#
-# fix timestamps for second and further recordings
-# fix audio " " " " "
-# flush audio buffer when recording starts
-# make code more readable
-
-
-import sys
-sys.path.append('/ufs/guido/src/video')
-import sv, SV
-import VFile
-import gl, GL, DEVICE
-import al, AL
-import time
-import posix
-import getopt
-import string
-
-
-def main():
- QSIZE = 16
- TIME = 5
- audio = 0
-
- opts, args = getopt.getopt(sys.argv[1:], 'aq:t:')
- for opt, arg in opts:
- if opt == '-a':
- audio = 1
- elif opt == '-q':
- QSIZE = string.atoi(arg)
- elif opt == '-t':
- TIME = string.atoi(arg)
-
- if args:
- filename = args[0]
- else:
- filename = 'film.video'
-
- if audio:
- if args[1:]:
- audiofilename = args[1]
- else:
- audiofilename = 'film.aiff'
-
- gl.foreground()
-
- x, y = SV.PAL_XMAX / 4, SV.PAL_YMAX / 4
- print x, 'x', y
-
- gl.minsize(40, 30)
- gl.stepunit(8, 6)
- gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX)
- gl.keepaspect(SV.PAL_XMAX, SV.PAL_YMAX)
- win = gl.winopen(filename)
- x, y = gl.getsize()
- print x, 'x', y
-
- v = sv.OpenVideo()
- v.BindGLWindow(win, SV.IN_REPLACE)
- v.SetSize(x, y)
- v.BindGLWindow(win, SV.IN_REPLACE)
-
- v.SetCaptureFormat(SV.RGB_FRAMES)
- v.SetCaptureMode(SV.BLOCKING_CAPTURE)
- v.SetQueueSize(QSIZE)
- v.InitCapture()
- if v.GetQueueSize() != QSIZE:
- QSIZE = v.GetQueueSize()
- print 'Warning: QSIZE reduced to', QSIZE
-
- gl.qdevice(DEVICE.LEFTMOUSE)
- gl.qdevice(DEVICE.WINQUIT)
- gl.qdevice(DEVICE.WINSHUT)
- gl.qdevice(DEVICE.ESCKEY)
-
- print 'Click left mouse to start recording', TIME, 'seconds'
- ofile = None
- afile = None
- # Mouse down opens the file & freezes window
- # Mouse up starts recording frames
-
- while 1:
- dev, val = gl.qread()
- if dev == DEVICE.LEFTMOUSE:
- # Start recording
- if val == 1:
- # Mouse down -- preparations
- if ofile == None:
- ofile = VFile.VoutFile().init(filename)
- ofile.format = 'rgb8'
- ofile.width = x
- ofile.height = y
- ofile.writeheader()
- # XXX other format bits?
- # The window can't be resized from now
- gl.prefsize(x, y)
- gl.winconstraints()
- gl.wintitle('* ' + filename)
- if audio:
- afile = initaudio(audiofilename)
- continue
- # Mouse up -- start actual recording
- global recording, stop_recording
- if audio:
- stop_recording = 0
- recording.release()
- t0 = time.millitimer()
- v.StartCapture()
- while 1:
- t = time.millitimer() - t0
- if t >= TIME*1000:
- break
- if v.GetCaptured() > 2:
- doframe(v, ofile, x, y, t)
- v.StopCapture()
- stop_recording = 1
- while v.GetCaptured() > 0:
- doframe(v, ofile, x, y, t)
- t = time.millitimer() - t0
- gl.wintitle(filename)
- elif dev == DEVICE.REDRAW:
- # Window resize (or move)
- x, y = gl.getsize()
- print x, 'x', y
- v.SetSize(x, y)
- v.BindGLWindow(win, SV.IN_REPLACE)
- elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
- # Quit
- if ofile:
- ofile.close()
- if afile:
- afile.destroy()
- posix._exit(0)
- # EndCapture dumps core...
- v.EndCapture()
- v.CloseVideo()
- gl.winclose(win)
-
-def doframe(v, ofile, x, y, t):
- cd, start = v.GetCaptureData()
- data = cd.interleave(x, y)
- cd.UnlockCaptureData()
- ofile.writeframe(t, data, None)
-
-AQSIZE = 16000
-
-def initaudio(filename):
- import thread, aiff
- global recording, stop_recording
- afile = aiff.Aiff().init(filename, 'w')
- afile.nchannels = AL.MONO
- afile.sampwidth = AL.SAMPLE_8
- params = [AL.INPUT_RATE, 0]
- al.getparams(AL.DEFAULT_DEVICE, params)
- print 'rate =', params[1]
- afile.samprate = params[1]
- c = al.newconfig()
- c.setchannels(AL.MONO)
- c.setqueuesize(AQSIZE)
- c.setwidth(AL.SAMPLE_8)
- aport = al.openport(filename, 'r', c)
- recording = thread.allocate_lock()
- recording.acquire()
- stop_recording = 0
- thread.start_new_thread(recorder, (afile, aport))
- return afile
-
-def recorder(afile, aport):
- # XXX recording more than one fragment doesn't work
- # XXX (the thread never dies)
- recording.acquire()
- while not stop_recording:
- data = aport.readsamps(AQSIZE/2)
- afile.writesampsraw(data)
- del data
-
-main()
diff --git a/Demo/sgi/video/squash.c b/Demo/sgi/video/squash.c
deleted file mode 100755
index d5ea946..0000000
--- a/Demo/sgi/video/squash.c
+++ /dev/null
@@ -1,130 +0,0 @@
-#include <stdio.h>
-
-long *bm;
-long h, w;
-long factor;
-
-#define OC(x,xi) ((x)*factor+(xi))
-#define BM(x,xi,y,yi) bm[OC(y,yi)*w+OC(x,xi)]
-
-#define COMP(r,g,b) ((r) | ((g)<<8) | ((b) << 16))
-
-#define R(comp) ((comp) & 0xff)
-#define G(comp) (((comp)>>8) & 0xff)
-#define B(comp) (((comp)>>16) & 0xff)
-
-main(argc, argv)
- char **argv;
-{
- char lbuf[100];
- int nh, nw;
- int x, y, xi, yi;
- int num;
- int r, g, b;
- long data;
- long *nbm, *nbmp;
- int i;
- int bits, mask, roundbit, addbit;
- int pf;
- int newfmt = 0;
-
- if( argc != 2 && argc != 3) {
- fprintf(stderr, "Usage: squash factor [bits]\n");
- exit(1);
- }
- factor = atoi(argv[1]);
- if ( argc > 2 ) {
- bits = atoi(argv[2]);
- mask = (1 << bits) - 1;
- mask <<= (8-bits);
- roundbit = 1 << (7-bits);
- addbit = 1 << (8-bits);
- fprintf(stderr, "%x %x %x\n", mask, roundbit, addbit);
- } else {
- mask = 0xff;
- roundbit = 0;
- addbit = 0;
- }
- gets(lbuf);
- if ( strncmp( lbuf, "CMIF", 4) == 0 ) {
- newfmt = 1;
- gets(lbuf);
- if( sscanf(lbuf, "(%d,%d,%d)", &w, &h, &pf) != 3) {
- fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
- exit(1);
- }
- if ( pf != 0 ) {
- fprintf(stderr, "%s: packed file\n", argv[0]);
- exit(1);
- }
- } else {
- if ( sscanf(lbuf, "(%d,%d)", &w, &h) != 2) {
- fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
- exit(1);
- }
- }
- nh = h / factor;
- nw = w / factor;
- if ( newfmt )
- printf("CMIF video 1.0\n(%d,%d,%d)\n", nw, nh, 0);
- else
- printf("(%d,%d)\n", nw, nh);
- if ( (bm = (long *)malloc(h*w*sizeof(long))) == 0) {
- fprintf(stderr, "%s: No memory\n", argv[0]);
- exit(1);
- }
- if ( (nbm = (long *)malloc(nh*nw*sizeof(long))) == 0) {
- fprintf(stderr, "%s: No memory\n", argv[0]);
- exit(1);
- }
- while( !feof(stdin) ) {
- { int t, s;
- gets(lbuf);
- if ( feof(stdin) ) break;
- if ( sscanf(lbuf, "%d,%d", &t,&s) == 2) {
- if ( s != h*w*4 ) {
- fprintf(stderr, "Size changed from %d to %d: %s\n",4*h*w,s, lbuf);
- exit(1);
- }
- printf("%d, %d\n", t, nh*nw*4);
- } else {
- puts(lbuf);
- }
- }
- fprintf(stderr, "Reading %d\n", h*w*sizeof(long));
- if ( (i=fread(bm, 1, h*w*sizeof(long), stdin)) != h*w*sizeof(long)) {
- fprintf(stderr, "%s: short read, %d wanted %d\n", argv[0],
- i, h*w*sizeof(long));
- exit(1);
- }
- nbmp = nbm;
- for( y=0; y<nh; y++) {
- for ( x=0; x<nw; x++) {
- r = g = b = 0;
- num = 0;
- for( xi=0; xi<factor; xi++ ) {
- for(yi=0; yi<factor; yi++) {
- if ( y*factor+yi < h && x*factor+xi < w ) {
- num++;
- data = BM(x,xi,y,yi);
- r += R(data);
- g += G(data);
- b += B(data);
- }
- else fprintf(stderr, "skip %d %d %d %d\n", x, xi, y, yi);
- }
- }
- r = r/num; g = g/num; b = b/num;
- if ( (r & mask) != mask && ( r & roundbit) ) r += addbit;
- if ( (g & mask) != mask && ( g & roundbit) ) g += addbit;
- if ( (b & mask) != mask && ( b & roundbit) ) b += addbit;
- data = COMP(r, g, b);
- *nbmp++ = data;
- }
- }
- if (nbmp - nbm != nh * nw ) fprintf(stderr, "%d %d\n", nbmp-nbm, nh*nw);
- fprintf(stderr, "Writing %d\n", (nbmp-nbm)*sizeof(long));
- fwrite(nbm, 1, (nbmp-nbm)*sizeof(long), stdout);
- }
- exit(0);
-}
diff --git a/Demo/sgi/video/squash2.c b/Demo/sgi/video/squash2.c
deleted file mode 100755
index c4d03e9..0000000
--- a/Demo/sgi/video/squash2.c
+++ /dev/null
@@ -1,72 +0,0 @@
-#include <stdio.h>
-
-long *bm;
-long h, w;
-long factor;
-
-#define OC(x,xi) ((x)*factor+(xi))
-#define BM(x,xi,y,yi) bm[OC(y,yi)*w+OC(x,xi)]
-
-#define COMP(r,g,b) ((r) | ((g)<<8) | ((b) << 16))
-
-#define R(comp) ((comp) & 0xff)
-#define G(comp) (((comp)>>8) & 0xff)
-#define B(comp) (((comp)>>16) & 0xff)
-
-main(argc, argv)
- char **argv;
-{
- char lbuf[100];
- int nh, nw;
- int x, y, xi, yi;
- int num;
- int r, g, b;
- long data;
- long *nbm, *nbmp;
- int i;
-
- if( argc != 2) {
- fprintf(stderr, "Usage: squash factor\n");
- exit(1);
- }
- factor = atoi(argv[1]);
- gets(lbuf);
- if ( sscanf(lbuf, "(%d,%d)", &w, &h) != 2) {
- fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
- exit(1);
- }
- nh = h / factor;
- nw = w / factor;
- printf("(%d,%d)\n", nw, nh);
- if ( (bm = (long *)malloc(h*w*sizeof(long))) == 0) {
- fprintf(stderr, "%s: No memory\n", argv[0]);
- exit(1);
- }
- if ( (nbm = (long *)malloc(nh*nw*sizeof(long))) == 0) {
- fprintf(stderr, "%s: No memory\n", argv[0]);
- exit(1);
- }
- while( !feof(stdin) ) {
- gets(lbuf);
- if ( feof(stdin) ) break;
- puts(lbuf);
- fprintf(stderr, "Reading %d\n", h*w*sizeof(long));
- if ( (i=fread(bm, 1, h*w*sizeof(long), stdin)) != h*w*sizeof(long)) {
- fprintf(stderr, "%s: short read, %d wanted %d\n", argv[0],
- i, h*w*sizeof(long));
- exit(1);
- }
- nbmp = nbm;
- for( y=0; y<nh; y++) {
- for ( x=0; x<nw; x++) {
- r = g = b = 0;
- num = 0;
- *nbmp++ = BM(x,0,y,0);
- }
- }
- if (nbmp - nbm != nh * nw ) fprintf(stderr, "%d %d\n", nbmp-nbm, nh*nw);
- fprintf(stderr, "Writing %d\n", (nbmp-nbm)*sizeof(long));
- fwrite(nbm, 1, (nbmp-nbm)*sizeof(long), stdout);
- }
- exit(0);
-}
diff --git a/Demo/sgi/video/statit.py b/Demo/sgi/video/statit.py
deleted file mode 100755
index b0c1782..0000000
--- a/Demo/sgi/video/statit.py
+++ /dev/null
@@ -1,115 +0,0 @@
-import sys
-from time import millitimer
-
-def main():
- filename = 'film2.video'
- if sys.argv[1:]: filename = sys.argv[1]
- f = open(filename, 'r')
-
- line = f.readline()
- w, h = eval(line[:-1])
- w2, h2 = w/2, h/2
- size = w2 * h2
-
- data = data2 = t = t0 = t1 = None
- nframes = 0
- t0 = millitimer()
- while 1:
- line = f.readline()
- if not line: break
- t = eval(line[:-1])
- data = None
- data = f.read(size)
- if len(data) <> size:
- raise EOFError
- dostat(w2, h2, data)
- nframes = nframes+1
- t1 = millitimer()
-
- t = 0.001 * (t1-t0)
- fps = 0.1 * int(10*nframes/t)
- print nframes, 'frames in', t, 'sec. =', fps, 'frames/sec.'
-
-def dostat(w, h, data):
- print
- stat3(w, h, data)
-
-# Statistic op 1: frequencies of byte values
-def stat1(w, h, data):
- bins = [0]*256
- for c in data:
- i = ord(c)
- bins[i] = bins[i]+1
- prbins(bins)
-
-def prbins(bins):
- import string
- s = ''
- tot = 0
- for i in range(256):
- tot = tot + bins[i]
- s = s + string.rjust(`bins[i]`, 4)
- if len(s) >= 4*16:
- print s, string.rjust(`tot`, 7)
- s = ''
- tot = 0
-
-# Statistic op 2: run lengths
-def stat2(w, h, data):
- runs = []
- for y in range(h):
- count, value = 0, ord(data[y*w])
- for c in data[y*w : y*w+w]:
- i = ord(c)
- if i <> value:
- runs.append(count, value)
- count, value = 0, i
- count = count+1
- runs.append(count, value)
- print len(runs), 'runs =', 0.1 * (10*w*h/len(runs)), 'bytes/run'
-
-# Statistic op 3: frequencies of byte differences
-def stat3(w, h, data):
- bins = [0]*256
- prev = 0
- for c in data:
- i = ord(c)
- delta = divmod(i-prev, 256)[1]
- prev = i
- bins[delta] = bins[delta]+1
- prbins(bins)
-
-# Try packing
-def packblock(w, h, data):
- res = ''
- for y in range(h):
- res = res + packline(data[y*w : y*w+w])
- return res
-
-def packline(line):
- bytes = []
- for c in line:
- bytes.append(ord(c))
- prev = bytes[0]
- i, n = 1, len(bytes)
- while i < n:
- for pack in (0, 2, 4, 8):
- if pack == 0:
- lo, hi = 0, 0
- else:
- hi = pow(2, pack-1)-1
- lo = -hi-1
- p = prev
- j = i
- count = 0
- while j < n:
- x = bytes[j]
- delta = byte(x-p)
- if not lo <= delta <= hi:
- break
- p = x
- j = j+1
-
-def byte(x): return divmod(x, 256)[1]
-
-main()
diff --git a/Demo/sgi/video/syncaudio.py b/Demo/sgi/video/syncaudio.py
deleted file mode 100755
index fd09d28..0000000
--- a/Demo/sgi/video/syncaudio.py
+++ /dev/null
@@ -1,94 +0,0 @@
-import AL
-import al
-import sys
-import vtime
-import socket
-import time
-
-
-SLEEPTIME = 500 # 500 ms sleeps
-SAMPLEFREQ = 16000 # 16Khz samples
-SAMPLERATE = AL.RATE_16000
-NEEDBUFFERED = SAMPLEFREQ # Buffer 1 second of sound
-BUFFERSIZE = NEEDBUFFERED*4 # setqueuesize() par for 2 second sound
-
-AVSYNCPORT = 10000 # Port for time syncing
-AVCTLPORT = 10001 # Port for record start/stop
-
-def main():
- if len(sys.argv) <> 3:
- print 'Usage: ', sys.argv[0], 'videohostname soundfile'
- sys.exit(1)
- #
- ofile = open(sys.argv[2], 'w')
- #
- globaltime = vtime.VTime().init(0,sys.argv[1],AVSYNCPORT)
- #
- ctl = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
- ctl.bind((socket.gethostname(),AVCTLPORT))
- #
- inp = openmic()
- #
- out = 0 # Open aiff file
- #
- while 1:
- if mainloop(None, ctl, inp, out, globaltime):
- break
- if mainloop(ofile, ctl, inp, out, globaltime):
- break
- pass # Close aiff file
- sys.exit(0)
-#
-def openmic():
- conf = al.newconfig()
- conf.setqueuesize(BUFFERSIZE)
- conf.setwidth(AL.SAMPLE_16)
- conf.setchannels(AL.MONO)
- return al.openport('micr','r',conf)
-#
-def mainloop(ofile, ctl, inp, out, globaltime):
- #
- # Wait for sync packet, keeping 1-2 seconds of sound in the
- # buffer
- #
- totsamps = 0
- totbytes = 0
- starttime = time.millitimer()
- while 1:
- time.millisleep(SLEEPTIME)
- if ctl.avail():
- break
- nsamples = inp.getfilled()-NEEDBUFFERED
- if nsamples>0:
- data = inp.readsamps(nsamples)
- totsamps = totsamps + nsamples
- totbytes = totbytes + len(data)
- if ofile <> None:
- ofile.write(data)
- #
- # Compute his starttime and the timestamp of the first byte in the
- # buffer. Discard all buffered data upto his starttime
- #
- startstop,histime = eval(ctl.recv(100))
- if (ofile == None and startstop == 0) or \
- (ofile <> None and startstop == 1):
- print 'Sync error: saving=',save,' request=',startstop
- sys.exit(1)
- filllevel = inp.getfilled()
- filltime = time.millitimer()
- filltime = filltime - filllevel / (SAMPLEFREQ/1000)
- starttime = globaltime.his2mine(histime)
- nsamples = starttime - filltime
- if nsamples < 0:
- print 'Start/stop signal came too late'
- sys.exit(1)
- nsamples = nsamples * (SAMPLEFREQ / 1000)
- data = inp.readsamps(nsamples)
- totsamps = totsamps + nsamples
- totbytes = totbytes + len(data)
- print 'Time: ', time.millitimer()-starttime, ', Bytes: ', totbytes, ', Samples: ', totsamps
- if ofile <> None:
- ofile.write(data)
- return (startstop == 2)
-
-main()
diff --git a/Demo/sgi/video/tomono.c b/Demo/sgi/video/tomono.c
deleted file mode 100755
index 546af68..0000000
--- a/Demo/sgi/video/tomono.c
+++ /dev/null
@@ -1,165 +0,0 @@
-#include <stdio.h>
-
-long *bm;
-long *nbm;
-long h, w;
-int nh, nw;
-long factor;
-
-#define OC(x,xi) ((x)*factor+(xi))
-#define BM(x,xi,y,yi) bm[OC(y,yi)*w+OC(x,xi)]
-
-#define COMP(r,g,b) ((r) | ((g)<<8) | ((b) << 16))
-
-#define R(comp) ((comp) & 0xff)
-#define G(comp) (((comp)>>8) & 0xff)
-#define B(comp) (((comp)>>16) & 0xff)
-
-#define CHOICEFUNC(np1, np2) ( random() & 1 )
-
-int inlevels = 3*255;
-int outlevels = 1;
-
-main(argc, argv)
- char **argv;
-{
- char lbuf[100];
- int x, y, xi, yi;
- int num;
- int r, g, b;
- long data;
- int i;
- double greyness;
- int inpixels, outpixels;
- int resid;
-
- setvbuf(stdout, 0, _IOFBF, 1024*128);
- if( argc != 2) {
- fprintf(stderr, "Usage: tomono factor\n");
- exit(1);
- }
- factor = atoi(argv[1]);
- gets(lbuf);
- if ( sscanf(lbuf, "(%d,%d)", &w, &h) != 2) {
- fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
- exit(1);
- }
- nh = h / factor;
- nw = w / factor;
- printf("(%d,%d)\n", nw, nh);
- if ( (bm = (long *)malloc(h*w*sizeof(long))) == 0) {
- fprintf(stderr, "%s: No memory\n", argv[0]);
- exit(1);
- }
- if ( (nbm = (long *)malloc(nh*nw*sizeof(long))) == 0) {
- fprintf(stderr, "%s: No memory\n", argv[0]);
- exit(1);
- }
- while( !feof(stdin) ) {
- gets(lbuf);
- if ( feof(stdin) ) break;
- puts(lbuf);
- fprintf(stderr, "Reading %d\n", h*w*sizeof(long));
- if ( (i=fread(bm, 1, h*w*sizeof(long), stdin)) != h*w*sizeof(long)) {
- fprintf(stderr, "%s: short read, %d wanted %d\n", argv[0],
- i, h*w*sizeof(long));
- exit(1);
- }
- /*
- ** Compute picture blackness.
- */
- inpixels = 0;
- inpixels = countpixels(0,0,w,h);
- greyness = (double)inpixels/(h*w*inlevels);
- fprintf(stderr, "%3.1f%% grey\n", 100.0*greyness);
- outpixels = (int)(greyness*outlevels*nh*nw);
- fprintf(stderr, "Inpixels: %d (%d) Outpixels %d\n", inpixels, inpixels/inlevels, outpixels);
- resid = fillpixels(0,0,nw,nh,0,0,w,h,outpixels);
- if ( resid > 1 ) fprintf(stderr, "Residue: %d pixels\n", resid);
- fprintf(stderr, "Writing %d\n", (nh*nw)*sizeof(long));
- fwrite(nbm, 1, (nh*nw)*sizeof(long), stdout);
- }
- exit(0);
-}
-
-countpixels(x0,y0,x1,y1)
-{
- int x, y, tot, data;
-
- tot = 0;
- for( y=y0; y<y1; y++)
- for(x=x0; x<x1; x++) {
- data = bm[y*w+x];
- tot += R(data);
- tot += G(data);
- tot += B(data);
- }
- return tot;
-}
-
-fillpixels(x0,y0,x1,y1,ox0,oy0,ox1,oy1,npixels)
-{
- int m, om, p1, p2, np1, np2, rp, resid;
-
- if ( npixels == 0 ) return 0;
- if ( x0+1 >= x1 && y0+1 >= y1 ) {
- if ( npixels ) {
- nbm[y0*nw+x0] = 0xffffff;
-/* fprintf(stderr, "->%d,%d\n", x0,y0); */
- return npixels - 1;
- }
- return 0;
- }
- if ( x1-x0 < y1-y0 ) {
- if ( y1 - y0 <= 2 )
- m = y0 + 1;
- else
- m = y0+1+(random()%(y1-y0-1));
-/* fprintf(stderr,"%d,%d %d,%d Y %d\n", x0, x1, y0, y1, m); */
- /* om = (oy0+oy1)/2; */ om = m;
- p1 = countpixels(ox0,oy0,ox1,om);
- p2 = countpixels(ox0,om,ox1,oy1);
- np1 = (int)(((float)p1/(p1+p2))*npixels);
- np2 = (int)(((float)p2/(p1+p2))*npixels);
- rp = npixels - np1 - np2;
- if ( rp ) {
- np1 += rp/2;
- rp = rp - rp/2;
- np2 += rp;
- }
- resid = 0;
- if ( CHOICEFUNC(np1, np2) ) {
- resid = fillpixels(x0,y0,x1,m,ox0,oy0,ox1,om,np1+resid);
- resid = fillpixels(x0,m,x1,y1,ox0,om,ox1,oy1,np2+resid);
- } else {
- resid = fillpixels(x0,m,x1,y1,ox0,om,ox1,oy1,np2+resid);
- resid = fillpixels(x0,y0,x1,m,ox0,oy0,ox1,om,np1+resid);
- }
- } else {
- if ( x1 - x0 <= 2 )
- m = x0 + 1;
- else
- m = x0+1+(random()%(x1-x0-1));
-/* fprintf(stderr,"%d,%d %d,%d X %d\n", x0, x1, y0, y1, m); */
- /* om = (ox0+ox1)/2; */ om = m;
- p1 = countpixels(ox0,oy0,om,oy1);
- p2 = countpixels(om,oy0,ox1,oy1);
- np1 = (int)(((float)p1/(p1+p2))*npixels);
- np2 = (int)(((float)p2/(p1+p2))*npixels);
- rp = npixels - np1 - np2;
- if ( rp ) {
- np1 += rp/2;
- rp = rp - rp/2;
- np2 += rp;
- }
- resid = 0;
- if ( CHOICEFUNC(np1, np2) ) {
- resid = fillpixels(x0,y0,m,y1,ox0,oy0,om,oy1,np1+resid);
- resid = fillpixels(m,y0,x1,y1,om,oy0,ox1,oy1,np2+resid);
- } else {
- resid = fillpixels(m,y0,x1,y1,om,oy0,ox1,oy1,np2+resid);
- resid = fillpixels(x0,y0,m,y1,ox0,oy0,om,oy1,np1+resid);
- }
- }
- return resid;
-}
diff --git a/Demo/sgi/video/tv.py b/Demo/sgi/video/tv.py
deleted file mode 100755
index da4bacb..0000000
--- a/Demo/sgi/video/tv.py
+++ /dev/null
@@ -1,79 +0,0 @@
-import string
-
-from socket import *
-from gl import *
-from GL import *
-from DEVICE import *
-from time import millisleep, millitimer
-
-PORT = 5555
-
-PF = 2 # packfactor
-HS = 40 # Header size
-
-def testimage():
- RGBcolor(0, 0, 0)
- clear()
- RGBcolor(0, 255, 0)
- cmov2i(10, 10)
- charstr('Waiting...')
-
-def reshape():
- reshapeviewport()
- w, h = getsize()
- ortho2(0, w, 0, h)
- testimage()
- return w, h
-
-def main():
- s = socket(AF_INET, SOCK_DGRAM)
- s.bind('', PORT)
-
- foreground()
- wid = winopen('tv')
- RGBmode()
- gconfig()
- qdevice(ESCKEY)
-
- oldw, oldh = getsize()
- ortho2(0, oldw, 0, oldh)
- testimage()
-
- t1 = millitimer()
-
- while 1:
- if qtest():
- dev, val = qread()
- if dev == ESCKEY:
- winclose(wid)
- return
- elif dev == REDRAW:
- oldw, oldh = reshape()
- elif s.avail():
- data = s.recv(17000)
- header = string.strip(data[:HS])
- w, h, pf, x1, y1, x2, y2 = eval(header)
- if (w, h) <> (oldw, oldh):
- x, y = getorigin()
- x, y = x-1, y+21 # TWM correction
- winposition(x, x+w-1, y+oldh-h, y+oldh-1)
- oldw, oldh = reshape()
- data2 = data[HS:]
- dx = (x2-x1+1)/pf
- dy = (y2-y1+1)/pf
- data3 = unpackrect(dx, dy, 1, data2)
- rectzoom(pf, pf)
- lrectwrite(x1, y1, x1+dx-1, y1+dy-1, data3)
- t1 = millitimer()
- else:
- t2 = millitimer()
- if t2-t1 >= 5000:
- testimage()
- t1 = t2
- else:
- millisleep(10)
-
- winclose(wid)
- return data
-
-main()
diff --git a/Demo/sgi/video/v2i.c b/Demo/sgi/video/v2i.c
deleted file mode 100755
index 5f8f3b5..0000000
--- a/Demo/sgi/video/v2i.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Convert the first image of a CMIF video movie file to SGI .rgb format.
- usage: v2i videofile imagefile [planemask]
- link with -limage
-*/
-
-#include <stdio.h>
-#include <gl/image.h>
-
-long bm[1280];
-short rb[1280], gb[1280], bb[1280];
-long w, h, pf;
-
-#define R(comp) ((comp) & 0xff)
-#define G(comp) (((comp)>>8) & 0xff)
-#define B(comp) (((comp)>>16) & 0xff)
-
-main(argc, argv)
- char **argv;
-{
- char lbuf[100];
- int x, y;
- int i;
- IMAGE * of;
- int pmask;
-
- if( argc != 3 && argc != 4) {
- fprintf(stderr, "Usage: v2i videofile imgfile [planemask]\n");
- exit(2);
- }
- if ( argc == 4)
- pmask = atoi(argv[3]);
- else
- pmask = 7;
- if ( freopen(argv[1], "r", stdin) == NULL ) {
- perror(argv[1]);
- exit(1);
- }
- if (fgets(lbuf, sizeof lbuf, stdin) == NULL) {
- fprintf(stderr, "Immediate EOF\n");
- exit(1);
- }
- if (strncmp(lbuf, "CMIF", 4) == 0) {
- /* Skip optional header line */
- if (fgets(lbuf, sizeof lbuf, stdin) == NULL) {
- fprintf(stderr, "Immediate EOF after header\n");
- exit(1);
- }
- }
- pf = 2; /* Default */
- if ( sscanf(lbuf, "(%d,%d,%d)", &w, &h, &pf) < 2) {
- fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
- exit(1);
- }
- fgets(lbuf, sizeof lbuf, stdin); /* Skip time info */
- if ( w > 1280 ) {
- fprintf(stderr, "%s: Sorry, too wide\n", argv[0]);
- exit(1);
- }
- if ( (of=iopen(argv[2], "w", RLE(1), 3, w, h, 3)) == 0) {
- perror(argv[2]);
- exit(1);
- }
- for( y=0; y<h; y++) {
- if( fread(bm, sizeof(long), w, stdin) != w) {
- fprintf(stderr, "%s: short read\n", argv[0]);
- exit(1);
- }
- for( x=0; x<w; x++) {
- if ( pmask & 1) rb[x] = R(bm[x]);
- if ( pmask & 2) gb[x] = G(bm[x]);
- if ( pmask & 4) bb[x] = B(bm[x]);
- }
- putrow(of, rb, y, 0);
- putrow(of, gb, y, 1);
- putrow(of, bb, y, 2);
- }
- iclose(of);
- exit(0);
-}
diff --git a/Demo/sgi/video/video.py b/Demo/sgi/video/video.py
deleted file mode 100755
index 1b81bd8..0000000
--- a/Demo/sgi/video/video.py
+++ /dev/null
@@ -1,218 +0,0 @@
-import getopt
-from gl import *
-from GL import *
-from DEVICE import *
-import time
-import sys
-import al
-import AL
-
-sys.path.append('/ufs/guido/src/video') # Increase chance to find colorsys
-import colorsys
-
-BUFFERSIZE = 32000
-
-class Struct(): pass
-epoch = Struct()
-epoch.correcttiming = 1
-EndOfFile = 'End of file'
-bye = 'bye'
-
-def openspkr():
- conf = al.newconfig()
- conf.setqueuesize(BUFFERSIZE)
- conf.setwidth(AL.SAMPLE_16)
- conf.setchannels(AL.MONO)
- return al.openport('spkr','w',conf)
-
-def openvideo(name):
- try:
- f = open(name, 'r')
- except:
- sys.stderr.write(name + ': cannot open\n')
- sys.exit(1)
- line = f.readline()
- if not line: raise EndOfFile
- colorinfo = (8, 0, 0, 0)
- if line[:4] == 'CMIF':
- if line[:14] == 'CMIF video 2.0':
- line = f.readline()
- colorinfo = eval(line[:-1])
- line = f.readline()
- x = eval(line[:-1])
- if len(x) == 3: w, h, pf = x
- else: w, h = x; pf = 2
- if pf and w/pf % 4 <> 0:
- sys.stderr.write( \
- 'warning: stride not a multiple of 4 -- may not work on Indigo XS\n')
- return f, w, h, pf, colorinfo
-
-def loadframe(f,w,h,pf,af,spkr, (ybits,ibits,qbits,chrompack),mf):
- 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
- data = f.read(size)
- if len(data) <> size:
- raise EndOfFile
- if pf:
- w = w/pf
- h = h/pf
- if chrompack:
- cw = (w+chrompack-1)/chrompack
- ch = (h+chrompack-1)/chrompack
- chromdata = f.read(2*cw*ch)
- rectzoom(pf*chrompack*mf,pf*chrompack*mf)
- pixmode(PM_SIZE,16)
- writemask(0x7ff - ((1<<ybits)-1))
- lrectwrite(0,0,cw-1,ch-1,chromdata)
- writemask((1<<ybits)-1)
- pixmode(PM_SIZE,8)
- if pf:
- rectzoom(pf*mf, pf*mf)
- elif mf <> 1:
- rectzoom(mf,mf)
- lrectwrite(0,0,w-1,h-1,data)
- # This is ugly here, but the only way to get the two
- # channels started in sync
- #if af <> None:
- # playsound(af,spkr)
- ct = time.millitimer() - epoch.epoch
- if epoch.correcttiming and tijd > 0 and ct < tijd:
- time.millisleep(tijd-ct)
- #swapbuffers()
- return tijd
-
-def initcmap(ybits,ibits,qbits,chrompack):
- if ybits+ibits+qbits > 11:
- raise 'Sorry, 11 bits max'
- maxy = pow(2,ybits)
- maxi = pow(2,ibits)
- maxq = pow(2,qbits)
- for i in range(2048,4096-256):
- mapcolor(i, 0, 255, 0)
- for y in range(maxy):
- yv = float(y)/float(maxy-1)
- for i in range(maxi):
- if maxi == 1: iv = 0
- else: iv = (float(i)/float(maxi-1))-0.5
- for q in range(maxq):
- if maxq == 1: qv = 0
- else: qv = (float(q)/float(maxq-1))-0.5
- index = 2048 + y + (i << ybits) + (q << (ybits+ibits))
- rv,gv,bv = colorsys.yiq_to_rgb(yv,iv,qv)
- r,g,b = int(rv*255.0), int(gv*255.0), int(bv*255.0)
- if index < 4096 - 256:
- mapcolor(index, r,g,b)
-
-def playsound(af, spkr):
- nsamp = spkr.getfillable()
- data = af.read(nsamp*2)
- spkr.writesamps(data)
-
-def main():
- looping = 0
- packfactor = 0
- magfactor = 1
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'm:p:lF')
- except getopt.error:
- sys.stderr.write('usage: video ' + \
- '[-l] [-p pf] [-m mag] [-F] [moviefile [soundfile [skipbytes]]]\n')
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-m':
- magfactor = int(eval(arg))
- elif opt == '-p':
- packfactor = int(eval(arg))
- elif opt == '-l':
- looping = 1
- elif opt == '-F':
- epoch.correcttiming = 0
- if args:
- filename = args[0]
- else:
- filename = 'film.video'
- f, w, h, pf, cinfo = openvideo(filename)
- if 0 < packfactor <> pf:
- w = w/pf*packfactor
- h = h/pf*packfactor
- pf = packfactor
- if args[1:]:
- audiofilename = args[1]
- af = open(audiofilename, 'r')
- spkr = openspkr()
- afskip = 0
- if args[2:]:
- afskip = eval(args[2])
- af.seek(afskip)
- else:
- af, spkr = None, None
- foreground()
- prefsize(w*magfactor,h*magfactor)
- win = winopen(filename)
- if pf:
- #doublebuffer()
- cmode()
- else:
- RGBmode()
- #doublebuffer()
- gconfig()
- if pf:
- initcmap(cinfo)
- color(2048)
- clear()
- writemask(2047)
- pixmode(PM_SIZE,8) # 8 bit pixels
- qdevice(ESCKEY)
- qdevice(WINSHUT)
- qdevice(WINQUIT)
- running = 1
- epoch.epoch = time.millitimer()
- nframe = 0
- tijd = 1
- if looping:
- looping = f.tell()
- try:
- while 1:
- if running:
- try:
- tijd = loadframe(f, w, h, pf, af, spkr, cinfo,magfactor)
- nframe = nframe + 1
- except EndOfFile:
- running = 0
- t = time.millitimer()
- if tijd > 0:
- print 'Recorded at',
- print 0.1 * int(nframe * 10000.0 / tijd),
- print 'frames/sec'
- print 'Played', nframe, 'frames at',
- print 0.1 * int(nframe * 10000.0 / (t-epoch.epoch)),
- print 'frames/sec'
- if looping:
- f.seek(looping)
- epoch.epoch = time.millitimer()
- nframe = 0
- running = 1
- if af <> None:
- af.seek(afskip)
- if af <> None:
- playsound(af,spkr)
- if not running or qtest():
- dev, val = qread()
- if dev in (ESCKEY, WINSHUT, WINQUIT):
- raise bye
- elif dev == REDRAW:
- reshapeviewport()
- except bye:
- pass
-
-main()
diff --git a/Demo/sgi/video/vpregs.py b/Demo/sgi/video/vpregs.py
deleted file mode 100755
index d33f1fe..0000000
--- a/Demo/sgi/video/vpregs.py
+++ /dev/null
@@ -1,28 +0,0 @@
-VID_VP = 0x1000000
-
-# Set vp1 register tokens
-VP_GBXORG = (VID_VP +0x01)
-VP_GBYORG = (VID_VP +0x02)
-VP_FBXORG = (VID_VP +0x03)
-VP_FBYORG = (VID_VP +0x04)
-VP_WIDTH = (VID_VP +0x05)
-VP_HEIGHT = (VID_VP +0x06)
-VP_PIXCNT = (VID_VP +0x07)
-VP_HBLANK = (VID_VP +0x08)
-VP_VBLANK = (VID_VP +0x09)
-VP_BRITE = (VID_VP +0x0A)
-VP_CONT = (VID_VP +0x0B)
-VP_HUE = (VID_VP +0x0C)
-VP_SAT = (VID_VP +0x0D)
-VP_ALPHA = (VID_VP +0X0E)
-VP_FGMODE = (VID_VP +0x0F)
-VP_MAPSRC = (VID_VP +0x10)
-VP_MAPADD = (VID_VP +0x11)
-VP_MAPRED = (VID_VP +0x12)
-VP_MAPGREEN = (VID_VP +0x13)
-VP_MAPBLUE = (VID_VP +0x14)
-VP_MAPSTROBE = (VID_VP +0x15)
-VP_DIGVAL = (VID_VP +0x16)
-VP_STATUS0 = (VID_VP +0x17)
-VP_STATUS1 = (VID_VP +0x18)
-VP_CMD = (VID_VP +0x19)
diff --git a/Lib/builtin.py b/Lib/builtin.py
deleted file mode 100755
index 710d825..0000000
--- a/Lib/builtin.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# B/W compat hack so code that says "import builtin" won't break after
-# name change from builtin to __builtin__.
-from __builtin__ import *
diff --git a/Lib/macstat.py b/Lib/macstat.py
deleted file mode 100755
index 4b53953..0000000
--- a/Lib/macstat.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# Module 'stat'
-#
-# Defines constants and functions for interpreting stat/lstat struct
-# as returned by os.stat() and os.lstat() (if it exists).
-#
-# Suggested usage: from stat import *
-#
-# XXX Strictly spoken, this module may have to be adapted for each POSIX
-# implementation; in practice, however, the numeric constants used by
-# stat() are almost universal (even for stat() emulations on non-UNIX
-# systems like MS-DOS).
-
-# Indices for stat struct members in tuple returned by os.stat()
-
-ST_MODE = 0
-ST_INO = 1
-ST_DEV = 2
-ST_NLINK = 3
-ST_UID = 4
-ST_GID = 5
-ST_SIZE = 6
-ST_ATIME = 7
-ST_MTIME = 8
-ST_CTIME = 9
-
-# Extract bits from the mode
-
-def S_IMODE(mode):
- return 0
-
-def S_IFMT(mode):
- return mode & 0xFFFF
-
-# Constants used as S_IFMT() for various file types
-# (not all are implemented on all systems)
-
-S_IFDIR = 0x0000
-S_IFREG = 0x0003
-
-# Functions to test for each file type
-
-def S_ISDIR(mode):
- return S_IFMT(mode) == S_IFDIR
-
-def S_ISCHR(mode):
- return 0
-
-def S_ISBLK(mode):
- return 0
-
-def S_ISREG(mode):
- return S_IFMT(mode) == S_IFREG
-
-def S_ISFIFO(mode):
- return 0
-
-def S_ISLNK(mode):
- return 0
-
-def S_ISSOCK(mode):
- return 0
-
-# Names for permission bits
-
-S_ISUID = 04000
-S_ISGID = 02000
-S_ENFMT = S_ISGID
-S_ISVTX = 01000
-S_IREAD = 00400
-S_IWRITE = 00200
-S_IEXEC = 00100
-S_IRWXU = 00700
-S_IRUSR = 00400
-S_IWUSR = 00200
-S_IXUSR = 00100
-S_IRWXG = 00070
-S_IRGRP = 00040
-S_IWGRP = 00020
-S_IXGRP = 00010
-S_IRWXO = 00007
-S_IROTH = 00004
-S_IWOTH = 00002
-S_IXOTH = 00001
diff --git a/Lib/persist.py b/Lib/persist.py
deleted file mode 100755
index 8f0f164..0000000
--- a/Lib/persist.py
+++ /dev/null
@@ -1,297 +0,0 @@
-# persist.py
-#
-# Implement limited persistence.
-#
-# Simple interface:
-# persist.save() save __main__ module on file (overwrite)
-# persist.load() load __main__ module from file (merge)
-#
-# These use the filename persist.defaultfile, initialized to 'wsrestore.py'.
-#
-# A raw interface also exists:
-# persist.writedict(dict, fp) save dictionary to open file
-# persist.readdict(dict, fp) read (merge) dictionary from open file
-#
-# Internally, the function dump() and a whole bunch of support of functions
-# traverse a graph of objects and print them in a restorable form
-# (which happens to be a Python module).
-#
-# XXX Limitations:
-# - Volatile objects are dumped as strings:
-# - open files, windows etc.
-# - Other 'obscure' objects are dumped as strings:
-# - classes, instances and methods
-# - compiled regular expressions
-# - anything else reasonably obscure (e.g., capabilities)
-# - type objects for obscure objects
-# - It's slow when there are many of lists or dictionaries
-# (This could be fixed if there were a quick way to compute a hash
-# function of any object, even if recursive)
-
-defaultfile = 'wsrestore.py'
-
-def save():
- import __main__
- import os
- # XXX On SYSV, if len(defaultfile) >= 14, this is wrong!
- backup = defaultfile + '~'
- try:
- os.unlink(backup)
- except os.error:
- pass
- try:
- os.rename(defaultfile, backup)
- except os.error:
- pass
- fp = open(defaultfile, 'w')
- writedict(__main__.__dict__, fp)
- fp.close()
-
-def load():
- import __main__
- fp = open(defaultfile, 'r')
- readdict(__main__.__dict__, fp)
-
-def writedict(dict, fp):
- import sys
- savestdout = sys.stdout
- try:
- sys.stdout = fp
- dump(dict) # Writes to sys.stdout
- finally:
- sys.stdout = savestdout
-
-def readdict(dict, fp):
- contents = fp.read()
- globals = {}
- exec(contents, globals)
- top = globals['top']
- for key in top.keys():
- if dict.has_key(key):
- print 'warning:', key, 'not overwritten'
- else:
- dict[key] = top[key]
-
-
-# Function dump(x) prints (on sys.stdout!) a sequence of Python statements
-# that, when executed in an empty environment, will reconstruct the
-# contents of an arbitrary dictionary.
-
-import sys
-
-# Name used for objects dict on output.
-#
-FUNNYNAME = FN = 'A'
-
-# Top-level function. Call with the object you want to dump.
-#
-def dump(x):
- types = {}
- stack = [] # Used by test for recursive objects
- print FN, '= {}'
- topuid = dumpobject(x, types, stack)
- print 'top =', FN, '[', `topuid`, ']'
-
-# Generic function to dump any object.
-#
-dumpswitch = {}
-#
-def dumpobject(x, types, stack):
- typerepr = `type(x)`
- if not types.has_key(typerepr):
- types[typerepr] = {}
- typedict = types[typerepr]
- if dumpswitch.has_key(typerepr):
- return dumpswitch[typerepr](x, typedict, types, stack)
- else:
- return dumpbadvalue(x, typedict, types, stack)
-
-# Generic function to dump unknown values.
-# This assumes that the Python interpreter prints such values as
-# <foo object at xxxxxxxx>.
-# The object will be read back as a string: '<foo object at xxxxxxxx>'.
-# In some cases it may be possible to fix the dump manually;
-# to ease the editing, these cases are labeled with an XXX comment.
-#
-def dumpbadvalue(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- print FN, '[', `uid`, '] =', `xrepr`, '# XXX'
- return uid
-
-# Generic function to dump pure, simple values, except strings
-#
-def dumpvalue(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- print FN, '[', `uid`, '] =', `x`
- return uid
-
-# Functions to dump string objects
-#
-def dumpstring(x, typedict, types, stack):
- # XXX This can break if strings have embedded '\0' bytes
- # XXX because of a bug in the dictionary module
- if typedict.has_key(x):
- return typedict[x]
- uid = genuid()
- typedict[x] = uid
- print FN, '[', `uid`, '] =', `x`
- return uid
-
-# Function to dump type objects
-#
-typeswitch = {}
-class some_class:
- def method(self): pass
-some_instance = some_class()
-#
-def dumptype(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- if typeswitch.has_key(xrepr):
- print FN, '[', `uid`, '] =', typeswitch[xrepr]
- elif x == type(sys):
- print 'import sys'
- print FN, '[', `uid`, '] = type(sys)'
- elif x == type(sys.stderr):
- print 'import sys'
- print FN, '[', `uid`, '] = type(sys.stderr)'
- elif x == type(dumptype):
- print 'def some_function(): pass'
- print FN, '[', `uid`, '] = type(some_function)'
- elif x == type(some_class):
- print 'class some_class: pass'
- print FN, '[', `uid`, '] = type(some_class)'
- elif x == type(some_instance):
- print 'class another_class: pass'
- print 'some_instance = another_class()'
- print FN, '[', `uid`, '] = type(some_instance)'
- elif x == type(some_instance.method):
- print 'class yet_another_class:'
- print ' def method(): pass'
- print 'another_instance = yet_another_class()'
- print FN, '[', `uid`, '] = type(another_instance.method)'
- else:
- # Unknown type
- print FN, '[', `uid`, '] =', `xrepr`, '# XXX'
- return uid
-
-# Initialize the typeswitch
-#
-for x in None, 0, 0.0, '', (), [], {}:
- typeswitch[`type(x)`] = 'type(' + `x` + ')'
-for s in 'type(0)', 'abs', '[].append':
- typeswitch[`type(eval(s))`] = 'type(' + s + ')'
-
-# Dump a tuple object
-#
-def dumptuple(x, typedict, types, stack):
- item_uids = []
- xrepr = ''
- for item in x:
- item_uid = dumpobject(item, types, stack)
- item_uids.append(item_uid)
- xrepr = xrepr + ' ' + item_uid
- del stack[-1:]
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- print FN, '[', `uid`, '] = (',
- for item_uid in item_uids:
- print FN, '[', `item_uid`, '],',
- print ')'
- return uid
-
-# Dump a list object
-#
-def dumplist(x, typedict, types, stack):
- # Check for recursion
- for x1, uid1 in stack:
- if x is x1: return uid1
- # Check for occurrence elsewhere in the typedict
- for uid1 in typedict.keys():
- if x is typedict[uid1]: return uid1
- # This uses typedict differently!
- uid = genuid()
- typedict[uid] = x
- print FN, '[', `uid`, '] = []'
- stack.append(x, uid)
- item_uids = []
- for item in x:
- item_uid = dumpobject(item, types, stack)
- item_uids.append(item_uid)
- del stack[-1:]
- for item_uid in item_uids:
- print FN, '[', `uid`, '].append(', FN, '[', `item_uid`, '])'
- return uid
-
-# Dump a dictionary object
-#
-def dumpdict(x, typedict, types, stack):
- # Check for recursion
- for x1, uid1 in stack:
- if x is x1: return uid1
- # Check for occurrence elsewhere in the typedict
- for uid1 in typedict.keys():
- if x is typedict[uid1]: return uid1
- # This uses typedict differently!
- uid = genuid()
- typedict[uid] = x
- print FN, '[', `uid`, '] = {}'
- stack.append(x, uid)
- item_uids = []
- for key in x.keys():
- val_uid = dumpobject(x[key], types, stack)
- item_uids.append(key, val_uid)
- del stack[-1:]
- for key, val_uid in item_uids:
- print FN, '[', `uid`, '][', `key`, '] =',
- print FN, '[', `val_uid`, ']'
- return uid
-
-# Dump a module object
-#
-def dumpmodule(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- from string import split
- # `x` has the form <module 'foo'>
- name = xrepr[9:-2]
- uid = genuid()
- typedict[xrepr] = uid
- print 'import', name
- print FN, '[', `uid`, '] =', name
- return uid
-
-
-# Initialize dumpswitch, a table of functions to dump various objects,
-# indexed by `type(x)`.
-#
-for x in None, 0, 0.0:
- dumpswitch[`type(x)`] = dumpvalue
-for x, f in ('', dumpstring), (type(0), dumptype), ((), dumptuple), \
- ([], dumplist), ({}, dumpdict), (sys, dumpmodule):
- dumpswitch[`type(x)`] = f
-
-
-# Generate the next unique id; a string consisting of digits.
-# The seed is stored as seed[0].
-#
-seed = [0]
-#
-def genuid():
- x = seed[0]
- seed[0] = seed[0] + 1
- return `x`
diff --git a/Python/pythonmain.c b/Python/pythonmain.c
deleted file mode 100644
index 000a3d7..0000000
--- a/Python/pythonmain.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/***********************************************************
-Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
-The Netherlands.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the names of Stichting Mathematisch
-Centrum or CWI not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-
-STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
-THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
-FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
-OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-******************************************************************/
-
-/* Python interpreter main program */
-
-#include "allobjects.h"
-
-extern int debugging; /* Needed in parser.c, declared in pythonrun.c */
-extern int verbose; /* Needed in import.c, declared in pythonrun.c */
-extern int suppress_print; /* Needed in ceval.c, declared in pythonrun.c */
-
-/* Interface to getopt(): */
-extern int optind;
-extern char *optarg;
-extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
-
-extern char *getenv();
-
-extern char *getversion();
-extern char *getcopyright();
-
-int
-realmain(argc, argv)
- int argc;
- char **argv;
-{
- int c;
- int sts;
- char *command = NULL;
- char *filename = NULL;
- FILE *fp = stdin;
- char *p;
- int inspect = 0;
- int unbuffered = 0;
-
- if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
- debugging = 1;
- if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
- suppress_print = 1;
- if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
- verbose = 1;
- if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
- inspect = 1;
- if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
- unbuffered = 1;
-
-#ifdef macintosh
- PyMac_InteractiveOptions(&inspect, &verbose, &suppress_print, &unbuffered, &debugging);
-#endif
-
- while ((c = getopt(argc, argv, "c:disuv")) != EOF) {
- if (c == 'c') {
- /* -c is the last option; following arguments
- that look like options are left for the
- the command to interpret. */
- command = malloc(strlen(optarg) + 2);
- if (command == NULL)
- fatal("not enough memory to copy -c argument");
- strcpy(command, optarg);
- strcat(command, "\n");
- break;
- }
-
- switch (c) {
-
- case 'd':
- debugging++;
- break;
-
- case 'i':
- inspect++;
- break;
-
- case 's':
- suppress_print++;
- break;
-
- case 'u':
- unbuffered++;
- break;
-
- case 'v':
- verbose++;
- break;
-
- /* This space reserved for other options */
-
- default:
- fprintf(stderr,
-"usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n",
- argv[0]);
-#if !(defined(__CFM68K__) && defined(__MWERKS__))
- /* Mwerks cfm68k linker doesn't like these... */
- fprintf(stderr, "\
-\n\
-Options and arguments (and corresponding environment variables):\n\
--d : debug output from parser (also PYTHONDEBUG=x)\n\
--i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
--s : suppress the printing of top level expressions (also PYTHONSUPPRESS=x)\n\
--u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
--v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
--c cmd : program passed in as string (terminates option list)\n\
-");
- /* ANSI does not allow strings > 512 chars
- and MPW doesn't like it either -- so split it! */
- fprintf(stderr, "\
-file : program read from script file\n\
-- : program read from stdin (default; interactive mode if a tty)\n\
-arg ...: arguments passed to program in sys.argv[1:]\n\
-\n\
-Other environment variables:\n\
-PYTHONSTARTUP: file executed on interactive startup (no default)\n\
-PYTHONPATH : colon-separated list of directories prefixed to the\n\
- default module search path. The result is sys.path.\n\
-");
-#endif /* !cfm68k || !mwerks */
- exit(2);
- /*NOTREACHED*/
-
- }
- }
-
- if (unbuffered) {
-#ifndef MPW
- setbuf(stdout, (char *)NULL);
- setbuf(stderr, (char *)NULL);
-#else
- /* On MPW (3.2) unbuffered seems to hang */
- setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
- setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
-#endif
- }
-
- if (command == NULL && optind < argc && strcmp(argv[optind], "-") != 0)
- filename = argv[optind];
-
- if (verbose ||
- command == NULL && filename == NULL && isatty((int)fileno(fp)))
- fprintf(stderr, "Python %s\n%s\n",
- getversion(), getcopyright());
-
- if (filename != NULL) {
- if ((fp = fopen(filename, "r")) == NULL) {
- fprintf(stderr, "%s: can't open file '%s'\n",
- argv[0], filename);
- exit(2);
- }
- }
-
- initall();
-
- if (command != NULL) {
- /* Backup optind and force sys.argv[0] = '-c' */
- optind--;
- argv[optind] = "-c";
- }
-
- setpythonargv(argc-optind, argv+optind);
-
- if (command) {
- sts = run_command(command) != 0;
- }
- else {
- if (filename == NULL && isatty((int)fileno(fp))) {
- char *startup = getenv("PYTHONSTARTUP");
-#ifdef macintosh
- if (startup == NULL)
- startup = "PythonStartup";
-#endif
- if (startup != NULL && startup[0] != '\0') {
- FILE *fp = fopen(startup, "r");
- if (fp != NULL) {
- (void) run_script(fp, startup);
- err_clear();
- fclose(fp);
- }
- }
- }
- sts = run(fp, filename == NULL ? "<stdin>" : filename) != 0;
- if (filename != NULL)
- fclose(fp);
- }
-
- if (inspect && isatty((int)fileno(stdin)) &&
- (filename != NULL || command != NULL))
- sts = run(stdin, "<stdin>") != 0;
-
- goaway(sts);
- /*NOTREACHED*/
-}