#yuv #pixel-format #format-conversion #optimization #simd #pure #frame

pixelfmt

Pixel format conversions in pure Rust with SIMD optimizations

1 unstable release

0.1.0 Oct 22, 2024

#220 in Images

Download history 164/week @ 2024-10-21

164 downloads per month

MIT/Apache

59KB
1K SLoC

pixelfmt

crates.io docs.rs CI

Pixel format conversions in pure Rust with SIMD optimizations on x86_64 and aarch64. The performance goal is to approximately reach the memory bandwidth limit and thus optimal performance when the input and output are not already in CPU cache.

Limitations and future work:

  • Supports exactly one conversion: UYVY to I420. More will be added as needed.
  • Expects to process full horizontal lines. This is likely to change to allow working on cropped regions.
  • Does not support output to a frame with padding, as required by some APIs/devices.
  • The ARM NEON code is less optimized than the AVX2 code today.

You may find the notes in docs/simd.md helpful if you are new to SIMD and thinking of contributing.

Alternatives

The main alternative to pixelfmt is Chrome's C++ libyuv library. Rust bindings are available via the yuv-sys or libyuv crates.

Some reasons to prefer pixelfmt:

  • pixelfmt is pure Rust and thus may be easier and quicker to build, particularly when cross-compiling.
  • pixelfmt is less total code.
  • pixelfmt's uyvy_to_i420 implementation benchmarks as slightly faster than libyuv's. This appears to come down to design choices: libyuv has separate routines to extract the Y and U+V planes, where pixelfmt gains some performance by doing it all with a single read of the UYVY data. pixelfmt also has a hand-optimized conversion function where libyuv uses a more generalized autovectorization approach.
  • pixelfmt uses safe Rust when possible, where libyuv is entirely written in (unsafe) C++. That said, pixelfmt still has a fair bit of unsafe logic for vendor SIMD intrinsics.

Some reasons to prefer libyuv:

  • libyuv is much more widely used.
  • libyuv is much more comprehensive and flexible.

License

SPDX-License-Identifier: MIT OR Apache-2.0

See LICENSE-MIT.txt or LICENSE-APACHE, respectively.

Dependencies

~69KB