blob: 242ebf2231f112f00b35b7cf39efe5fa94dc841e [file] [log] [blame]
Guido van Rossum5e044b71993-02-25 14:20:13 +00001# 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
6import gl, GL
7import VFile
8import GET
9from VFile import Error
10
11class VGrabber(VFile.VideoParams):
12
Guido van Rossum21a3ff91993-12-17 15:11:41 +000013 # XXX The constructor of VideoParams is just fine, for now
Guido van Rossum5e044b71993-02-25 14:20:13 +000014
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
25def 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
35def 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
42def 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
61def grab_grey(w, h, pf):
62 raise Error, 'Sorry, grabbing grey not implemented'
63
64def grab_yiq(w, h, pf):
65 raise Error, 'Sorry, grabbing yiq not implemented'
66
67def grab_hls(w, h, pf):
68 raise Error, 'Sorry, grabbing hls not implemented'
69
70def grab_hsv(w, h, pf):
71 raise Error, 'Sorry, grabbing hsv not implemented'
72
73def grab_jpeg(w, h, pf):
Jack Jansen35173711993-06-08 12:47:20 +000074 data, dummy = grab_rgb(w, h, pf)
75 import jpeg
76 data = jpeg.compress(data, w, h, 4)
77 return data, None
Guido van Rossum5e044b71993-02-25 14:20:13 +000078
79def grab_jpeggrey(w, h, pf):
80 raise Error, 'sorry, grabbing jpeggrey not implemented'