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

Skip to content

Commit 4df20fa

Browse files
committed
New tool Vfix: truncate the right edge of 'grey' type images to make
the scanline width a multiple of 4. VFile: use gl.gversion() to distinguish 4.0.1 and 4.0.5 Indigos; truncate width and height to multiples of packfactor. Vinfo: add -t to descriptive comment; print '!' after packfactor for files that should be fixed with Vfix.
1 parent 384f248 commit 4df20fa

3 files changed

Lines changed: 114 additions & 11 deletions

File tree

Demo/sgi/video/VFile.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,11 @@ def showpartframe(self, data, chromdata, (x,y,w,h)):
309309
data, width, height, bytes = jpeg.decompress(data)
310310
if self.format == 'jpeg':
311311
b = 4
312+
p = 1
312313
else:
313314
b = 1
314-
width, height = width*pf, height*pf
315-
if (width, height, bytes) <> (w, h, b):
315+
p = pf
316+
if (width, height, bytes) <> (w/p, h/p, b):
316317
raise Error, 'jpeg data has wrong size'
317318
if not self.colormapinited:
318319
self.initcolormap()
@@ -359,14 +360,15 @@ def initcolormap(self):
359360
gl.RGBcolor(200, 200, 200) # XXX rather light grey
360361
gl.clear()
361362
return
362-
## XXX Unfortunately this doesn't work on IRIX 4.0.1...
363-
## if self.format == 'rgb8' and is_entry_indigo():
364-
## gl.RGBmode()
365-
## gl.gconfig()
366-
## gl.RGBcolor(200, 200, 200) # XXX rather light grey
367-
## gl.clear()
368-
## gl.pixmode(GL.PM_SIZE, 8)
369-
## return
363+
# This only works on an Entry-level Indigo from IRIX 4.0.5
364+
if self.format == 'rgb8' and is_entry_indigo() and \
365+
gl.gversion() == 'GL4DLG-4.0.': # Note trailing '.'!
366+
gl.RGBmode()
367+
gl.gconfig()
368+
gl.RGBcolor(200, 200, 200) # XXX rather light grey
369+
gl.clear()
370+
gl.pixmode(GL.PM_SIZE, 8)
371+
return
370372
gl.cmode()
371373
gl.gconfig()
372374
self.skipchrom = 0
@@ -571,6 +573,9 @@ def readfileheader(fp, filename):
571573
packfactor = 2
572574
else:
573575
raise Error, filename + ': Bad (w,h,pf) info'
576+
if packfactor > 1:
577+
width = (width / packfactor) * packfactor
578+
height = (height / packfactor) * packfactor
574579
#
575580
# Return (version, values)
576581
#

Demo/sgi/video/Vfix.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/ufs/guido/bin/sgi/python
2+
3+
# Copy a video file, fixing the line width to be a multiple of 4
4+
5+
6+
# Usage:
7+
#
8+
# Vfix [infile [outfile]]
9+
10+
11+
# Options:
12+
#
13+
# infile : input file (default film.video)
14+
# outfile : output file (default out.video)
15+
16+
17+
import sys
18+
import imageop
19+
sys.path.append('/ufs/guido/src/video')
20+
import VFile
21+
22+
23+
# Main program -- mostly command line parsing
24+
25+
def main():
26+
args = sys.argv[1:]
27+
if len(args) < 1:
28+
args.append('film.video')
29+
if len(args) < 2:
30+
args.append('out.video')
31+
if len(args) > 2:
32+
sys.stderr.write('usage: Vfix [infile [outfile]]\n')
33+
sys.exit(2)
34+
sts = process(args[0], args[1])
35+
sys.exit(sts)
36+
37+
38+
# Copy one file to another
39+
40+
def process(infilename, outfilename):
41+
try:
42+
vin = VFile.BasicVinFile().init(infilename)
43+
except IOError, msg:
44+
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
45+
return 1
46+
except VFile.Error, msg:
47+
sys.stderr.write(msg + '\n')
48+
return 1
49+
except EOFError:
50+
sys.stderr.write(infilename + ': EOF in video file\n')
51+
return 1
52+
53+
try:
54+
vout = VFile.BasicVoutFile().init(outfilename)
55+
except IOError, msg:
56+
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
57+
return 1
58+
59+
info = vin.getinfo()
60+
if info[0] <> 'grey':
61+
sys.stderr.write('Vfix: input not in grey format\n')
62+
return 1
63+
vout.setinfo(info)
64+
inwidth, height = vin.getsize()
65+
pf = vin.packfactor
66+
if (inwidth/pf)%4 == 0:
67+
sys.stderr.write('Vfix: fix not necessary\n')
68+
return 1
69+
outwidth = (inwidth/pf/4)*4*pf
70+
print 'inwidth =', inwidth, 'outwidth =', outwidth
71+
vout.setsize(outwidth, height)
72+
vout.writeheader()
73+
n = 0
74+
try:
75+
while 1:
76+
t, data, cdata = vin.getnextframe()
77+
n = n + 1
78+
sys.stderr.write('Frame ' + `n` + '...')
79+
data = imageop.crop(data, 1, inwidth/pf, height/pf, \
80+
0, 0, outwidth/pf-1, height/pf-1)
81+
vout.writeframe(t, data, None)
82+
sys.stderr.write('\n')
83+
except EOFError:
84+
pass
85+
return 0
86+
87+
88+
# Don't forget to call the main program
89+
90+
main()

Demo/sgi/video/Vinfo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
# Usage:
77
#
8-
# Vinfo [-d] [-q] [-s] [file] ...
8+
# Vinfo [-d] [-q] [-s] [-t] [file] ...
99

1010

1111
# Options:
1212
#
1313
# -d : print deltas between frames instead of frame times
1414
# -q : quick: don't read the frames
1515
# -s : don't print times (but do count frames and print the total)
16+
# -t : terse (one line/file, implies -s)
1617
# file ... : file(s) to inspect; default film.video
1718

1819

@@ -86,6 +87,13 @@ def process(filename):
8687
print string.ljust(vin.format, 8),
8788
print string.rjust(`vin.width`, 4),
8889
print string.rjust(`vin.height`, 4),
90+
s = string.rjust(`vin.packfactor`, 2)
91+
if vin.packfactor and vin.format not in ('rgb', 'jpeg') and \
92+
(vin.width/vin.packfactor) % 4 <> 0:
93+
s = s + '!'
94+
else:
95+
s = s + ' '
96+
print s,
8997
sys.stdout.flush()
9098
else:
9199
vin.printinfo()

0 commit comments

Comments
 (0)