Added reopen() to VinFile with semantics of old rewind(); rewind() now
saves the cache. Added getinfo() to VoutFile. Fixed writing of 'grey' file header. Added quiet parameter. Adapted to new syntax.
This commit is contained in:
parent
dfb61fa2cb
commit
9a35d57ab2
|
@ -32,6 +32,7 @@ def conv_rgb8(rgb,d1,d2):
|
||||||
# It has the following methods:
|
# It has the following methods:
|
||||||
# init(filename)
|
# init(filename)
|
||||||
# initfp(fp, filename)
|
# initfp(fp, filename)
|
||||||
|
# reopen()
|
||||||
# rewind()
|
# rewind()
|
||||||
# getnextframe()
|
# getnextframe()
|
||||||
# skipnextframe()
|
# skipnextframe()
|
||||||
|
@ -69,6 +70,7 @@ class VinFile:
|
||||||
self.skipchrom = 0
|
self.skipchrom = 0
|
||||||
self.fp = fp
|
self.fp = fp
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.quiet = 0
|
||||||
#
|
#
|
||||||
line = self.fp.readline()
|
line = self.fp.readline()
|
||||||
if line == 'CMIF video 1.0\n':
|
if line == 'CMIF video 1.0\n':
|
||||||
|
@ -170,13 +172,19 @@ class VinFile:
|
||||||
self.c0bits, self.c1bits, self.c2bits, self.offset, \
|
self.c0bits, self.c1bits, self.c2bits, self.offset, \
|
||||||
self.chrompack)
|
self.chrompack)
|
||||||
|
|
||||||
# rewind() raises Error if the header is bad (which can only
|
# reopen() raises Error if the header is bad (which can only
|
||||||
# happen if the file was written to since opened).
|
# happen if the file was written to since opened).
|
||||||
|
|
||||||
def rewind(self):
|
def reopen(self):
|
||||||
self.fp.seek(0)
|
self.fp.seek(0)
|
||||||
x = self.initfp(self.fp, self.filename)
|
x = self.initfp(self.fp, self.filename)
|
||||||
|
|
||||||
|
def rewind(self):
|
||||||
|
if self.hascache:
|
||||||
|
self.frameno = 0
|
||||||
|
else:
|
||||||
|
self.reopen()
|
||||||
|
|
||||||
def position(self):
|
def position(self):
|
||||||
if self.frameno >= len(self.framecache):
|
if self.frameno >= len(self.framecache):
|
||||||
raise EOFError
|
raise EOFError
|
||||||
|
@ -191,7 +199,7 @@ class VinFile:
|
||||||
data, chromdata = self.getnextframedata(size, chromsize)
|
data, chromdata = self.getnextframedata(size, chromsize)
|
||||||
return time, data, chromdata
|
return time, data, chromdata
|
||||||
|
|
||||||
def getnextframedata(self, (size, chromsize)):
|
def getnextframedata(self, size, chromsize):
|
||||||
if self.hascache:
|
if self.hascache:
|
||||||
self.position()
|
self.position()
|
||||||
self.frameno = self.frameno + 1
|
self.frameno = self.frameno + 1
|
||||||
|
@ -210,7 +218,7 @@ class VinFile:
|
||||||
self.skipnextframedata(size, chromsize)
|
self.skipnextframedata(size, chromsize)
|
||||||
return time
|
return time
|
||||||
|
|
||||||
def skipnextframedata(self, (size, chromsize)):
|
def skipnextframedata(self, size, chromsize):
|
||||||
if self.hascache:
|
if self.hascache:
|
||||||
self.frameno = self.frameno + 1
|
self.frameno = self.frameno + 1
|
||||||
return
|
return
|
||||||
|
@ -262,7 +270,7 @@ class VinFile:
|
||||||
self.showframe(data, chromdata)
|
self.showframe(data, chromdata)
|
||||||
return time
|
return time
|
||||||
|
|
||||||
def showframe(self, (data, chromdata)):
|
def showframe(self, data, chromdata):
|
||||||
w, h, pf = self.width, self.height, self.packfactor
|
w, h, pf = self.width, self.height, self.packfactor
|
||||||
if not self.colormapinited:
|
if not self.colormapinited:
|
||||||
self.initcolormap()
|
self.initcolormap()
|
||||||
|
@ -297,8 +305,10 @@ class VinFile:
|
||||||
gl.cmode()
|
gl.cmode()
|
||||||
gl.gconfig()
|
gl.gconfig()
|
||||||
self.skipchrom = 0
|
self.skipchrom = 0
|
||||||
|
if not self.quiet:
|
||||||
sys.stderr.write('Initializing color map...')
|
sys.stderr.write('Initializing color map...')
|
||||||
self.initcmap()
|
self.initcmap()
|
||||||
|
if not self.quiet:
|
||||||
sys.stderr.write(' Done.\n')
|
sys.stderr.write(' Done.\n')
|
||||||
if self.offset == 0:
|
if self.offset == 0:
|
||||||
gl.color(0x800)
|
gl.color(0x800)
|
||||||
|
@ -428,6 +438,11 @@ class VoutFile:
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
x = self.initfp(None, None)
|
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):
|
def setinfo(self, values):
|
||||||
self.format, self.width, self.height, self.packfactor,\
|
self.format, self.width, self.height, self.packfactor,\
|
||||||
self.c0bits, self.c1bits, self.c2bits, self.offset, \
|
self.c0bits, self.c1bits, self.c2bits, self.offset, \
|
||||||
|
@ -443,7 +458,7 @@ class VoutFile:
|
||||||
if self.format == 'rgb':
|
if self.format == 'rgb':
|
||||||
data = ('rgb', 0)
|
data = ('rgb', 0)
|
||||||
elif self.format == 'grey':
|
elif self.format == 'grey':
|
||||||
data = ('grey', 0)
|
data = ('grey', self.c0bits)
|
||||||
else:
|
else:
|
||||||
data = (self.format, (self.c0bits, self.c1bits, \
|
data = (self.format, (self.c0bits, self.c1bits, \
|
||||||
self.c2bits, self.chrompack, self.offset))
|
self.c2bits, self.chrompack, self.offset))
|
||||||
|
|
Loading…
Reference in New Issue