Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: encoder #7

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

william-silversmith
Copy link

This PR adds an spng encoder to the library and builds off of its sister PR #6 for improving the build process.

The encoder currently supports regular, progressive, and interlaced modes as well as a compression level setting. No support for palettes or optimization at this time.

import pyspng
from pyspng import ProgressiveMode
binary = pyspng.encode(numpy_array, progressive=ProgressiveMode.NONE, compress_level=6)

This also fixes an issue where spng was not able to decode GRAY+ALPHA colorspaces (see randy408/libspng#207) because the author of this library was so careful as to specify fmt. I replaced the spng calls with SPNG_FMT_PNG to enable that decoding.

The tests were updated to include synthetic encoding tests for correctness and benchmark performance. Here are my results on a Macbook Pro M1:

d: pil  compressed   noise     272.80ms
d: pil  compressed   gradient  140.74ms
d: pil  uncompressed noise     86.95ms
d: pil  uncompressed gradient  82.32ms
d: spng compressed   noise     148.25ms
d: spng compressed   gradient  73.53ms
d: spng uncompressed noise     30.85ms
d: spng uncompressed gradient  33.78ms
e: pil  compressed   noise     1534.95ms
e: pil  compressed   gradient  462.84ms
e: pil  uncompressed noise     285.58ms
e: pil  uncompressed gradient  127.78ms
e: spng compressed   noise     1153.44ms
e: spng compressed   gradient  272.75ms
e: spng uncompressed noise     397.57ms
e: spng uncompressed gradient  398.16ms

I might add a couple more commits tomorrow. Thanks for reading and for developing a great library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant