diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1993-02-17 15:58:49 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1993-02-17 15:58:49 (GMT) |
commit | b05eaf19093446e7aa00d0ad432be11740806c35 (patch) | |
tree | 6480846bf560033f86b721ab0a8945dc0a3938ca /Demo/sgi/video/DisplayVideoIn.py | |
parent | 1d6821f58f3e25584084f8c989e53dcd187db85f (diff) | |
download | cpython-b05eaf19093446e7aa00d0ad432be11740806c35.zip cpython-b05eaf19093446e7aa00d0ad432be11740806c35.tar.gz cpython-b05eaf19093446e7aa00d0ad432be11740806c35.tar.bz2 |
DisplayVideoIn - Class similar to LiveVideoIn but sends data from
screen
Dsend - Main program analogous to Vsend to send data from display
Diffstat (limited to 'Demo/sgi/video/DisplayVideoIn.py')
-rwxr-xr-x | Demo/sgi/video/DisplayVideoIn.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/Demo/sgi/video/DisplayVideoIn.py b/Demo/sgi/video/DisplayVideoIn.py new file mode 100755 index 0000000..427d30a --- /dev/null +++ b/Demo/sgi/video/DisplayVideoIn.py @@ -0,0 +1,100 @@ +# Live video input from display class. + +import gl +import GL + +# The live video input class. +# Only instantiate this if have_video is true! + +class DisplayVideoIn: + + # Initialize an instance. Arguments: + # vw, vh: size of the video window data to be captured. + # position defaults to 0, 0 but can be set later + def init(self, pktmax, vw, vh, type): + self.pktmax = pktmax + self.realwidth, self.realheight = vw, vh + if type <> 'rgb': + raise 'Incorrent video data type', type + self.type = type + self.width = vw + self.height = vh + # + # Open dummy window + # + gl.foreground() + gl.noport() + self.wid = gl.winopen('DisplayVideoIn') + + self.x0 = 0 + self.x1 = self.x0 + self.width - 1 + self.y0 = 0 + self.y1 = self.y0 + self.height - 1 + # Compute # full lines per packet + self.lpp = pktmax / self.linewidth() + if self.lpp <= 0: + raise 'No lines in packet', self.linewidth() + self.pktsize = self.lpp*self.linewidth() + self.data = None + self.old_data = None + self.dataoffset = 0 + self.lpos = 0 + self.hints = 0 + return self + + # Change the size of the video being displayed. + + def resizevideo(self, vw, vh): + self.width = vw + self.height = vh + self.x1 = self.x0 + self.width - 1 + self.y1 = self.y0 + self.height - 1 + + def positionvideo(self, x, y): + self.x0 = x + self.y0 = y + self.x1 = self.x0 + self.width - 1 + self.y1 = self.y0 + self.height - 1 + + # Remove an instance. + # This turns off continuous capture. + + def close(self): + gl.winclose(self.wid) + + # Get the length in bytes of a video line + def linewidth(self): + return self.width*4 + + # Get the next video packet. + # This returns (lpos, data) where: + # - lpos is the line position + # - data is a piece of data + # The dimensions of data are: + # - pixel depth = 1 byte + # - scan line width = self.width (the vw argument to init()) + # - number of scan lines = self.lpp (PKTMAX / vw) + + def getnextpacket(self): + if not self.data or self.dataoffset >= len(self.data): + self.old_data = self.data + self.data = gl.readdisplay(self.x0, self.y0, \ + self.x1, self.y1, self.hints) + self.dataoffset = 0 + self.lpos = 0 + data = self.data[self.dataoffset:self.dataoffset+self.pktsize] + while self.old_data and \ + self.dataoffset+self.pktsize < len(self.data): + odata = self.old_data[self.dataoffset: \ + self.dataoffset+self.pktsize] + if odata <> data: + break + print 'skip', self.lpos + self.lpos = self.lpos + self.lpp + self.dataoffset = self.dataoffset + self.pktsize + data = self.data[self.dataoffset:\ + self.dataoffset+self.pktsize] + lpos = self.lpos + self.dataoffset = self.dataoffset + self.pktsize + self.lpos = self.lpos + self.lpp + return lpos, data |