def show(file): import gl, GL, DEVICE jpegdata = open(file, 'r').read() imgdata, width, height, bytesperpixel = decompress(jpegdata) gl.foreground() gl.prefsize(width, height) win = gl.winopen(file) if bytesperpixel == 1: gl.cmode() gl.pixmode(GL.PM_SIZE, 8) gl.gconfig() for i in range(256): gl.mapcolor(i, i, i, i) else: gl.RGBmode() gl.pixmode(GL.PM_SIZE, 32) gl.gconfig() gl.qdevice(DEVICE.REDRAW) gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.lrectwrite(0, 0, width - 1, height - 1, imgdata) while 1: dev, val = gl.qread() if dev in (DEVICE.ESCKEY, DEVICE.WINSHUT, DEVICE.WINQUIT): break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, width - 1, height - 1, imgdata) gl.winclose(win) newjpegdata = compress(imgdata, width, height, bytesperpixel) open('/tmp/j.jpg', 'w').write(newjpegdata)
def main(): format = SV.RGB8_FRAMES requestedwidth = SV.PAL_XMAX queuesize = 30 if sys.argv[1:]: queuesize = eval(sys.argv[1]) v = sv.OpenVideo() svci = (format, requestedwidth, 0, queuesize, 0) go = raw_input('Press return to capture ' + `queuesize` + ' frames: ') result = v.CaptureBurst(svci) svci, buffer, bitvec = result ## svci, buffer = result # XXX If bit vector not yet implemented print 'Captured', svci[3], 'frames, i.e.', len(buffer)/1024, 'K bytes' w, h = svci[1:3] framesize = w * h gl.prefposition(300, 300+w-1, 100, 100+h-1) gl.foreground() win = gl.winopen('Burst Capture') gl.RGBmode() gl.gconfig() gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.ESCKEY) print 'Click left mouse for next frame' for i in range(svci[3]): inverted_frame = sv.RGB8toRGB32(1, \ buffer[i*framesize:(i+1)*framesize], w, h) gl.lrectwrite(0, 0, w-1, h-1, inverted_frame) while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE and val == 1: break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, w-1, h-1, inverted_frame) if dev == DEVICE.ESCKEY: v.CloseVideo() gl.winclose(win) return v.CloseVideo() gl.winclose(win)
def main(): format = SV.RGB8_FRAMES requestedwidth = SV.PAL_XMAX queuesize = 30 if sys.argv[1:]: queuesize = eval(sys.argv[1]) v = sv.OpenVideo() svci = (format, requestedwidth, 0, queuesize, 0) go = raw_input('Press return to capture ' + ` queuesize ` + ' frames: ') result = v.CaptureBurst(svci) svci, buffer, bitvec = result ## svci, buffer = result # XXX If bit vector not yet implemented print 'Captured', svci[3], 'frames, i.e.', len(buffer) / 1024, 'K bytes' w, h = svci[1:3] framesize = w * h gl.prefposition(300, 300 + w - 1, 100, 100 + h - 1) gl.foreground() win = gl.winopen('Burst Capture') gl.RGBmode() gl.gconfig() gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.ESCKEY) print 'Click left mouse for next frame' for i in range(svci[3]): inverted_frame = sv.RGB8toRGB32(1, \ buffer[i*framesize:(i+1)*framesize], w, h) gl.lrectwrite(0, 0, w - 1, h - 1, inverted_frame) while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE and val == 1: break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, w - 1, h - 1, inverted_frame) if dev == DEVICE.ESCKEY: v.CloseVideo() gl.winclose(win) return v.CloseVideo() gl.winclose(win)
def imageview(file): import cl, CL, gl, GL, DEVICE filep = open(file, 'r') header = filep.read(16) filep.seek(0) scheme = cl.QueryScheme(header) decomp = cl.OpenDecompressor(scheme) headersize = cl.QueryMaxHeaderSize(scheme) header = filep.read(headersize) filep.seek(0) headersize = decomp.ReadHeader(header) width = decomp.GetParam(CL.IMAGE_WIDTH) height = decomp.GetParam(CL.IMAGE_HEIGHT) params = [CL.ORIGINAL_FORMAT, CL.RGBX, \ CL.ORIENTATION, CL.BOTTOM_UP, \ CL.FRAME_BUFFER_SIZE, width*height*CL.BytesPerPixel(CL.RGBX)] decomp.SetParams(params) image = decomp.Decompress(1, filep.read()) filep.close() decomp.CloseDecompressor() gl.foreground() gl.prefsize(width, height) win = gl.winopen(file) gl.RGBmode() gl.pixmode(GL.PM_SIZE, 32) gl.gconfig() gl.qdevice(DEVICE.REDRAW) gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.lrectwrite(0, 0, width-1, height-1, image) while 1: dev, val = gl.qread() if dev in (DEVICE.ESCKEY, DEVICE.WINSHUT, DEVICE.WINQUIT): break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, width-1, height-1, image) gl.winclose(win)
# Implement 'jpeg' interface using SGI's compression library
import sys
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()
# Classes to read and write CMIF video files.