]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
New tool Vfix: truncate the right edge of 'grey' type images to make
authorGuido van Rossum <guido@python.org>
Tue, 29 Sep 1992 17:07:10 +0000 (17:07 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 29 Sep 1992 17:07:10 +0000 (17:07 +0000)
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.

Demo/sgi/video/VFile.py
Demo/sgi/video/Vfix.py [new file with mode: 0755]
Demo/sgi/video/Vinfo.py

index 12e087ca31146f2b9a96c4d966f0d9d1e2fed551..6443fb66efa98bb3673f5b4d1c418702ddd1dc86 100755 (executable)
@@ -309,10 +309,11 @@ class Displayer(VideoParams):
                        data, width, height, bytes = jpeg.decompress(data)
                        if self.format == 'jpeg':
                                b = 4
+                               p = 1
                        else:
                                b = 1
-                               width, height = width*pf, height*pf
-                       if (width, height, bytes) <> (w, h, b):
+                               p = pf
+                       if (width, height, bytes) <> (w/p, h/p, b):
                                raise Error, 'jpeg data has wrong size'
                if not self.colormapinited:
                        self.initcolormap()
@@ -359,14 +360,15 @@ class Displayer(VideoParams):
                        gl.RGBcolor(200, 200, 200) # XXX rather light grey
                        gl.clear()
                        return
-## XXX Unfortunately this doesn't work on IRIX 4.0.1...
-##             if self.format == 'rgb8' and is_entry_indigo():
-##                     gl.RGBmode()
-##                     gl.gconfig()
-##                     gl.RGBcolor(200, 200, 200) # XXX rather light grey
-##                     gl.clear()
-##                     gl.pixmode(GL.PM_SIZE, 8)
-##                     return
+               # This only works on an Entry-level Indigo from IRIX 4.0.5
+               if self.format == 'rgb8' and is_entry_indigo() and \
+                         gl.gversion() == 'GL4DLG-4.0.': # Note trailing '.'!
+                       gl.RGBmode()
+                       gl.gconfig()
+                       gl.RGBcolor(200, 200, 200) # XXX rather light grey
+                       gl.clear()
+                       gl.pixmode(GL.PM_SIZE, 8)
+                       return
                gl.cmode()
                gl.gconfig()
                self.skipchrom = 0
@@ -571,6 +573,9 @@ def readfileheader(fp, filename):
                packfactor = 2
        else:
                raise Error, filename + ': Bad (w,h,pf) info'
+       if packfactor > 1:
+               width = (width / packfactor) * packfactor
+               height = (height / packfactor) * packfactor
        #
        # Return (version, values)
        #
diff --git a/Demo/sgi/video/Vfix.py b/Demo/sgi/video/Vfix.py
new file mode 100755 (executable)
index 0000000..82465bc
--- /dev/null
@@ -0,0 +1,90 @@
+#!/ufs/guido/bin/sgi/python
+
+# Copy a video file, fixing the line width to be a multiple of 4
+
+
+# Usage:
+#
+# Vfix [infile [outfile]]
+
+
+# Options:
+#
+# infile     : input file (default film.video)
+# outfile    : output file (default out.video)
+
+
+import sys
+import imageop
+sys.path.append('/ufs/guido/src/video')
+import VFile
+
+
+# Main program -- mostly command line parsing
+
+def main():
+       args = sys.argv[1:]
+       if len(args) < 1:
+               args.append('film.video')
+       if len(args) < 2:
+               args.append('out.video')
+       if len(args) > 2:
+               sys.stderr.write('usage: Vfix [infile [outfile]]\n')
+               sys.exit(2)
+       sts = process(args[0], args[1])
+       sys.exit(sts)
+
+
+# Copy one file to another
+
+def process(infilename, outfilename):
+       try:
+               vin = VFile.BasicVinFile().init(infilename)
+       except IOError, msg:
+               sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
+               return 1
+       except VFile.Error, msg:
+               sys.stderr.write(msg + '\n')
+               return 1
+       except EOFError:
+               sys.stderr.write(infilename + ': EOF in video file\n')
+               return 1
+
+       try:
+               vout = VFile.BasicVoutFile().init(outfilename)
+       except IOError, msg:
+               sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
+               return 1
+
+       info = vin.getinfo()
+       if info[0] <> 'grey':
+               sys.stderr.write('Vfix: input not in grey format\n')
+               return 1
+       vout.setinfo(info)
+       inwidth, height = vin.getsize()
+       pf = vin.packfactor
+       if (inwidth/pf)%4 == 0:
+               sys.stderr.write('Vfix: fix not necessary\n')
+               return 1
+       outwidth = (inwidth/pf/4)*4*pf
+       print 'inwidth =', inwidth, 'outwidth =', outwidth
+       vout.setsize(outwidth, height)
+       vout.writeheader()
+       n = 0
+       try:
+               while 1:
+                       t, data, cdata = vin.getnextframe()
+                       n = n + 1
+                       sys.stderr.write('Frame ' + `n` + '...')
+                       data = imageop.crop(data, 1, inwidth/pf, height/pf, \
+                               0, 0, outwidth/pf-1, height/pf-1)
+                       vout.writeframe(t, data, None)
+                       sys.stderr.write('\n')
+       except EOFError:
+               pass
+       return 0
+
+
+# Don't forget to call the main program
+
+main()
index 22eab2325ca741a747b377cd28f059b11bd0dbb1..77ae3a33166a0966aa869574c885e68ae64caace 100755 (executable)
@@ -5,7 +5,7 @@
 
 # Usage:
 #
-# Vinfo [-d] [-q] [-s] [file] ...
+# Vinfo [-d] [-q] [-s] [-t] [file] ...
 
 
 # Options:
@@ -13,6 +13,7 @@
 # -d       : print deltas between frames instead of frame times
 # -q       : quick: don't read the frames
 # -s       : don't print times (but do count frames and print the total)
+# -t       : terse (one line/file, implies -s)
 # file ... : file(s) to inspect; default film.video
 
 
@@ -86,6 +87,13 @@ def process(filename):
                print string.ljust(vin.format, 8),
                print string.rjust(`vin.width`, 4),
                print string.rjust(`vin.height`, 4),
+               s = string.rjust(`vin.packfactor`, 2)
+               if vin.packfactor and vin.format not in ('rgb', 'jpeg') and \
+                         (vin.width/vin.packfactor) % 4 <> 0:
+                       s = s + '!'
+               else:
+                       s = s + ' '
+               print s,
                sys.stdout.flush()
        else:
                vin.printinfo()