From 9b6190b186e97ce12c5bb592a10c96d791c285ff Mon Sep 17 00:00:00 2001 From: Jan Klopper Date: Wed, 22 Jun 2016 12:28:16 +0200 Subject: [PATCH] Add pixel factor in the server so that clients ca push more effective pixels --- protocol.md | 23 +++++++++++++++++++++++ vloed.py | 18 ++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 protocol.md diff --git a/protocol.md b/protocol.md new file mode 100644 index 0000000..0332f64 --- /dev/null +++ b/protocol.md @@ -0,0 +1,23 @@ +# The protocol for the UDP pixelvloed client and server (v1) + +Pixelvloed allows clients to send up to a configurable amount of pixels per message. +Each message should contain the RGB or RGBA mode indentifier, and the version bit. +Each pixel in the message is a set of (x,y,r,g,b) or (x,y,r,g,b,a) + X and Y are the positions on screen, and should be unsigned shorts + rgb and a are unsigned chars + +All values should be little endian. + +Mixing rgb and rgba pixels in one message is not supported. + +# The Autodetection system + +A pixelvloed server should broadcast a package advertising its settings with the following string content + +"%s:%f %s:%d %d*%d" % (PROTOCOL_PREAMBLE, PROTOCOL_VERSION, UDP_IP, UDP_PORT, width, height) + +A client should listen for these packages, split it on spaces and check the preample and protocol_version to see if it is capable of speaking the requested protocol. + +An example of a broadcasted packet would be: + +pixelvloed:1.00 192.168.0.1:5005 1920*1080 diff --git a/vloed.py b/vloed.py index bd1a387..602947c 100755 --- a/vloed.py +++ b/vloed.py @@ -40,6 +40,7 @@ class Canvas(object): self.screen = None self.udp_ip = UDP_IP self.udp_port = UDP_PORT + self.factor = options.factor if options.factor else 1 self.width = options.width if options.width else DEFAULT_WIDTH self.height = options.height if options.height else DEFAULT_HEIGHT self.canvas() @@ -74,7 +75,13 @@ class Canvas(object): """Print a pixel to the screen""" try: if a == 255: - self.pixels[x][y] = (r*256*256) + (g*256) + b + color = (r*256*256) + (g*256) + b + if self.factor>1: + for w in xrange(0, self.factor): + for h in xrange(0, self.factor): + self.pixels[(x*self.factor) + w][(y*self.factor) + h] = color + else: + self.pixels[x][y] = color else: old = self.pixels[x][y] oldr = old >> 16 @@ -148,9 +155,10 @@ class Canvas(object): """Lets send out our ip/port/resolution to any listening clients""" try: self.broadcastsocket.sendto( - '%s:%f %s:%d %d*%d' % (PROTOCOL_PREAMBLE, PROTOCOL_VERSION, - UDP_IP, UDP_PORT, - self.width, self.height), + '%s:%f %s:%d %d*%d' % ( + PROTOCOL_PREAMBLE, PROTOCOL_VERSION, + UDP_IP, UDP_PORT, + self.width/self.factor, self.height/self.factor), ('', DISCOVER_PORT)) if self.debug: print 'sending discovery packet' @@ -324,5 +332,7 @@ if __name__ == '__main__': type="int") parser.add_option('-m', action="store", dest="maxpixels", default=MAX_PIXELS, type="int") + parser.add_option('-f', action="store", dest="factor", default=1, + type="int") options, remainder = parser.parse_args() RunServer(options)