Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ee7e15

Browse files
committed
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...).
1 parent e1b4d7c commit 9ee7e15

File tree

6 files changed

+1007
-144
lines changed

6 files changed

+1007
-144
lines changed

Demo/sgi/video/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ Vtime.py (unrelated to vtime!!!) Copy a video file,
100100
manipulating the time codes (e.g. faster/slower, or
101101
regenerate time codes, or drop frames too close apart)
102102

103+
Vedit.py interactive video editing program
104+
105+
Viewer.py two viewer classes used by Vedit
106+
103107

104108
The following are C programs, either for efficiency or because they
105109
need to link with a C library:

Demo/sgi/video/VFile.py

Lines changed: 139 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,138 @@ def conv_rgb8(rgb,d1,d2):
5252
# xorigin, yorigin
5353
# fallback
5454

55-
class VinFile:
55+
56+
57+
# XXX it's a total mess now -- VFile is a new base class
58+
# XXX to support common functionality (e.g. showframe)
59+
60+
class VFile:
61+
62+
#
63+
# getinfo returns all info pertaining to a film. The returned tuple
64+
# can be passed to VoutFile.setinfo()
65+
#
66+
def getinfo(self):
67+
return (self.format, self.width, self.height, self.packfactor,\
68+
self.c0bits, self.c1bits, self.c2bits, self.offset, \
69+
self.chrompack)
70+
71+
# reopen() raises Error if the header is bad (which can only
72+
# happen if the file was written to since opened).
73+
74+
def reopen(self):
75+
self.fp.seek(0)
76+
x = self.initfp(self.fp, self.filename)
77+
78+
def setconvcolor(self):
79+
try:
80+
self.convcolor = eval('conv_'+self.format)
81+
except:
82+
raise Error, \
83+
self.filename + ': unknown colorsys ' + self.format
84+
85+
def showframe(self, data, chromdata):
86+
w, h, pf = self.width, self.height, self.packfactor
87+
if not self.colormapinited:
88+
self.initcolormap()
89+
factor = self.magnify
90+
if pf: factor = factor * pf
91+
if chromdata and not self.skipchrom:
92+
cp = self.chrompack
93+
cw = (w+cp-1)/cp
94+
ch = (h+cp-1)/cp
95+
gl.rectzoom(factor*cp, factor*cp)
96+
gl.pixmode(GL.PM_SIZE, 16)
97+
gl.writemask(self.mask - ((1 << self.c0bits) - 1))
98+
gl.lrectwrite(self.xorigin, self.yorigin, \
99+
self.xorigin + cw - 1, self.yorigin + ch - 1, \
100+
chromdata)
101+
#
102+
if pf:
103+
gl.writemask((1 << self.c0bits) - 1)
104+
gl.pixmode(GL.PM_SIZE, 8)
105+
gl.rectzoom(factor, factor)
106+
w = w/pf
107+
h = h/pf
108+
gl.lrectwrite(self.xorigin, self.yorigin, \
109+
self.xorigin + w - 1, self.yorigin + h - 1, data)
110+
111+
def initcolormap(self):
112+
self.colormapinited = 1
113+
if self.format == 'rgb':
114+
gl.RGBmode()
115+
gl.gconfig()
116+
gl.RGBcolor(200, 200, 200)
117+
gl.clear()
118+
return
119+
gl.cmode()
120+
gl.gconfig()
121+
self.skipchrom = 0
122+
if not self.quiet:
123+
sys.stderr.write('Initializing color map...')
124+
self.initcmap()
125+
if not self.quiet:
126+
sys.stderr.write(' Done.\n')
127+
if self.offset == 0:
128+
gl.color(0x800)
129+
gl.clear()
130+
self.mask = 0x7ff
131+
else:
132+
self.mask = 0xfff
133+
gl.clear()
134+
135+
136+
def initcmap(self):
137+
maxbits = gl.getgdesc(GL.GD_BITS_NORM_SNG_CMODE)
138+
if maxbits > 11:
139+
maxbits = 11
140+
c0bits, c1bits, c2bits = self.c0bits, self.c1bits, self.c2bits
141+
if c0bits+c1bits+c2bits > maxbits:
142+
if self.fallback and c0bits < maxbits:
143+
# Cannot display film in this mode, use mono
144+
self.skipchrom = 1
145+
c1bits = c2bits = 0
146+
self.convcolor = conv_grey
147+
else:
148+
raise Error, 'Sorry, '+`maxbits`+ \
149+
' bits max on this machine'
150+
maxc0 = 1 << c0bits
151+
maxc1 = 1 << c1bits
152+
maxc2 = 1 << c2bits
153+
if self.offset == 0 and maxbits == 11:
154+
offset = 2048
155+
else:
156+
offset = self.offset
157+
if maxbits <> 11:
158+
offset = offset & ((1<<maxbits)-1)
159+
#for i in range(512, MAXMAP):
160+
# gl.mapcolor(i, 0, 0, 0)
161+
#void = gl.qtest() # Should be gl.gflush()
162+
for c0 in range(maxc0):
163+
c0v = c0/float(maxc0-1)
164+
for c1 in range(maxc1):
165+
if maxc1 == 1:
166+
c1v = 0
167+
else:
168+
c1v = c1/float(maxc1-1)
169+
for c2 in range(maxc2):
170+
if maxc2 == 1:
171+
c2v = 0
172+
else:
173+
c2v = c2/float(maxc2-1)
174+
index = offset + c0 + (c1<<c0bits) + \
175+
(c2 << (c0bits+c1bits))
176+
rv, gv, bv = self.convcolor( \
177+
c0v, c1v, c2v)
178+
r, g, b = int(rv*255.0), \
179+
int(gv*255.0), int(bv*255.0)
180+
if index < MAXMAP:
181+
gl.mapcolor(index, r, g, b)
182+
void = gl.gflush()
183+
184+
185+
186+
class VinFile(VFile):
56187

