Skip to content

Commit

Permalink
decode PNG cursors in packet handler so the cursor_data always has RG…
Browse files Browse the repository at this point in the history
…B pixels

git-svn-id: https://xpra.org/svn/Xpra/trunk@15564 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 11, 2017
1 parent 2988cad commit 7bfc1e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/xpra/client/gtk_base/gtk_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,14 @@ def make_cursor(self, cursor_data):
missing_cursor_names.add(cursor_name)
#create cursor from the pixel data:
encoding, _, _, w, h, xhot, yhot, serial, pixels = cursor_data[0:9]
if encoding==b"png":
from xpra.os_util import BytesIOClass
from PIL import Image
buf = BytesIOClass(pixels)
img = Image.open(buf)
pixels = img.tobytes("raw", "BGRA")
cursorlog("used PIL to convert png cursor to raw")
elif encoding!=b"raw":
if encoding!=b"raw":
cursorlog.warn("Warning: invalid cursor encoding: %s", encoding)
return None
if len(pixels)<w*h*4:
import binascii
cursorlog.warn("not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)", w*h*4, len(pixels), binascii.hexlify(pixels)[:100])
cursorlog.warn("Warning: not enough pixels provided in cursor data")
cursorlog.warn(" %s needed and only %s bytes found:", w*h*4, len(pixels))
cursorlog.warn(" '%s')", binascii.hexlify(pixels)[:100])
return None
pixbuf = get_pixbuf_from_data(pixels, True, w, h, w*4)
x = max(0, min(xhot, w-1))
Expand Down
13 changes: 13 additions & 0 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
scalinglog = Logger("scaling")
webcamlog = Logger("webcam")
notifylog = Logger("notify")
cursorlog = Logger("cursor")


from xpra.gtk_common.gobject_util import no_arg_signal
Expand Down Expand Up @@ -3086,6 +3087,18 @@ def _process_cursor(self, packet):
else:
#prepend "raw" which is the default
new_cursor = ["raw"] + packet
encoding = packet[0]
pixels = packet[8]
if encoding==b"png":
from PIL import Image
buf = BytesIOClass(pixels)
img = Image.open(buf)
pixels = img.tobytes("raw", "BGRA")
cursorlog("used PIL to convert png cursor to raw")
packet[0] = b"raw"
elif encoding!=b"raw":
cursorlog.warn("Warning: invalid cursor encoding: %s", encoding)
return
self.set_windows_cursor(self._id_to_window.values(), new_cursor)

def _process_bell(self, packet):
Expand Down

0 comments on commit 7bfc1e3

Please sign in to comment.