Guido van Rossum | 5e044b7 | 1993-02-25 14:20:13 +0000 | [diff] [blame] | 1 | # Class to grab frames from a window. |
| 2 | # (This has fewer user-settable parameters than Displayer.) |
| 3 | # It is the caller's responsibility to initialize the window and to |
| 4 | # ensure that it is current when using grabframe() |
| 5 | |
| 6 | import gl, GL |
| 7 | import VFile |
| 8 | import GET |
| 9 | from VFile import Error |
| 10 | |
| 11 | class VGrabber(VFile.VideoParams): |
| 12 | |
| 13 | # XXX The init() method of VideoParams is just fine, for now |
| 14 | |
| 15 | # Grab a frame. |
| 16 | # Return (data, chromdata) just like getnextframe(). |
| 17 | |
| 18 | def grabframe(self): |
| 19 | grabber = choose_grabber(self.format) |
| 20 | return grabber(self.width, self.height, self.packfactor) |
| 21 | |
| 22 | |
| 23 | # Choose one of the grabber functions below based upon a color system name |
| 24 | |
| 25 | def choose_grabber(format): |
| 26 | try: |
| 27 | return eval('grab_' + format) |
| 28 | except: |
| 29 | raise Error, 'Unknown color system: ' + `format` |
| 30 | |
| 31 | |
| 32 | # Routines to grab data, per color system (only a few really supported). |
| 33 | # (These functions are used via eval with a constructed argument!) |
| 34 | |
| 35 | def grab_rgb(w, h, pf): |
| 36 | if gl.getdisplaymode() <> GET.DMRGB: |
| 37 | raise Error, 'Sorry, can only grab rgb in single-buf rgbmode' |
| 38 | if pf <> (1, 1): |
| 39 | raise Error, 'Sorry, only grab rgb with packfactor (1,1)' |
| 40 | return gl.lrectread(0, 0, w-1, h-1), None |
| 41 | |
| 42 | def grab_rgb8(w, h, pf): |
| 43 | if gl.getdisplaymode() <> GET.DMRGB: |
| 44 | raise Error, 'Sorry, can only grab rgb8 in single-buf rgbmode' |
| 45 | if pf <> (1, 1): |
| 46 | raise Error, 'Sorry, can only grab rgb8 with packfactor (1,1)' |
| 47 | if not VFile.is_entry_indigo(): |
| 48 | raise Error, 'Sorry, can only grab rgb8 on entry level Indigo' |
| 49 | # XXX Dirty Dirty here. |
| 50 | # XXX Set buffer to cmap mode, grab image and set it back. |
| 51 | gl.cmode() |
| 52 | gl.gconfig() |
| 53 | gl.pixmode(GL.PM_SIZE, 8) |
| 54 | data = gl.lrectread(0, 0, w-1, h-1) |
| 55 | data = data[:w*h] # BUG FIX for python lrectread |
| 56 | gl.RGBmode() |
| 57 | gl.gconfig() |
| 58 | gl.pixmode(GL.PM_SIZE, 32) |
| 59 | return data, None |
| 60 | |
| 61 | def grab_grey(w, h, pf): |
| 62 | raise Error, 'Sorry, grabbing grey not implemented' |
| 63 | |
| 64 | def grab_yiq(w, h, pf): |
| 65 | raise Error, 'Sorry, grabbing yiq not implemented' |
| 66 | |
| 67 | def grab_hls(w, h, pf): |
| 68 | raise Error, 'Sorry, grabbing hls not implemented' |
| 69 | |
| 70 | def grab_hsv(w, h, pf): |
| 71 | raise Error, 'Sorry, grabbing hsv not implemented' |
| 72 | |
| 73 | def grab_jpeg(w, h, pf): |
| 74 | # XXX Ought to grab rgb and compress it |
| 75 | raise Error, 'sorry, grabbing jpeg not implemented' |
| 76 | |
| 77 | def grab_jpeggrey(w, h, pf): |
| 78 | raise Error, 'sorry, grabbing jpeggrey not implemented' |