57188
# init() and initfp() raise Error if the header is bad.
58189
# init() raises whatever open() raises if the file can't be opened.
@@ -122,11 +253,7 @@ def initfp(self, fp, filename):
122253
raise Error, \
123254
self.filename + ': bad 3.0 color info'
124255

125-
try:
126-
self.convcolor = eval('conv_'+self.format)
127-
except:
128-
raise Error, \
129-
self.filename + ': unknown colorsys ' + self.format
256+
self.setconvcolor()
130257
#
131258
line = self.fp.readline()
132259
try:
@@ -162,23 +289,6 @@ def close(self):
162289
self.fp.close()
163290
self.fp = None
164291

165-
166-
#
167-
# getinfo returns all info pertaining to a film. The returned tuple
168-
# can be passed to VoutFile.setinfo()
169-
#
170-
def getinfo(self):
171-
return (self.format, self.width, self.height, self.packfactor,\
172-
self.c0bits, self.c1bits, self.c2bits, self.offset, \
173-
self.chrompack)
174-
175-
# reopen() raises Error if the header is bad (which can only
176-
# happen if the file was written to since opened).
177-
178-
def reopen(self):
179-
self.fp.seek(0)
180-
x = self.initfp(self.fp, self.filename)
181-
182292
def rewind(self):
183293
if self.hascache:
184294
self.frameno = 0
@@ -270,105 +380,6 @@ def shownextframe(self):
270380
self.showframe(data, chromdata)
271381
return time
272382

273-
def showframe(self, data, chromdata):
274-
w, h, pf = self.width, self.height, self.packfactor
275-
if not self.colormapinited:
276-
self.initcolormap()
277-
factor = self.magnify
278-
if pf: factor = factor * pf
279-
if chromdata and not self.skipchrom:
280-
cp = self.chrompack
281-
cw = (w+cp-1)/cp
282-
ch = (h+cp-1)/cp
283-
gl.rectzoom(factor*cp, factor*cp)
284-
gl.pixmode(GL.PM_SIZE, 16)
285-
gl.writemask(self.mask - ((1 << self.c0bits) - 1))
286-
gl.lrectwrite(self.xorigin, self.yorigin, \
287-
self.xorigin + cw - 1, self.yorigin + ch - 1, \
288-
chromdata)
289-
#
290-
if pf:
291-
gl.writemask((1 << self.c0bits) - 1)
292-
gl.pixmode(GL.PM_SIZE, 8)
293-
gl.rectzoom(factor, factor)
294-
w = w/pf
295-
h = h/pf
296-
gl.lrectwrite(self.xorigin, self.yorigin, \
297-
self.xorigin + w - 1, self.yorigin + h - 1, data)
298-
299-
def initcolormap(self):
300-
self.colormapinited = 1
301-
if self.format == 'rgb':
302-
gl.RGBmode()
303-
gl.gconfig()
304-
gl.RGBcolor(200, 200, 200)
305-
gl.clear()
306-
return
307-
gl.cmode()
308-
gl.gconfig()
309-
self.skipchrom = 0
310-
if not self.quiet:
311-
sys.stderr.write('Initializing color map...')
312-
self.initcmap()
313-
if not self.quiet:
314-
sys.stderr.write(' Done.\n')
315-
if self.offset == 0:
316-
gl.color(0x800)
317-
gl.clear()
318-
self.mask = 0x7ff
319-
else:
320-
self.mask = 0xfff
321-
gl.clear()
322-
323-
324-
def initcmap(self):
325-
maxbits = gl.getgdesc(GL.GD_BITS_NORM_SNG_CMODE)
326-
if maxbits > 11:
327-
maxbits = 11
328-
c0bits, c1bits, c2bits = self.c0bits, self.c1bits, self.c2bits
329-
if c0bits+c1bits+c2bits > maxbits:
330-
if self.fallback and c0bits < maxbits:
331-
# Cannot display film in this mode, use mono
332-
self.skipchrom = 1
333-
c1bits = c2bits = 0
334-
self.convcolor = conv_grey
335-
else:
336-
raise Error, 'Sorry, '+`maxbits`+ \
337-
' bits max on this machine'
338-
maxc0 = 1 << c0bits
339-
maxc1 = 1 << c1bits
340-
maxc2 = 1 << c2bits
341-
if self.offset == 0 and maxbits == 11:
342-
offset = 2048
343-
else:
344-
offset = self.offset
345-
if maxbits <> 11:
346-
offset = offset & ((1<<maxbits)-1)
347-
#for i in range(512, MAXMAP):
348-
# gl.mapcolor(i, 0, 0, 0)
349-
#void = gl.qtest() # Should be gl.gflush()
350-
for c0 in range(maxc0):
351-
c0v = c0/float(maxc0-1)
352-
for c1 in range(maxc1):
353-
if maxc1 == 1:
354-
c1v = 0
355-
else:
356-
c1v = c1/float(maxc1-1)
357-
for c2 in range(maxc2):
358-
if maxc2 == 1:
359-
c2v = 0
360-
else:
361-
c2v = c2/float(maxc2-1)
362-
index = offset + c0 + (c1<<c0bits) + \
363-
(c2 << (c0bits+c1bits))
364-
rv, gv, bv = self.convcolor( \
365-
c0v, c1v, c2v)
366-
r, g, b = int(rv*255.0), \
367-
int(gv*255.0), int(bv*255.0)
368-
if index < MAXMAP:
369-
gl.mapcolor(index, r, g, b)
370-
void = gl.gflush()
371-
372383
#
373384
# A set of routines to grab images from windows
374385
#
@@ -417,7 +428,7 @@ def grab_hsv(w, h, pf):
417428
# Notably it will accept almost any garbage and write it to the video
418429
# output file
419430
#
420-
class VoutFile:
431+
class VoutFile(VFile):
421432
def init(self, filename):
422433
if filename == '-':
423434
return self.initfp(sys.stdout, filename)
@@ -434,21 +445,21 @@ def initfp(self, fp, filename):
434445
self.offset = 0
435446
self.chrompack = 0
436447
self.headerwritten = 0
448+
self.quiet = 0
449+
self.magnify = 1
450+
self.setconvcolor()
451+
self.xorigin = self.yorigin = 0
437452
return self
438453

439454
def close(self):
440455
self.fp.close()
441456
x = self.initfp(None, None)
442457

443-
def getinfo(self):
444-
return (self.format, self.width, self.height, self.packfactor,\
445-
self.c0bits, self.c1bits, self.c2bits, self.offset, \
446-
self.chrompack)
447-
448458
def setinfo(self, values):
449459
self.format, self.width, self.height, self.packfactor,\
450460
self.c0bits, self.c1bits, self.c2bits, self.offset, \
451461
self.chrompack = values
462+
self.setconvcolor()
452463

453464
def writeheader(self):
454465
self.headerwritten = 1

0 commit comments

Comments
 (0)