Skip to content

Commit

Permalink
#3374 tune for best performance
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Dec 4, 2021
1 parent 37c74ab commit 66ea1f2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion xpra/codecs/spng/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ cdef extern from "spng.h":
SPNG_ENCODE_PROGRESSIVE
SPNG_ENCODE_FINALIZE

enum spng_filter_choice:
SPNG_DISABLE_FILTERING
SPNG_FILTER_CHOICE_NONE
SPNG_FILTER_CHOICE_SUB
SPNG_FILTER_CHOICE_UP
SPNG_FILTER_CHOICE_AVG
SPNG_FILTER_CHOICE_PAETH
SPNG_FILTER_CHOICE_ALL

enum spng_option:
SPNG_ENCODE_TO_BUFFER
SPNG_KEEP_UNKNOWN_CHUNKS
Expand Down Expand Up @@ -127,6 +136,7 @@ def encode(coding, image, options=None):
assert coding=="png"
options = options or {}
cdef int grayscale = options.get("grayscale", 0)
cdef int speed = options.get("speed", 50)
cdef int width = image.get_width()
cdef int height = image.get_height()
cdef int scaled_width = options.get("scaled-width", width)
Expand Down Expand Up @@ -165,7 +175,7 @@ def encode(coding, image, options=None):
if rgb_format=="RGBA":
ihdr.color_type = SPNG_COLOR_TYPE_TRUECOLOR_ALPHA
ihdr.compression_method = 0
ihdr.filter_method = SPNG_FILTER_NONE
ihdr.filter_method = 0
ihdr.interlace_method = SPNG_INTERLACE_NONE
if check_error(spng_set_ihdr(ctx, &ihdr),
"failed to set encode-to-buffer option"):
Expand All @@ -189,6 +199,13 @@ def encode(coding, image, options=None):
"failed to set mem level"):
spng_ctx_free(ctx)
return None
cdef int filter = SPNG_FILTER_CHOICE_NONE
if speed<30:
filter |= SPNG_FILTER_CHOICE_SUB
if check_error(spng_set_option(ctx, SPNG_FILTER_CHOICE, filter),
"failed to set filter choice"):
spng_ctx_free(ctx)
return None

if check_error(spng_set_option(ctx, SPNG_ENCODE_TO_BUFFER, 1),
"failed to set encode-to-buffer option"):
Expand Down

0 comments on commit 66ea1f2

Please sign in to comment.