]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Vrec.py, Vrecb.py:
authorGuido van Rossum <guido@python.org>
Thu, 25 Feb 1993 16:10:16 +0000 (16:10 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 25 Feb 1993 16:10:16 +0000 (16:10 +0000)
 - call v.SetParam() after v.BindGLWindow()
 - turn of dithering in mono/grey mode
 - use prefposition to place the top left corner at (150, 150)
   (so that the video remains visible during recording)
 - default width is 256
Vcopy.py: correct typos; more verbose output.
OldVcopy.py: new name for Jack's old grabbing Vcopy.py.
Vstat.py: print values of all video parameters.

Demo/sgi/video/OldVcopy.py [new file with mode: 0755]
Demo/sgi/video/README
Demo/sgi/video/Vcopy.py
Demo/sgi/video/Vrec.py
Demo/sgi/video/Vrecb.py
Demo/sgi/video/Vstat.py [new file with mode: 0755]

diff --git a/Demo/sgi/video/OldVcopy.py b/Demo/sgi/video/OldVcopy.py
new file mode 100755 (executable)
index 0000000..63bbf71
--- /dev/null
@@ -0,0 +1,148 @@
+#! /ufs/guido/bin/sgi/python
+
+# Copy a video file, interactively, frame-by-frame.
+
+import sys
+import getopt
+from gl import *
+from DEVICE import *
+import VFile
+import VGrabber
+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'
+
+class GrabbingVoutFile(VFile.VoutFile, VGrabber.VGrabber):
+       pass
+
+def main():
+       foreground()
+       try:
+               opts, args = getopt.getopt(sys.argv[1:], 't:am:d')
+       except getopt.error, msg:
+               print msg
+               usage()
+       if len(args) <> 2:
+               usage()
+       [ifile, ofile] = args
+       print 'open film ', ifile
+       ifilm = VFile.VinFile().init(ifile)
+       print 'open output ', ofile
+       ofilm = GrabbingVoutFile().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:
+                                       try:
+                                               data, cdata = ofilm.grabframe()
+                                       except VFile.Error, msg:
+                                               print msg
+                                               break
+                               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()
index 01a01d21b5bb3ead0695b6a8783797bc49c7bc77..6abe698795b8c71499f9372b1e822bf706087bf2 100644 (file)
@@ -4,6 +4,11 @@ CMIF video tools
 This directory contains Python and C programs to manipulate files
 containing digitized video in the "CMIF video format".
 
+An introduction to using the basic tools is in the file "video.doc".
+
+A description of the video file format is in the file "cmif-film.ms"
+(troff/nroff -ms input).
+
 
 History
 -------
index f9c954a3798d68836d92c4688d0f55b504e0d707..e8d4f5523018ef9e48aa534335c29be65031cc9f 100755 (executable)
@@ -166,6 +166,7 @@ def process(infilename, outfilename):
                sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
                return 1
 
+       print '=== input file ==='
        vin.printinfo()
 
        vout.setinfo(vin.getinfo())
@@ -187,7 +188,6 @@ def process(infilename, outfilename):
                if not ypf: ypf = vout.ypf
                newpf = (xpf, ypf)
                vout.setpf(newpf)
-               scale = 1
 
        if newwidth and newheight:
                scale = 1
@@ -221,6 +221,7 @@ def process(infilename, outfilename):
        newwidth = newwidth / vout.xpf
        newheight = newheight / vout.ypf
 
+       print '=== output file ==='
        vout.printinfo()
        vout.writeheader()
 
@@ -251,13 +252,14 @@ def process(infilename, outfilename):
                                  inwidth, inheight, newwidth, newheight)
                if flip:
                        x0, y0 = 0, 0
-                       x1, y1 = newwidth-1, neheight-1
+                       x1, y1 = newwidth-1, newheight-1
                        if vin.upside_down <> vout.upside_down:
                                y1, y0 = y0, y1
                        if vin.mirror_image <> vout.mirror_image:
                                x1, x0 = x0, x1
                        data = imageop.crop(data, vout.bpp/8, \
                                  newwidth, newheight, x0, y0, x1, y1)
