1991-11-04 11:54:22 -04:00
|
|
|
# Copy a video file, interactively, frame-by-frame.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import getopt
|
|
|
|
from gl import *
|
|
|
|
from DEVICE import *
|
1992-03-18 09:04:25 -04:00
|
|
|
import VFile
|
1992-12-14 08:25:21 -04:00
|
|
|
import string
|
|
|
|
import imageop
|
1991-11-04 11:54:22 -04:00
|
|
|
|
|
|
|
def report(time, iframe):
|
|
|
|
print 'Frame', iframe, ': t =', time
|
|
|
|
|
|
|
|
def usage():
|
1992-12-14 08:25:21 -04:00
|
|
|
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')
|
1991-11-04 11:54:22 -04:00
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
def help():
|
|
|
|
print 'Command summary:'
|
|
|
|
print 'n get next image from input'
|
|
|
|
print 'w write current image to output'
|
|
|
|
|
|
|
|
def main():
|
1992-03-18 09:04:25 -04:00
|
|
|
foreground()
|
1992-12-14 08:25:21 -04:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], 't:am:d')
|
1991-11-04 11:54:22 -04:00
|
|
|
if len(args) <> 2:
|
|
|
|
usage()
|
|
|
|
[ifile, ofile] = args
|
1992-03-18 09:04:25 -04:00
|
|
|
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
|
1992-12-14 08:25:21 -04:00
|
|
|
tomono = 0
|
|
|
|
tomonodither = 0
|
1992-03-18 09:04:25 -04:00
|
|
|
for o, a in opts:
|
|
|
|
if o == '-t':
|
|
|
|
ofilm.format = a
|
|
|
|
use_grabber = 1
|
|
|
|
if o == '-a':
|
|
|
|
continuous = 1
|
1992-12-14 08:25:21 -04:00
|
|
|
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'
|
|
|
|
|
1992-03-18 09:04:25 -04:00
|
|
|
ofilm.writeheader()
|
1991-11-04 11:54:22 -04:00
|
|
|
#
|
1992-03-18 09:04:25 -04:00
|
|
|
prefsize(ifilm.width, ifilm.height)
|
|
|
|
w = winopen(ifile)
|
1991-11-04 11:54:22 -04:00
|
|
|
qdevice(KEYBD)
|
|
|
|
qdevice(ESCKEY)
|
|
|
|
qdevice(WINQUIT)
|
|
|
|
qdevice(WINSHUT)
|
1992-03-18 09:04:25 -04:00
|
|
|
print 'qdevice calls done'
|
1991-11-04 11:54:22 -04:00
|
|
|
#
|
|
|
|
help()
|
|
|
|
#
|
1992-03-18 09:04:25 -04:00
|
|
|
time, data, cdata = ifilm.getnextframe()
|
|
|
|
ifilm.showframe(data, cdata)
|
1991-11-04 11:54:22 -04:00
|
|
|
iframe = 1
|
|
|
|
report(time, iframe)
|
|
|
|
#
|
|
|
|
while 1:
|
1992-03-18 09:04:25 -04:00
|
|
|
if continuous:
|
|
|
|
dev = KEYBD
|
|
|
|
else:
|
|
|
|
dev, val = qread()
|
1991-11-04 11:54:22 -04:00
|
|
|
if dev in (ESCKEY, WINQUIT, WINSHUT):
|
|
|
|
break
|
1992-02-11 10:50:22 -04:00
|
|
|
if dev == REDRAW:
|
1991-11-04 11:54:22 -04:00
|
|
|
reshapeviewport()
|
1992-02-11 10:50:22 -04:00
|
|
|
elif dev == KEYBD:
|
1992-03-18 09:04:25 -04:00
|
|
|
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()
|
1992-12-14 08:25:21 -04:00
|
|
|
if tomono:
|
|
|
|
data = imageop.grey2mono(data, \
|
|
|
|
ifilm.width, ifilm.height, \
|
|
|
|
treshold)
|
|
|
|
if tomonodither:
|
|
|
|
data = imageop.dither2mono(data, \
|
|
|
|
ifilm.width, ifilm.height)
|
1992-03-18 09:04:25 -04:00
|
|
|
ofilm.writeframe(time, data, cdata)
|
|
|
|
print 'Frame', iframe, 'written.'
|
|
|
|
if c == 'n' or continuous:
|
1991-11-04 11:54:22 -04:00
|
|
|
try:
|
1992-03-18 09:04:25 -04:00
|
|
|
time,data,cdata = ifilm.getnextframe()
|
|
|
|
ifilm.showframe(data, cdata)
|
1991-11-04 11:54:22 -04:00
|
|
|
iframe = iframe+1
|
|
|
|
report(time, iframe)
|
|
|
|
except EOFError:
|
|
|
|
print 'EOF'
|
1992-03-18 09:04:25 -04:00
|
|
|
if continuous:
|
|
|
|
break
|
1991-11-04 11:54:22 -04:00
|
|
|
ringbell()
|
1992-02-11 10:50:22 -04:00
|
|
|
elif dev == INPUTCHANGE:
|
1991-11-04 11:54:22 -04:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
print '(dev, val) =', (dev, val)
|
1992-03-18 09:04:25 -04:00
|
|
|
ofilm.close()
|
1991-11-04 11:54:22 -04:00
|
|
|
|
|
|
|
main()
|