#! /usr/bin/env python # Decompress a jpeg or jpeggrey video file to rgb format # Usage: # # Vunjpeg [infile [outfile]] # Options: # # infile : input file (default film.video) # outfile : output file (default out.video) import sys import jpeg 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: Vunjpeg [infile [outfile]]\n') sys.exit(2) sts = process(args[0], args[1]) sys.exit(sts)
import imageop
def jpeg2rgb(img, width, height): import cl, CL import jpeg data, width, height, bytesperpixel = jpeg.decompress(img) if bytesperpixel <> 4: raise RuntimeError, 'not rgb jpeg' return data
class Displayer(VideoParams): # Initialize an instance. # This does not need a current window def __init__(self): if no_gl: raise RuntimeError, \ 'no gl module available, so cannot display' VideoParams.__init__(self) # User-settable parameters self.magnify = 1.0 # frame magnification factor self.xorigin = 0 # x frame offset self.yorigin = 0 # y frame offset (from bottom) self.quiet = 0 # if set, don't print messages self.fallback = 1 # allow fallback to grey # Internal flags self.colormapinited = 0 # must initialize window self.skipchrom = 0 # don't skip chrominance data self.color0 = None # magic, used by clearto() self.fixcolor0 = 0 # don't need to fix color0 self.mustunpack = (not support_packed_pixels()) # setinfo() must reset some internal flags def setinfo(self, values): VideoParams.setinfo(self, values) self.colormapinited = 0 self.skipchrom = 0 self.color0 = None self.fixcolor0 = 0 # Show one frame, initializing the window if necessary def showframe(self, data, chromdata): self.showpartframe(data, chromdata, \ (0,0,self.width,self.height)) def showpartframe(self, data, chromdata, (x, y, w, h)): pmsize = self.bpp xpf, ypf = self.xpf, self.ypf if self.upside_down: gl.pixmode(GL.PM_TTOB, 1) if self.mirror_image: gl.pixmode(GL.PM_RTOL, 1) if self.format in ('jpeg', 'jpeggrey'): import jpeg data, width, height, bytes = jpeg.decompress(data) pmsize = bytes * 8 elif self.format == 'compress': data = self.decompress(data) pmsize = 32 elif self.format in ('mono', 'grey4'): if self.mustunpack: if self.format == 'mono': data = imageop.mono2grey(data, \ w/xpf, h/ypf, 0x20, 0xdf) elif self.format == 'grey4': data = imageop.grey42grey(data, \ w/xpf, h/ypf) pmsize = 8 elif self.format == 'grey2': data = imageop.grey22grey(data, w / xpf, h / ypf) pmsize = 8 if not self.colormapinited: self.initcolormap() if self.fixcolor0: gl.mapcolor(self.color0) self.fixcolor0 = 0 xfactor = yfactor = self.magnify xfactor = xfactor * xpf yfactor = yfactor * ypf if chromdata and not self.skipchrom: cp = self.chrompack cx = int(x * xfactor * cp) + self.xorigin cy = int(y * yfactor * cp) + self.yorigin cw = (w + cp - 1) / cp ch = (h + cp - 1) / cp gl.rectzoom(xfactor * cp, yfactor * cp) gl.pixmode(GL.PM_SIZE, 16) gl.writemask(self.mask - ((1 << self.c0bits) - 1)) gl.lrectwrite(cx, cy, cx + cw - 1, cy + ch - 1, \ chromdata) # if pmsize < 32: gl.writemask((1 << self.c0bits) - 1) gl.pixmode(GL.PM_SIZE, pmsize) w = w / xpf h = h / ypf x = x / xpf y = y / ypf gl.rectzoom(xfactor, yfactor) x = int(x * xfactor) + self.xorigin y = int(y * yfactor) + self.yorigin gl.lrectwrite(x, y, x + w - 1, y + h - 1, data) gl.gflush()
def jpeg2rgb(img, width, height): import jpeg data, width, height, bytesperpixel = jpeg.decompress(img) if bytesperpixel <> 4: raise RuntimeError, 'not rgb jpeg' return data
def jpeggrey2grey(img, width, height): import jpeg data, width, height, bytesperpixel = jpeg.decompress(img) if bytesperpixel <> 1: raise RuntimeError, 'not greyscale jpeg' return data
width, height = width/pf, height/pf bytes = 1 else: sys.stderr.write('Vunjpeg: input not in jpeg[grey] format\n') return 1 info = (format,) + info[1:] vout.setinfo(info) vout.writeheader() sts = 0 n = 0 try: while 1: t, data, cdata = vin.getnextframe() n = n + 1 sys.stderr.write('Frame ' + `n` + '...') data, w, h, b = jpeg.decompress(data) if (w, h, b) <> (width, height, bytes): sys.stderr.write('jpeg data has wrong size\n') sts = 1 else: vout.writeframe(t, data, None) sys.stderr.write('\n') except EOFError: pass return sts # Don't forget to call the main program main()
# Classes to read and write CMIF video files.
width, height = width / pf, height / pf bytes = 1 else: sys.stderr.write('Vunjpeg: input not in jpeg[grey] format\n') return 1 info = (format, ) + info[1:] vout.setinfo(info) vout.writeheader() sts = 0 n = 0 try: while 1: t, data, cdata = vin.getnextframe() n = n + 1 sys.stderr.write('Frame ' + ` n ` + '...') data, w, h, b = jpeg.decompress(data) if (w, h, b) <> (width, height, bytes): sys.stderr.write('jpeg data has wrong size\n') sts = 1 else: vout.writeframe(t, data, None) sys.stderr.write('\n') except EOFError: pass return sts # Don't forget to call the main program main()
#! /usr/bin/env python # Decompress a jpeg or jpeggrey video file to rgb format # Usage: # # Vunjpeg [infile [outfile]] # Options: # # infile : input file (default film.video) # outfile : output file (default out.video) import sys import jpeg 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: Vunjpeg [infile [outfile]]\n') sys.exit(2) sts = process(args[0], args[1]) sys.exit(sts) # Copy one file to another def process(infilename, outfilename):