summaryrefslogtreecommitdiffstats
path: root/Demo/sgi/video/VFile.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-25 12:29:30 (GMT)
committerGuido van Rossum <guido@python.org>1992-08-25 12:29:30 (GMT)
commit9ee7e159663ff81b3651a556dfde73574724ac26 (patch)
tree28988ccd34af9a321471b02e0b348ff4eb0945b9 /Demo/sgi/video/VFile.py
parente1b4d7ce14c3463c14a188cb86eb1e267e66c254 (diff)
downloadcpython-9ee7e159663ff81b3651a556dfde73574724ac26.zip
cpython-9ee7e159663ff81b3651a556dfde73574724ac26.tar.gz
cpython-9ee7e159663ff81b3651a556dfde73574724ac26.tar.bz2
Created Vedit.py, the video editor. This uses the classes in Viewer.py.
Viewer.py in turn requires changes to VFile.py (unfortunately that file is now a complete mess...).
Diffstat (limited to 'Demo/sgi/video/VFile.py')
-rwxr-xr-xDemo/sgi/video/VFile.py267
1 files changed, 139 insertions, 128 deletions
diff --git a/Demo/sgi/video/VFile.py b/Demo/sgi/video/VFile.py
index 17f677f..b16b2ab 100755
--- a/Demo/sgi/video/VFile.py
+++ b/Demo/sgi/video/VFile.py
@@ -52,7 +52,138 @@ def conv_rgb8(rgb,d1,d2):
# xorigin, yorigin
# fallback
-class VinFile:
+
+
+# XXX it's a total mess now -- VFile is a new base class
+# XXX to support common functionality (e.g. showframe)
+
+class VFile:
+
+ #
+ # getinfo returns all info pertaining to a film. The returned tuple
+ # can be passed to VoutFile.setinfo()
+ #
+ def getinfo(self):
+ return (self.format, self.width, self.height, self.packfactor,\
+ self.c0bits, self.c1bits, self.c2bits, self.offset, \
+ self.chrompack)
+
+ # reopen() raises Error if the header is bad (which can only
+ # happen if the file was written to since opened).
+
+ def reopen(self):
+ self.fp.seek(0)
+ x = self.initfp(self.fp, self.filename)
+
+ def setconvcolor(self):
+ try:
+ self.convcolor = eval('conv_'+self.format)
+ except:
+ raise Error, \
+ self.filename + ': unknown colorsys ' + self.format
+
+ def showframe(self, data, chromdata):
+ w, h, pf = self.width, self.height, self.packfactor
+ if not self.colormapinited:
+ self.initcolormap()
+ factor = self.magnify
+ if pf: factor = factor * pf
+ if chromdata and not self.skipchrom:
+ cp = self.chrompack
+ cw = (w+cp-1)/cp
+ ch = (h+cp-1)/cp
+ gl.rectzoom(factor*cp, factor*cp)
+ gl.pixmode(GL.PM_SIZE, 16)
+ gl.writemask(self.mask - ((1 << self.c0bits) - 1))
+ gl.lrectwrite(self.xorigin, self.yorigin, \
+ self.xorigin + cw - 1, self.yorigin + ch - 1, \
+ chromdata)
+ #
+ if pf:
+ gl.writemask((1 << self.c0bits) - 1)
+ gl.pixmode(GL.PM_SIZE, 8)
+ gl.rectzoom(factor, factor)
+ w = w/pf
+ h = h/pf
+ gl.lrectwrite(self.xorigin, self.yorigin, \
+ self.xorigin + w - 1, self.yorigin + h - 1, data)
+
+ def initcolormap(self):
+ self.colormapinited = 1
+ if self.format == 'rgb':
+ gl.RGBmode()
+ gl.gconfig()
+ gl.RGBcolor(200, 200, 200)
+ gl.clear()
+ return
+ gl.cmode()
+ gl.gconfig()
+ self.skipchrom = 0
+ if not self.quiet:
+ sys.stderr.write('Initializing color map...')
+ self.initcmap()
+ if not self.quiet:
+ sys.stderr.write(' Done.\n')
+ if self.offset == 0:
+ gl.color(0x800)
+ gl.clear()
+ self.mask = 0x7ff
+ else:
+ self.mask = 0xfff
+ gl.clear()
+
+
+ def initcmap(self):
+ maxbits = gl.getgdesc(GL.GD_BITS_NORM_SNG_CMODE)
+ if maxbits > 11:
+ maxbits = 11
+ c0bits, c1bits, c2bits = self.c0bits, self.c1bits, self.c2bits
+ if c0bits+c1bits+c2bits > maxbits:
+ if self.fallback and c0bits < maxbits:
+ # Cannot display film in this mode, use mono
+ self.skipchrom = 1
+ c1bits = c2bits = 0
+ self.convcolor = conv_grey
+ else:
+ raise Error, 'Sorry, '+`maxbits`+ \
+ ' bits max on this machine'
+ maxc0 = 1 << c0bits
+ maxc1 = 1 << c1bits
+ maxc2 = 1 << c2bits
+ if self.offset == 0 and maxbits == 11:
+ offset = 2048
+ else:
+ offset = self.offset
+ if maxbits <> 11:
+ offset = offset & ((1<<maxbits)-1)
+ #for i in range(512, MAXMAP):
+ # gl.mapcolor(i, 0, 0, 0)
+ #void = gl.qtest() # Should be gl.gflush()
+ for c0 in range(maxc0):
+ c0v = c0/float(maxc0-1)
+ for c1 in range(maxc1):
+ if maxc1 == 1:
+ c1v = 0
+ else:
+ c1v = c1/float(maxc1-1)
+ for c2 in range(maxc2):
+ if maxc2 == 1:
+ c2v = 0
+ else:
+ c2v = c2/float(maxc2-1)
+ index = offset + c0 + (c1<<c0bits) + \
+ (c2 << (c0bits+c1bits))
+ rv, gv, bv = self.convcolor( \
+ c0v, c1v, c2v)
+ r, g, b = int(rv*255.0), \
+ int(gv*255.0), int(bv*255.0)
+ if index < MAXMAP:
+ gl.mapcolor(index, r, g, b)
+ void = gl.gflush()
+
+
+
+class VinFile(VFile):
# init() and initfp() raise Error if the header is bad.
# init() raises whatever open() raises if the file can't be opened.
@@ -122,11 +253,7 @@ class VinFile:
raise Error, \
self.filename + ': bad 3.0 color info'
- try:
- self.convcolor = eval('conv_'+self.format)
- except:
- raise Error, \
- self.filename + ': unknown colorsys ' + self.format
+ self.setconvcolor()
#
line = self.fp.readline()
try:
@@ -162,23 +289,6 @@ class VinFile:
self.fp.close()
self.fp = None
-
- #
- # getinfo returns all info pertaining to a film. The returned tuple
- # can be passed to VoutFile.setinfo()
- #
- def getinfo(self):
- return (self.format, self.width, self.height, self.packfactor,\
- self.c0bits, self.c1bits, self.c2bits, self.offset, \
- self.chrompack)
-
- # reopen() raises Error if the header is bad (which can only
- # happen if the file was written to since opened).
-
- def reopen(self):
- self.fp.seek(0)
- x = self.initfp(self.fp, self.filename)
-
def rewind(self):
if self.hascache:
self.frameno = 0
@@ -270,105 +380,6 @@ class VinFile:
self.showframe(data, chromdata)
return time
- def showframe(self, data, chromdata):
- w, h, pf = self.width, self.height, self.packfactor
- if not self.colormapinited:
- self.initcolormap()
- factor = self.magnify
- if pf: factor = factor * pf
- if chromdata and not self.skipchrom:
- cp = self.chrompack
- cw = (w+cp-1)/cp
- ch = (h+cp-1)/cp
- gl.rectzoom(factor*cp, factor*cp)
- gl.pixmode(GL.PM_SIZE, 16)
- gl.writemask(self.mask - ((1 << self.c0bits) - 1))
- gl.lrectwrite(self.xorigin, self.yorigin, \
- self.xorigin + cw - 1, self.yorigin + ch - 1, \
- chromdata)
- #
- if pf:
- gl.writemask((1 << self.c0bits) - 1)
- gl.pixmode(GL.PM_SIZE, 8)
- gl.rectzoom(factor, factor)
- w = w/pf
- h = h/pf
- gl.lrectwrite(self.xorigin, self.yorigin, \
- self.xorigin + w - 1, self.yorigin + h - 1, data)
-
- def initcolormap(self):
- self.colormapinited = 1
- if self.format == 'rgb':
- gl.RGBmode()
- gl.gconfig()
- gl.RGBcolor(200, 200, 200)
- gl.clear()
- return
- gl.cmode()
- gl.gconfig()
- self.skipchrom = 0
- if not self.quiet:
- sys.stderr.write('Initializing color map...')
- self.initcmap()
- if not self.quiet:
- sys.stderr.write(' Done.\n')
- if self.offset == 0:
- gl.color(0x800)
- gl.clear()
- self.mask = 0x7ff
- else:
- self.mask = 0xfff
- gl.clear()
-
-
- def initcmap(self):
- maxbits = gl.getgdesc(GL.GD_BITS_NORM_SNG_CMODE)
- if maxbits > 11:
- maxbits = 11
- c0bits, c1bits, c2bits = self.c0bits, self.c1bits, self.c2bits
- if c0bits+c1bits+c2bits > maxbits:
- if self.fallback and c0bits < maxbits:
- # Cannot display film in this mode, use mono
- self.skipchrom = 1
- c1bits = c2bits = 0
- self.convcolor = conv_grey
- else:
- raise Error, 'Sorry, '+`maxbits`+ \
- ' bits max on this machine'
- maxc0 = 1 << c0bits
- maxc1 = 1 << c1bits
- maxc2 = 1 << c2bits
- if self.offset == 0 and maxbits == 11:
- offset = 2048
- else:
- offset = self.offset
- if maxbits <> 11:
- offset = offset & ((1<<maxbits)-1)
- #for i in range(512, MAXMAP):
- # gl.mapcolor(i, 0, 0, 0)
- #void = gl.qtest() # Should be gl.gflush()
- for c0 in range(maxc0):
- c0v = c0/float(maxc0-1)
- for c1 in range(maxc1):
- if maxc1 == 1:
- c1v = 0
- else:
- c1v = c1/float(maxc1-1)
- for c2 in range(maxc2):
- if maxc2 == 1:
- c2v = 0
- else:
- c2v = c2/float(maxc2-1)
- index = offset + c0 + (c1<<c0bits) + \
- (c2 << (c0bits+c1bits))
- rv, gv, bv = self.convcolor( \
- c0v, c1v, c2v)
- r, g, b = int(rv*255.0), \
- int(gv*255.0), int(bv*255.0)
- if index < MAXMAP:
- gl.mapcolor(index, r, g, b)
- void = gl.gflush()
-
#
# A set of routines to grab images from windows
#
@@ -417,7 +428,7 @@ def grab_hsv(w, h, pf):
# Notably it will accept almost any garbage and write it to the video
# output file
#
-class VoutFile:
+class VoutFile(VFile):
def init(self, filename):
if filename == '-':
return self.initfp(sys.stdout, filename)
@@ -434,21 +445,21 @@ class VoutFile:
self.offset = 0
self.chrompack = 0
self.headerwritten = 0
+ self.quiet = 0
+ self.magnify = 1
+ self.setconvcolor()
+ self.xorigin = self.yorigin = 0
return self
def close(self):
self.fp.close()
x = self.initfp(None, None)
- def getinfo(self):
- return (self.format, self.width, self.height, self.packfactor,\
- self.c0bits, self.c1bits, self.c2bits, self.offset, \
- self.chrompack)
-
def setinfo(self, values):
self.format, self.width, self.height, self.packfactor,\
self.c0bits, self.c1bits, self.c2bits, self.offset, \
self.chrompack = values
+ self.setconvcolor()
def writeheader(self):
self.headerwritten = 1