+               print 'Writing frame', nout
                vout.writeframe(tout, data, cdata)
                nout = nout + 1
 
index e90a4bd030daf08af7d6a76e9a55305fb4fa35dc..7b95aee11da3d9d90e75c495eeb2c79fd18d6370 100755 (executable)
@@ -20,7 +20,7 @@ def usage():
        print '-r rate       : capture 1 out of every "rate" frames', \
                             '(default and min 2)'
        print '-w width      : initial window width', \
-                            '(default interactive placement)'
+                             '(default 256, use 0 for interactive placement)'
        print '-n            : Don\'t write to file, only timing info'
        print '-d            : drop fields if needed'
        print '-g bits       : greyscale (2, 4 or 8 bits)'
@@ -184,7 +184,12 @@ def main():
        gl.keepaspect(x, y)
        gl.stepunit(8, 6)
        if width:
-               gl.prefsize(width, width*3/4)
+               height = width*3/4
+               x1 = 150
+               x2 = x1 + width-1
+               y2 = 768-150
+               y1 = y2-height+1
+               gl.prefposition(x1, x2, y1, y2)
        win = gl.winopen(filename)
        if width:
                gl.maxsize(x, y)
@@ -201,12 +206,13 @@ def main():
        else:
                param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
        if mono or grey:
-               param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1]
+               param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \
+                              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)
+       v.SetParam(param)
 
        gl.qdevice(DEVICE.LEFTMOUSE)
        gl.qdevice(DEVICE.WINQUIT)
index 43a5ddf3a706f063613c4187cb995e245371af57..ef7bc37c135258b4e1216df08dd5477ba9442f18 100755 (executable)
@@ -1,4 +1,3 @@
-#! /ufs/guido/bin/sgi/python-405
 #! /ufs/guido/bin/sgi/python
 
 # Capture a CMIF movie using the Indigo video library and board in burst mode
@@ -41,7 +40,7 @@ def usage():
        print '-r rate       : capture 1 out of every "rate" frames', \
                             '(default and min 1)'
        print '-w width      : initial window width', \
-                            '(default interactive placement)'
+                             '(default 256, use 0 for interactive placement)'
        print '-d            : drop fields if needed'
        print '-g bits       : greyscale (2, 4 or 8 bits)'
        print '-G            : 2-bit greyscale dithered'
@@ -69,7 +68,7 @@ def main():
        format = SV.RGB8_FRAMES
        audio = 0
        rate = 1
-       width = 0
+       width = 256
        drop = 0
        mono = 0
        grey = 0
@@ -167,7 +166,12 @@ def main():
        gl.keepaspect(x, y)
        gl.stepunit(8, 6)
        if width:
-               gl.prefsize(width, width*3/4)
+               height = width*3/4
+               x1 = 150
+               x2 = x1 + width-1
+               y2 = 768-150
+               y1 = y2-height+1
+               gl.prefposition(x1, x2, y1, y2)
        win = gl.winopen(filename)
        if width:
                gl.maxsize(x, y)
@@ -184,12 +188,13 @@ def main():
        else:
                param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
        if mono or grey:
-               param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1]
+               param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \
+                              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)
+       v.SetParam(param)
 
        gl.qdevice(DEVICE.LEFTMOUSE)
        gl.qdevice(DEVICE.WINQUIT)
diff --git a/Demo/sgi/video/Vstat.py b/Demo/sgi/video/Vstat.py
new file mode 100755 (executable)
index 0000000..cc0ecfb
--- /dev/null
@@ -0,0 +1,23 @@
+#! /ufs/guido/bin/sgi/python
+
+# Print the value of all video parameters
+
+import sys
+import sv, SV
+
+def main():
+       v = sv.OpenVideo()
+       for name in dir(SV):
+               const = getattr(SV, name)
+               if type(const) is type(0):
+                       sys.stdout.flush()
+                       params = [const, 0]
+                       try:
+                               v.GetParam(params)
+                       except sv.error, msg:
+##                             print name, msg
+                               continue
+                       print name, params
+
+main()
+