-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
# This file is part of Xpra. | ||
# Copyright (C) 2021 Antoine Martin <[email protected]> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
||
import sys | ||
from time import monotonic | ||
|
||
from xpra.codecs.image_wrapper import ImageWrapper | ||
|
||
N = 10 | ||
|
||
def main(argv): | ||
assert len(argv)>1, "specify images to benchmark" | ||
from xpra.net import compression | ||
compression.init_all() | ||
from xpra.codecs.loader import load_codec, get_codec | ||
|
||
FORMAT = "png" | ||
CODECS = ("enc_spng", "enc_pillow") | ||
for codec in CODECS: | ||
load_codec(codec) | ||
|
||
from PIL import Image | ||
for f in argv[1:]: | ||
img = Image.open(f) | ||
if img.mode not in ("RGBA", "RGB"): | ||
img = img.convert("RGB") | ||
#img.show() | ||
pixel_format = img.mode | ||
w, h = img.size | ||
rgb_data = img.tobytes("raw") | ||
stride = w * len(pixel_format) | ||
print("%s : %s" % (f, img)) | ||
image = ImageWrapper(0, 0, w, h, | ||
rgb_data, pixel_format, len(pixel_format)*8, stride, | ||
planes=ImageWrapper.PACKED, thread_safe=True) | ||
for codec in CODECS: | ||
enc = get_codec(codec) | ||
start = monotonic() | ||
for _ in range(N): | ||
try: | ||
r = enc.encode(FORMAT, image) | ||
except Exception: | ||
print("error on %s.%s" % (enc.get_type(), enc.encode)) | ||
raise | ||
if not r: | ||
print("Error: no data") | ||
break | ||
end = monotonic() | ||
print("%-10s : %.1f MPixels/s" % (enc.get_type(), w*h*N/(end-start)/1024/1024)) | ||
cdata = r[1] | ||
#verify that the png data is valid using pillow: | ||
from io import BytesIO | ||
buf = BytesIO(cdata.data) | ||
img = Image.open(buf) | ||
#img.show() | ||
|
||
if __name__ == '__main__': | ||
main(sys.argv) |