1 # Live video input from display class.
6 # The live video input class.
7 # Only instantiate this if have_video is true!
11 # Initialize an instance. Arguments:
12 # vw, vh: size of the video window data to be captured.
13 # position defaults to 0, 0 but can be set later
14 def __init__(self
, pktmax
, vw
, vh
, type):
16 self
.realwidth
, self
.realheight
= vw
, vh
18 raise 'Incorrent video data type', type
27 self
.wid
= gl
.winopen('DisplayVideoIn')
30 self
.x1
= self
.x0
+ self
.width
- 1
32 self
.y1
= self
.y0
+ self
.height
- 1
33 # Compute # full lines per packet
34 self
.lpp
= pktmax
/ self
.linewidth()
36 raise 'No lines in packet', self
.linewidth()
37 self
.pktsize
= self
.lpp
*self
.linewidth()
44 # Change the size of the video being displayed.
46 def resizevideo(self
, vw
, vh
):
49 self
.x1
= self
.x0
+ self
.width
- 1
50 self
.y1
= self
.y0
+ self
.height
- 1
52 def positionvideo(self
, x
, y
):
55 self
.x1
= self
.x0
+ self
.width
- 1
56 self
.y1
= self
.y0
+ self
.height
- 1
59 # This turns off continuous capture.
64 # Get the length in bytes of a video line
68 # Get the next video packet.
69 # This returns (lpos, data) where:
70 # - lpos is the line position
71 # - data is a piece of data
72 # The dimensions of data are:
73 # - pixel depth = 1 byte
74 # - scan line width = self.width (the vw argument to __init__())
75 # - number of scan lines = self.lpp (PKTMAX / vw)
77 def getnextpacket(self
):
78 if not self
.data
or self
.dataoffset
>= len(self
.data
):
79 self
.old_data
= self
.data
80 self
.data
= gl
.readdisplay(self
.x0
, self
.y0
, \
81 self
.x1
, self
.y1
, self
.hints
)
84 data
= self
.data
[self
.dataoffset
:self
.dataoffset
+self
.pktsize
]
85 while self
.old_data
and \
86 self
.dataoffset
+self
.pktsize
< len(self
.data
):
87 odata
= self
.old_data
[self
.dataoffset
: \
88 self
.dataoffset
+self
.pktsize
]
91 print 'skip', self
.lpos
92 self
.lpos
= self
.lpos
+ self
.lpp
93 self
.dataoffset
= self
.dataoffset
+ self
.pktsize
94 data
= self
.data
[self
.dataoffset
:\
95 self
.dataoffset
+self
.pktsize
]
97 self
.dataoffset
= self
.dataoffset
+ self
.pktsize
98 self
.lpos
= self
.lpos
+ self
.lpp