Skip to content

Commit

Permalink
use premultiplied alpha with pillow
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 25, 2022
1 parent d7ab988 commit f674dce
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions xpra/codecs/pillow/encoder.py
Expand Up @@ -128,17 +128,18 @@ def encode(coding : str, image, options=None):
else:
if pixel_format not in ("RGBA", "RGBX", "BGRA", "BGRX", "BGR", "RGB"):
raise ValueError(f"invalid pixel format {pixel_format}")
pil_import_format = pixel_format.replace("A", "a")
try:
#PIL cannot use the memoryview directly:
if isinstance(pixels, memoryview):
pixels = pixels.tobytes()
#it is safe to use frombuffer() here since the convert()
#calls below will not convert and modify the data in place
#and we save the compressed data then discard the image
im = Image.frombuffer(rgb, (w, h), pixels, "raw", pixel_format, image.get_rowstride(), 1)
im = Image.frombuffer(rgb, (w, h), pixels, "raw", pil_import_format, image.get_rowstride(), 1)
except Exception as e:
log("Image.frombuffer%s", (rgb, (w, h), len(pixels),
"raw", pixel_format, image.get_rowstride(), 1),
"raw", pil_import_format, image.get_rowstride(), 1),
exc_info=True)
log.error("Error: pillow failed to import image:")
log.error(" %s", e)
Expand Down

0 comments on commit f674dce

Please sign in to comment.