SwiftPNG 4.1 released!

hi all, swift-png 4.1 has been released!


This release is focused on separating out the LZ77/DEFLATE implementation from the rest of the library, and making it available for use as a general-purpose data compressor. The package now vends a separate library target, LZ77, which exposes the DEFLATE implementation.

Currently, only the deflate wrapper format is supported, although we plan on supporting the gzip wrapper format in a future release. An example of how to use the new API can be found in the BasicCompression.swift snippet.

While preparing this release, it was discovered that SIMD-accelerated encoding backend was broken on Apple Silicon; a problem that was only uncovered upon upgrading the CI runners to macOS 14. This bug has been fixed in 4.1.

8 Likes

Out of tangential curiosity, why the continued work on a PNG library, as opposed to e.g. WebP or AVIF?

PNG is still a very relevant image format.

3 Likes

i do not do much work with image processing anymore, so i had no reason to write libraries for some of the newer formats, although it would be nice if those libraries existed. my main goal in this update was to separate the library code into an LZ77 module and a PNG-specific library module to be able to make use of the pure-swift DEFLATE compressor from other clients.

Yes, but on the decline.

I was asking because currently there's no great options for newer formats, in Swift. It's possible to integrate libwebp, libavif, etc, but it's awkward and with SPM you can't easily get full performance from them. Even if you permit an Apple dependency and use CoreImage etc, Apple doesn't provide encoders for them.

I'd love to see a more Swift-native version of them, like swift-png for PNG.

i agree. (but not with PNG being “on the decline”, as far as i can tell the format is alive and kicking) i just don’t have time personally to budget towards writing those libraries, my main priority at the moment is getting a real, pure-swift gzip implementation ready for production, which would have a lot of applications on the server.

it would be great if some of the deeper-pocketed stakeholders in this community could pitch in to fund the development of such libraries though.

7 Likes

BTW have you tried the workaround for Windows?

the project doesn’t have Windows CI anymore (does anyone?). but i’ve added the flags from the linked thread to the manifest so maybe it will work now.

update: ended up having to revert that patch, because .unsafeFlags(["-parse-as-library"], .when(platforms: [.windows])) was preventing users from depending on the package from any platform.

$ swift build
error: the target 'LZ77' in product 'LZ77' contains unsafe build flags
error: ExitCode(rawValue: 1)

it does not make sense to me why SPM rejects the dependency even on platforms that are not windows.

(i do not even know who to ping about this, as i don’t know who is responsible for SPM these days.)

1 Like