Skip to content

0.7.0

Latest

Choose a tag to compare

@ainame ainame released this 28 Sep 18:51
· 8 commits to main since this release

Breaking

Source-compatible, but some calls now behave differently at runtime:

  • Encoder inputs must contain stride * originHeight bytes, including final-row padding, matching libwebp's documented contract. Compact padded buffers that the unchecked pointer API previously accepted now throw invalidParameter. (#66)
  • UIImage encoding no longer downscales @2x/@3x images to their point size; output now has the image's full pixel dimensions. To keep the previous size, pass width/height in points. (#68)

Added

  • WebPEncoder.encode(normalizing:config:resizeWidth:resizeHeight:) for CGImage, which converts premultiplied, BGRA, 16-bit, and other layouts to straight-alpha RGBA before encoding. The existing encode(_:format:config:resizeWidth:resizeHeight:) still encodes the backing bytes as-is. (#68)
  • Safe encoding entrypoints that accept pixels as [UInt8], Data, or a borrowed Span<UInt8>. (#66)
  • Decoding into a caller-provided MutableSpan<UInt8>. (#66)
  • WebPImageInspector.inspect(_:) overload for a borrowed Span<UInt8>. (#66)
  • WebPDecoderConfig.validate(), backed by libwebp's decoder configuration validation. (#65)

Changed

  • Raised the libwebp-Xcode dependency minimum to 1.6.0, picking up upstream lossless compression improvements and bug fixes. Projects that pin libwebp-Xcode below 1.6.0 need to relax that pin. (#65)
  • Invalid decoder settings are now rejected up front with WebPDecodingError.invalidParam, before any output buffer is allocated. (#65)

Fixed

  • NSImage and UIImage encoding 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 Data on 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 Data APIs come from FoundationEssentials when 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)