The markdown parsing is broken/disabled for release notes. Sorry about that, I'm chasing the source of a crash that's been bringing this website down for the last couple of days.
this release patches a critical vulnerability that occurs when the *DEFLATE* backend attempts to compress very short inputs (less than 3 bytes) causing a **runtime crash**.
for applications using the library for PNG compression, the attack is only effective if the server is asked to compress a 1x1 pixel grayscale image, as all other types of PNG images create data streams that are longer than 2 bytes.
all *Swift PNG* users are advised to upgrade to 4.4.1 immediately.
*Swift PNG* 4.4 adds gzip compression and decompression tools to the `LZ77` module, and updates the documentation with [examples of how to use gzip compression](https://swiftinit.org/docs/swift-png/lz77#Gzip%20compression) in your app.
Internally, *Swift PNG* 4.4 also adopts nested protocols ([SE-0404](https://github.com/apple/swift-evolution/blob/main/proposals/0404-nested-protocols.md)), which makes the documentation easier to navigate but should be an API-transparent change, as all of these protocols were already informally namespaced via `typealias`es.
*Swift PNG* 4.4 requires Swift 5.10 or newer.
## Why use *Swift PNG*’s gzip implementation?
*Swift PNG*’s native Swift gzip implementation is not as fast as some existing C libraries which are found on many systems. However, a lot of optimization work went into the LZ77 module long ago, and the Swift version should not be *significantly* slower than an equivalent C library.
Applications that compress large volumes of data and do little else may be better off calling a system C library instead of using `LZ77`. However the complexity of marshaling data through a C library can often be a disincentive to using compression in more peripheral use cases, and having a convenient, portable Swift library available that still performs reasonably well can help make applications more efficient overall.
## Why is the gzip library still part of *Swift PNG*?
The compression backend was written long ago exclusively for *Swift PNG*, and the decision to expose it to external clients was only made recently. The PNG library helps us test the correctness of the gzip backend, as the PNG format is little more than a wrapper around an LZ77 data stream.
Applications that depend on the `LZ77` target only will not pull in PNG-related code.
## How can I help?
Rewriting the project’s [benchmarks](https://github.com/tayloraswift/swift-png/tree/master/Benchmarks) to use the more-modern [`package-benchmark`](https://github.com/ordo-one/package-benchmark) framework would help us gain better visibility into how the library is performing relative to system C libraries. PRs that add benchmark integrations to the project are likely to be merged.
This release is almost entirely focused on documentation, as much of the library’s existing docs had rotted due to evolution of tooling. We have rewritten the package’s examples and tutorials and repaired scores of broken doccomments, and the package’s documentation is [now available](https://swiftinit.org/docs/swift-png/png) on swiftinit.org.
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`](https://stackoverflow.com/questions/7243705/what-is-the-advantage-of-gzip-vs-deflate-compression) 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](https://github.com/tayloraswift/swift-png/blob/master/Snippets/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.
Swift PNG 4.0.1
2 years ago
Minor concurrency patch: Adds `Sendable` conformances to the built-in generic `RGBA<T>` and `VA<T>` types.
Swift PNG 4.0
3 years ago
<p align="center">
<strong><em>Swift PNG</em></strong> <br/> 4.0.0
</p>
## features
- ***Powerful interfaces.*** *Swift PNG*’s expressive, strongly-typed APIs make working with PNG images easy for beginners and advanced users alike. If your code compiles, you’re already most of the way there. Power users can take advantage of [custom indexing](../../tree/master/examples/#using-indexed-images), [manual decoding workflows](../../tree/master/examples/#online-decoding), and [user-defined color targets](../../tree/master/examples/#custom-color-targets).
- ***Superior compression***. *Swift PNG* supports minimum cost path-based [*DEFLATE*](https://tools.ietf.org/html/rfc1951) optimization, which is why it offers four additional compression levels beyond what [*libpng*](http://www.libpng.org/pub/png/libpng.html) supports. *Swift PNG* outperforms *libpng* at its highest compression setting by [significant margins](../../tree/master/benchmarks#compression-level-13) for almost all types of input images.
- ***Competitive performance.*** *Swift PNG* offers [competitive performance](../../tree/master/benchmarks/) compared to *libpng*. On appropriate CPU architectures, the *Swift PNG* encoder makes use of [hardware-accelerated hash tables](https://engineering.fb.com/2019/04/25/developer-tools/f14/) for even greater performance.
- ***Pure Swift, all the way down.*** Aside from having no external dependencies, *Swift PNG* is powered by its own, native Swift *DEFLATE* implementation. This means *Swift PNG* works on any platform that Swift itself works on. It also means that *Swift PNG*’s performance [improves as the Swift compiler matures](../../tree/master/benchmarks#performance-by-toolchain).
- ***Batteries included.*** *Swift PNG* comes with [built-in color targets](https://kelvin13.github.io/png/PNG/Color/) with support for [premultiplied alpha](https://kelvin13.github.io/png/PNG/RGBA/premultiplied/). [Convolution](https://kelvin13.github.io/png/PNG/convolve(_:dereference:kernel:)/) and [deconvolution](https://kelvin13.github.io/png/PNG/deconvolve(_:reference:kernel:)/) helper functions make [implementing custom color targets](../../tree/master/examples/#custom-color-targets) a breeze.
On MacOS and Linux, *Swift PNG* has built-in file system support, allowing you to [compress](https://kelvin13.github.io/png/PNG/Data/Rectangular/compress(path:level:hint:)/) or [decompress](https://kelvin13.github.io/png/PNG/Data/Rectangular/decompress(path:)/) an image, given a filepath, in a single function call. Other platforms can take advantage of *Swift PNG*’s [protocol-oriented IO](https://kelvin13.github.io/png/PNG/Bytestream/) to implement their own data loading.
- ***First-class iPhone optimization support.*** *Swift PNG* requires no custom setup or third-party plugins to handle [iPhone-optimized](../../tree/master/examples/#using-iphone-optimized-images) PNG images. iPhone-optimized images just work, on all platforms. Reproduce [`pngcrush`](https://developer.apple.com/library/archive/qa/qa1681/_index.html)’s output with [bit width-aware alpha premultiplication](https://kelvin13.github.io/png/PNG/RGBA/premultiplied(as:)/), for seamless integration anywhere in your application stack.
- ***Comprehensive metadata support.*** *Swift PNG* can parse and validate all public PNG chunks, which are accessible as [strongly-typed metadata records](https://kelvin13.github.io/png/PNG/Metadata/).
- ***Modern error handling.*** *Swift PNG* has a fully stateless and Swift-native [error-handling system](https://kelvin13.github.io/png/PNG/Error/).
This release addresses `@_specialize` warnings produced by compiler PR [#30962](https://github.com/apple/swift/pull/30962) which affects users using the nightly 5.2+ builds.
This release fixes some compiler warnings due to compiler drift from Swift 4.2 to 5.2+, and with the agreement of all contributors, [re-licenses](https://github.com/kelvin13/png/commit/a8c94cc4ef539f8d7300492c6c3d7c3265f44d61) the library under a weaker copyleft license, the Mozilla Public License 2.0.
The library has been completely rewritten since version 2.0.1 and now features a much streamlined and improved API, as well as ancillary PNG chunk support, and a wider variety of color format inputs and outputs. Grayscale–alpha and indexed color now have first-class status in the 3.0 API, and are fully integrated with all PNG color backends in the file format’s specification. The typing system has also been greatly strengthened, resulting in an API which returns far fewer optionals, provides more expressive enumerations, and has a much greater chance of catching errors at compile time.
This release adds a new overload to `png_encode(path:raw_data:properties:chunk_size:)` that takes a Swift `UnsafeBufferPointer<UInt8>` instead of an `Array`, to avoid having to recopy a foreign array into Swift managed memory.