blob: 23d03da845330ef48551686b013a8c23ce01a402 [file] [log] [blame]
Guido van Rossumba066151992-09-22 17:23:17 +00001# Live video output (display video on the screen, presumably from the net)
2
3import gl
4from VFile import Displayer
5
6
7# Video output (displayer) class.
8
9class LiveVideoOut:
10
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000011 # Call this to initialize things. Arguments:
12 # wid: the window id where the video is to be displayed (centered)
13 # vw, vh: size of the video image to be displayed
14
Jack Jansen3b253711992-12-14 12:25:21 +000015 def init(self, wid, vw, vh, type):
Guido van Rossumba066151992-09-22 17:23:17 +000016 ##print 'Init', wid, xywh
17 ##print 'video', vw, vw
18 self.vw = vw
19 self.vh = vh
20 self.disp = Displayer().init()
Jack Jansen3b253711992-12-14 12:25:21 +000021 if not type in ('rgb8', 'grey', 'mono'):
22 raise 'Incorrent live video output type'
23 info = (type, vw, vh, 1, 8, 0, 0, 0, 0)
Guido van Rossumba066151992-09-22 17:23:17 +000024 self.disp.setinfo(info)
25 self.wid = wid
26 oldwid = gl.winget()
27 gl.winset(wid)
28 self.disp.initcolormap()
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000029 self.reshapewindow()
Guido van Rossumba066151992-09-22 17:23:17 +000030 gl.winset(oldwid)
31 return self
32
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000033 # Call this in response to every REDRAW event for the window
34 # or if the window size has changed for other reasons.
35
36 def reshapewindow(self):
Guido van Rossumba066151992-09-22 17:23:17 +000037 oldwid = gl.winget()
38 gl.winset(self.wid)
Guido van Rossumba066151992-09-22 17:23:17 +000039 gl.reshapeviewport()
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000040 w, h = gl.getsize()
41 self.disp.xorigin = (w-self.vw)/2
42 self.disp.yorigin = (h-self.vh)/2
Guido van Rossumba066151992-09-22 17:23:17 +000043 self.disp.clear()
44 gl.winset(oldwid)
45
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000046 # Call this to change the size of the video images being displayed.
47 # Implies reshapewindow().
48
49 def resizevideo(self, vw, vh):
50 self.vw, self.vh = vw, vh
51 self.disp.setsize(vw, vh)
52 self.reshapewindow()
53
54 # Call this to display the next video packet. Arguments:
55 # pos: line number where the packet begins
56 # data: image data of the packet
57 # (these correspond directly to the return values from
58 # LiveVideoIn.getnextpacket()).
59
Guido van Rossumba066151992-09-22 17:23:17 +000060 def putnextpacket(self, pos, data):
Jack Jansen3b253711992-12-14 12:25:21 +000061 if self.disp.format == 'mono':
62 # Unfortunately size-check is difficult for
63 # packed video
64 nline = (len(data)*8)/self.vw
65 else:
66 nline = len(data)/self.vw
67 if nline*self.vw <> len(data):
68 print 'Incorrect-sized video fragment ignored'
69 return
Guido van Rossumba066151992-09-22 17:23:17 +000070 oldwid = gl.winget()
71 gl.winset(self.wid)
Guido van Rossumba066151992-09-22 17:23:17 +000072 self.disp.showpartframe(data, None, (0, pos, self.vw, nline))
73 gl.winset(oldwid)
74
Guido van Rossumcfb6bb21992-09-24 16:03:56 +000075 # Call this to close the window.
76
Guido van Rossumba066151992-09-22 17:23:17 +000077 def close(self):
Guido van Rossum7b47c791992-09-24 15:01:37 +000078 pass