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()
9 from VFile
import Error
11 class VGrabber(VFile
.VideoParams
):
13 # XXX The constructor of VideoParams is just fine, for now
16 # Return (data, chromdata) just like getnextframe().
19 grabber
= choose_grabber(self
.format
)
20 return grabber(self
.width
, self
.height
, self
.packfactor
)
23 # Choose one of the grabber functions below based upon a color system name
25 def choose_grabber(format
):
27 return eval('grab_' + format
)
29 raise Error
, 'Unknown color system: ' + `format`
32 # Routines to grab data, per color system (only a few really supported).
33 # (These functions are used via eval with a constructed argument!)
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'
39 raise Error
, 'Sorry, only grab rgb with packfactor (1,1)'
40 return gl
.lrectread(0, 0, w
-1, h
-1), None
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'
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.
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
58 gl
.pixmode(GL
.PM_SIZE
, 32)
61 def grab_grey(w
, h
, pf
):
62 raise Error
, 'Sorry, grabbing grey not implemented'
64 def grab_yiq(w
, h
, pf
):
65 raise Error
, 'Sorry, grabbing yiq not implemented'
67 def grab_hls(w
, h
, pf
):
68 raise Error
, 'Sorry, grabbing hls not implemented'
70 def grab_hsv(w
, h
, pf
):
71 raise Error
, 'Sorry, grabbing hsv not implemented'
73 def grab_jpeg(w
, h
, pf
):
74 data
, dummy
= grab_rgb(w
, h
, pf
)
76 data
= jpeg
.compress(data
, w
, h
, 4)
79 def grab_jpeggrey(w
, h
, pf
):
80 raise Error
, 'sorry, grabbing jpeggrey not implemented'