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 grab_rgb8(w, h, pf): if gl.getdisplaymode() <> GET.DMRGB: raise Error, 'Sorry, can only grab rgb8 in single-buf rgbmode' if pf <> (1, 1): raise Error, 'Sorry, can only grab rgb8 with packfactor (1,1)' if not VFile.is_entry_indigo(): raise Error, 'Sorry, can only grab rgb8 on entry level Indigo' # XXX Dirty Dirty here. # XXX Set buffer to cmap mode, grab image and set it back. gl.cmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 8) data = gl.lrectread(0, 0, w - 1, h - 1) data = data[:w * h] # BUG FIX for python lrectread gl.RGBmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 32) return data, None
def grab_rgb8(w, h, pf): if gl.getdisplaymode() <> GET.DMRGB: raise Error, 'Sorry, can only grab rgb8 in single-buf rgbmode' if pf <> (1, 1): raise Error, 'Sorry, can only grab rgb8 with packfactor (1,1)' if not VFile.is_entry_indigo(): raise Error, 'Sorry, can only grab rgb8 on entry level Indigo' # XXX Dirty Dirty here. # XXX Set buffer to cmap mode, grab image and set it back. gl.cmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 8) data = gl.lrectread(0, 0, w-1, h-1) data = data[:w*h] # BUG FIX for python lrectread gl.RGBmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 32) return data, None
# Implement 'jpeg' interface using SGI's compression library
def set_cmode(self): gl.cmode() gl.gconfig()
# Classes to read and write CMIF video files.
# Class to grab frames from a window.