1991-11-04 18:04:21 +00:00
|
|
|
import getopt
|
1991-10-30 11:52:48 +00:00
|
|
|
from gl import *
|
|
|
|
from GL import *
|
|
|
|
from DEVICE import *
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import al
|
|
|
|
import AL
|
1992-05-12 12:33:44 +00:00
|
|
|
|
|
|
|
sys.path.append('/ufs/guido/src/video') # Increase chance to find colorsys
|
1991-11-22 14:04:01 +00:00
|
|
|
import colorsys
|
1991-10-30 11:52:48 +00:00
|
|
|
|
|
|
|
BUFFERSIZE = 32000
|
|
|
|
|
|
|
|
class Struct(): pass
|
|
|
|
epoch = Struct()
|
1991-11-22 14:04:01 +00:00
|
|
|
epoch.correcttiming = 1
|
1991-10-30 11:52:48 +00:00
|
|
|
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)
|
1991-11-04 14:29:27 +00:00
|
|
|
|
1991-10-30 11:52:48 +00:00
|
|
|
def openvideo(name):
|
1991-11-04 14:29:27 +00:00
|
|
|
try:
|
|
|
|
f = open(name, 'r')
|
|
|
|
except:
|
|
|
|
sys.stderr.write(name + ': cannot open\n')
|
|
|
|
sys.exit(1)
|
1991-10-30 11:52:48 +00:00
|
|
|
line = f.readline()
|
|
|
|
if not line: raise EndOfFile
|
1992-05-06 17:58:18 +00:00
|
|
|
colorinfo = (8, 0, 0, 0)
|
1992-02-11 14:50:22 +00:00
|
|
|
if line[:4] == 'CMIF':
|
|
|
|
if line[:14] == 'CMIF video 2.0':
|
1991-11-22 14:04:01 +00:00
|
|
|
line = f.readline()
|
|
|
|
colorinfo = eval(line[:-1])
|
|
|
|
line = f.readline()
|
1991-10-30 11:52:48 +00:00
|
|
|
x = eval(line[:-1])
|
1992-02-11 14:50:22 +00:00
|
|
|
if len(x) == 3: w, h, pf = x
|
1991-10-30 11:52:48 +00:00
|
|
|
else: w, h = x; pf = 2
|
1992-05-07 15:21:25 +00:00
|
|
|
if pf and w/pf % 4 <> 0:
|
|
|
|
sys.stderr.write( \
|
|
|
|
'warning: stride not a multiple of 4 -- may not work on Indigo XS\n')
|
1991-11-22 14:04:01 +00:00
|
|
|
return f, w, h, pf, colorinfo
|
1991-11-04 14:29:27 +00:00
|
|
|
|
1991-11-22 14:04:01 +00:00
|
|
|
def loadframe(f,w,h,pf,af,spkr, (ybits,ibits,qbits,chrompack),mf):
|
1991-10-30 11:52:48 +00:00
|
|
|
line = f.readline()
|
1992-02-11 14:50:22 +00:00
|
|
|
if line == '':
|
1991-10-30 11:52:48 +00:00
|
|
|
raise EndOfFile
|
|
|
|
x = eval(line[:-1])
|
1992-02-11 14:50:22 +00:00
|
|
|
if type(x) == type(0) or type(x) == type(0.0):
|
1991-10-30 11:52:48 +00:00
|
|
|
tijd = x
|
1992-02-11 14:50:22 +00:00
|
|
|
if pf == 0:
|
1991-10-30 11:52:48 +00:00
|
|
|
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
|
1991-11-22 14:04:01 +00:00
|
|
|
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)
|
1992-05-07 15:21:25 +00:00
|
|
|
pixmode(PM_SIZE,16)
|
1991-11-22 14:04:01 +00:00
|
|
|
writemask(0x7ff - ((1<<ybits)-1))
|
|
|
|
lrectwrite(0,0,cw-1,ch-1,chromdata)
|
|
|
|
writemask((1<<ybits)-1)
|
1992-05-07 15:21:25 +00:00
|
|
|
pixmode(PM_SIZE,8)
|
1991-11-22 14:04:01 +00:00
|
|
|
if pf:
|
|
|
|
rectzoom(pf*mf, pf*mf)
|
|
|
|
elif mf <> 1:
|
|
|
|
rectzoom(mf,mf)
|
1991-10-30 11:52:48 +00:00
|
|
|
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
|
1991-11-22 14:04:01 +00:00
|
|
|
if epoch.correcttiming and tijd > 0 and ct < tijd:
|
1991-10-30 11:52:48 +00:00
|
|
|
time.millisleep(tijd-ct)
|
1991-11-04 14:29:27 +00:00
|
|
|
#swapbuffers()
|
1991-10-30 11:52:48 +00:00
|
|
|
return tijd
|
1991-11-04 14:29:27 +00:00
|
|
|
|
1991-11-22 14:04:01 +00:00
|
|
|
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):
|
1992-02-11 14:50:22 +00:00
|
|
|
if maxi == 1: iv = 0
|
1991-12-03 17:25:52 +00:00
|
|
|
else: iv = (float(i)/float(maxi-1))-0.5
|
1991-11-22 14:04:01 +00:00
|
|
|
for q in range(maxq):
|
1992-02-11 14:50:22 +00:00
|
|
|
if maxq == 1: qv = 0
|
1991-12-03 17:25:52 +00:00
|
|
|
else: qv = (float(q)/float(maxq-1))-0.5
|
1991-11-22 14:04:01 +00:00
|
|
|
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)
|
|
|
|
|
1991-10-30 11:52:48 +00:00
|
|
|
def playsound(af, spkr):
|
|
|
|
nsamp = spkr.getfillable()
|
|
|
|
data = af.read(nsamp*2)
|
|
|
|
spkr.writesamps(data)
|
1991-11-04 14:29:27 +00:00
|
|
|
|
1991-10-30 11:52:48 +00:00
|
|
|
def main():
|
1991-11-04 18:04:21 +00:00
|
|
|
looping = 0
|
|
|
|
packfactor = 0
|
1991-11-22 14:04:01 +00:00
|
|
|
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)
|
1991-11-04 18:04:21 +00:00
|
|
|
for opt, arg in opts:
|
1992-02-11 14:50:22 +00:00
|
|
|
if opt == '-m':
|
1991-11-22 14:04:01 +00:00
|
|
|
magfactor = int(eval(arg))
|
1992-02-11 14:50:22 +00:00
|
|
|
elif opt == '-p':
|
1991-11-04 18:04:21 +00:00
|
|
|
packfactor = int(eval(arg))
|
1992-02-11 14:50:22 +00:00
|
|
|
elif opt == '-l':
|
1991-11-04 18:04:21 +00:00
|
|
|
looping = 1
|
1992-02-11 14:50:22 +00:00
|
|
|
elif opt == '-F':
|
1991-11-22 14:04:01 +00:00
|
|
|
epoch.correcttiming = 0
|
1991-11-04 18:04:21 +00:00
|
|
|
if args:
|
|
|
|
filename = args[0]
|
1991-11-04 14:29:27 +00:00
|
|
|
else:
|
|
|
|
filename = 'film.video'
|
1991-11-22 14:04:01 +00:00
|
|
|
f, w, h, pf, cinfo = openvideo(filename)
|
1991-11-04 18:04:21 +00:00
|
|
|
if 0 < packfactor <> pf:
|
|
|
|
w = w/pf*packfactor
|
|
|
|
h = h/pf*packfactor
|
|
|
|
pf = packfactor
|
|
|
|
if args[1:]:
|
|
|
|
audiofilename = args[1]
|
1991-11-04 14:29:27 +00:00
|
|
|
af = open(audiofilename, 'r')
|
|
|
|
spkr = openspkr()
|
1991-11-04 18:04:21 +00:00
|
|
|
afskip = 0
|
1991-11-04 18:14:23 +00:00
|
|
|
if args[2:]:
|
|
|
|
afskip = eval(args[2])
|
|
|
|
af.seek(afskip)
|
1991-11-04 14:29:27 +00:00
|
|
|
else:
|
|
|
|
af, spkr = None, None
|
1991-11-04 18:04:21 +00:00
|
|
|
foreground()
|
1991-11-22 14:04:01 +00:00
|
|
|
prefsize(w*magfactor,h*magfactor)
|
1991-11-04 14:29:27 +00:00
|
|
|
win = winopen(filename)
|
1991-11-22 14:04:01 +00:00
|
|
|
if pf:
|
|
|
|
#doublebuffer()
|
|
|
|
cmode()
|
|
|
|
else:
|
|
|
|
RGBmode()
|
1991-11-04 14:29:27 +00:00
|
|
|
#doublebuffer()
|
|
|
|
gconfig()
|
1991-11-22 14:04:01 +00:00
|
|
|
if pf:
|
|
|
|
initcmap(cinfo)
|
|
|
|
color(2048)
|
|
|
|
clear()
|
|
|
|
writemask(2047)
|
1992-05-07 15:21:25 +00:00
|
|
|
pixmode(PM_SIZE,8) # 8 bit pixels
|
1991-11-04 14:29:27 +00:00
|
|
|
qdevice(ESCKEY)
|
|
|
|
qdevice(WINSHUT)
|
|
|
|
qdevice(WINQUIT)
|
|
|
|
running = 1
|
|
|
|
epoch.epoch = time.millitimer()
|
|
|
|
nframe = 0
|
|
|
|
tijd = 1
|
1991-11-04 18:04:21 +00:00
|
|
|
if looping:
|
|
|
|
looping = f.tell()
|
1991-11-04 14:29:27 +00:00
|
|
|
try:
|
|
|
|
while 1:
|
|
|
|
if running:
|
|
|
|
try:
|
1991-11-22 14:04:01 +00:00
|
|
|
tijd = loadframe(f, w, h, pf, af, spkr, cinfo,magfactor)
|
1991-11-04 14:29:27 +00:00
|
|
|
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'
|
1991-11-04 18:04:21 +00:00
|
|
|
if looping:
|
|
|
|
f.seek(looping)
|
|
|
|
epoch.epoch = time.millitimer()
|
|
|
|
nframe = 0
|
|
|
|
running = 1
|
|
|
|
if af <> None:
|
|
|
|
af.seek(afskip)
|
1991-11-04 14:29:27 +00:00
|
|
|
if af <> None:
|
|
|
|
playsound(af,spkr)
|
|
|
|
if not running or qtest():
|
|
|
|
dev, val = qread()
|
|
|
|
if dev in (ESCKEY, WINSHUT, WINQUIT):
|
|
|
|
raise bye
|
1992-02-11 14:50:22 +00:00
|
|
|
elif dev == REDRAW:
|
1991-11-04 14:29:27 +00:00
|
|
|
reshapeviewport()
|
|
|
|
except bye:
|
|
|
|
pass
|
1991-10-30 11:52:48 +00:00
|
|
|
|
|
|
|
main()
|