Skip to content

Commit

Permalink
allow webp to be used for transparent windows: pass has_alpha flag an…
Browse files Browse the repository at this point in the history
…d decompress to rgba and call paint_rgb32 instead of paint_rgb24

git-svn-id: https://xpra.org/svn/Xpra/trunk@3514 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 27, 2013
1 parent 298d39e commit 123b8d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
19 changes: 15 additions & 4 deletions src/xpra/client/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,21 @@ def paint_image(self, coding, img_data, x, y, width, height, options, callbacks)

def paint_webp(self, img_data, x, y, width, height, options, callbacks):
""" can be called from any thread """
from xpra.codecs.webm.decode import DecodeRGB
rgb24 = DecodeRGB(img_data)
rowstride = width*3
self.idle_add(self.do_paint_rgb24, str(rgb24.bitmap), x, y, width, height, rowstride, options, callbacks)
from xpra.codecs.webm.decode import DecodeRGB, DecodeRGBA
if options.get("has_alpha", False):
decode = DecodeRGBA
rowstride = width*4
paint_rgb = self.do_paint_rgb32
else:
decode = DecodeRGB
rowstride = width*3
paint_rgb = self.do_paint_rgb24
if DRAW_DEBUG:
log.info("paint_webp(%s) using decode=%s, paint=%s",
("%s bytes" % len(img_data), x, y, width, height, options, callbacks), decode, paint_rgb)
rgb_data = decode(img_data)
pixels = str(rgb_data.bitmap)
self.idle_add(paint_rgb, pixels, x, y, width, height, rowstride, options, callbacks)
return False

def paint_rgb24(self, raw_data, x, y, width, height, rowstride, options, callbacks):
Expand Down
26 changes: 15 additions & 11 deletions src/xpra/server/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,12 @@ def switch_to_lossless(reason):
debug("do_get_best_encoding(..) temporarily switching to %s encoder for %s pixels: %s", coding, pixel_count, reason)
return coding
if has_alpha:
if current_encoding in ("png", "rgb32"):
if current_encoding in ("png", "rgb32", "webp"):
return current_encoding
if current_encoding=="rgb":
encs = ("rgb32", "png")
encs = ("rgb32", "png", "webp")
else:
encs = ("png", "rgb32")
encs = ("png", "rgb32", "webp")
for x in encs:
if x in self.SERVER_CORE_ENCODINGS and x in self.core_encodings:
debug("do_get_best_encoding(..) using %s for alpha channel support", x)
Expand Down Expand Up @@ -881,23 +881,27 @@ def webp_encode(self, image, options):
from xpra.codecs.webm.encode import EncodeRGB, EncodeBGR, EncodeRGBA, EncodeBGRA
from xpra.codecs.webm.handlers import BitmapHandler
handler_encs = {
"RGB" : (BitmapHandler.RGB, EncodeRGB),
"BGR" : (BitmapHandler.BGR, EncodeBGR),
"RGBA": (BitmapHandler.RGBA, EncodeRGBA),
"RGBX": (BitmapHandler.RGBA, EncodeRGBA),
"BGRA": (BitmapHandler.BGRA, EncodeBGRA),
"BGRX": (BitmapHandler.BGRA, EncodeBGRA),
"RGB" : (BitmapHandler.RGB, EncodeRGB, False),
"BGR" : (BitmapHandler.BGR, EncodeBGR, False),
"RGBA": (BitmapHandler.RGBA, EncodeRGBA, True),
"RGBX": (BitmapHandler.RGBA, EncodeRGBA, False),
"BGRA": (BitmapHandler.BGRA, EncodeBGRA, True),
"BGRX": (BitmapHandler.BGRA, EncodeBGRA, False),
}
rgb_format = image.get_rgb_format()
h_e = handler_encs.get(rgb_format)
assert h_e is not None, "cannot handle rgb format %s with webp!" % rgb_format
bh, enc = h_e
bh, enc, has_alpha = h_e
debug("webp_encode(%s, %s) using encoder=%s for %s", image, options, enc, rgb_format)
image = BitmapHandler(image.get_pixels(), bh, image.get_width(), image.get_height(), image.get_rowstride())
q = 80
if options:
q = options.get("quality", 80)
q = min(99, max(1, q))
return Compressed("webp", str(enc(image, quality=q).data)), {"quality" : q}
client_options = {"quality" : q}
if has_alpha:
client_options["has_alpha"] = True
return Compressed("webp", str(enc(image, quality=q).data)), client_options

def rgb_encode(self, coding, image):
rgb_format = image.get_rgb_format()
Expand Down

0 comments on commit 123b8d3

Please sign in to comment.