Skip to content

Commit

Permalink
#3374 spng uses unpremultiplied alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 26, 2022
1 parent 3fa5760 commit 5c694b0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion xpra/codecs/spng/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ log = Logger("decoder", "spng")

from xpra.net.compression import Compressed
from xpra.codecs.codec_debug import may_save_image
from xpra.codecs.argb.argb import unpremultiply_argb
from xpra.codecs.spng.spng cimport (
SPNG_VERSION_MAJOR, SPNG_VERSION_MINOR, SPNG_VERSION_PATCH,
SPNG_CTX_ENCODER,
Expand Down Expand Up @@ -78,11 +79,13 @@ def encode(coding, image, options=None):

rgb_format = image.get_pixel_format()
alpha = options.get("alpha", rgb_format.find("A")>=0)
if rgb_format not in INPUT_FORMATS or (resize and len(rgb_format)!=4) or rowstride!=width*len(rgb_format) or grayscale:
if rgb_format not in INPUT_FORMATS or (resize and len(rgb_format)!=4) or rowstride!=width*len(rgb_format) or grayscale or alpha:
#best to restride before byte-swapping to trim extra unused data:
if rowstride!=width*len(rgb_format):
image.restride(width*len(rgb_format))
input_formats = INPUT_FORMATS
if alpha:
image.set_pixels(unpremultiply_argb(image.get_pixels()))
if grayscale:
input_formats = ("BGRX", "BGRA", "BGR", "RGB")
if rgb_format not in input_formats:
Expand Down

0 comments on commit 5c694b0

Please sign in to comment.