Breaking
Source-compatible, but some calls now behave differently at runtime:
- Encoder inputs must contain
stride * originHeightbytes, including final-row padding, matching libwebp's documented contract. Compact padded buffers that the unchecked pointer API previously accepted now throwinvalidParameter. (#66) UIImageencoding no longer downscales@2x/@3ximages to their point size; output now has the image's full pixel dimensions. To keep the previous size, passwidth/heightin points. (#68)
Added
WebPEncoder.encode(normalizing:config:resizeWidth:resizeHeight:)forCGImage, which converts premultiplied, BGRA, 16-bit, and other layouts to straight-alpha RGBA before encoding. The existingencode(_:format:config:resizeWidth:resizeHeight:)still encodes the backing bytes as-is. (#68)- Safe encoding entrypoints that accept pixels as
[UInt8],Data, or a borrowedSpan<UInt8>. (#66) - Decoding into a caller-provided
MutableSpan<UInt8>. (#66) WebPImageInspector.inspect(_:)overload for a borrowedSpan<UInt8>. (#66)WebPDecoderConfig.validate(), backed by libwebp's decoder configuration validation. (#65)
Changed
- Raised the
libwebp-Xcodedependency minimum to1.6.0, picking up upstream lossless compression improvements and bug fixes. Projects that pinlibwebp-Xcodebelow1.6.0need to relax that pin. (#65) - Invalid decoder settings are now rejected up front with
WebPDecodingError.invalidParam, before any output buffer is allocated. (#65)
Fixed
NSImageandUIImageencoding no longer assumes straight RGBA, fixing darkened translucent colors and swapped red/blue channels for premultiplied, BGRA, or 16-bit images (e.g. from drawing or screen capture). Straight 8-bit layouts such as decoded PNGs and JPEGs are still encoded from their backing bytes without a copy. Thanks to macshot for documenting the workaround that exposed this issue. (#68)- Encoder input capacity, row stride, and dimensions are validated before pixel memory is read, including in the deprecated raw-pointer encoder. (#66)
- CoreGraphics pixel storage is retained for the whole duration of encoding. (#66)
- Partially written encoder output is freed on failure. (#66)
- Decode buffer sizing when one scaled dimension is zero, including scaling after cropping and rounding up inferred dimensions. (#65)
- Crop validation keeps exact origins for lossless images and snaps to even pixels only for lossy images. (#65)
- Platform image helpers now use the resolved output dimensions for cropping and inferred scaling. (#65)
Performance
- Decoding writes into an uninitialized allocation that is handed directly to
Dataon success, avoiding zero-filling and a duplicate layout inspection. (#66) - Bitstream feature inspection uses a stack-local C structure instead of a heap allocation. (#66)
- Core
DataAPIs come fromFoundationEssentialswhen available, and unused Foundation imports were removed, reducing Foundation dependencies on Linux. (#67)
Demo
- Added a visual comparison of the old platform image encoding bugs against the corrected WebP output. (#68)