rust-turbojpeg
Rust bindings for TurboJPEG, which provides simple and fast operations for JPEG images:
- Compression (encoding)
- Decompression (decoding)
- Lossless transformations
Usage with image-rs
To quickly encode and decode images from the image crate, add this
to the [dependencies] section in your Cargo.toml:
turbojpeg = {version = "0.4", features = ["image"]}
and then use the functions turbojpeg::decompress_image and
turbojpeg::compress_image.
For more advanced usage without the image crate, please see the
documentation.
Requirements
The low-level binding to libturbojpeg is provided by the crate
turbojpeg-sys, which needs:
- Rust binding code generated from C headers using
bindgen. - Linker flags that
rustcwill use to link againstlibturbojpeg.
By default, the turbojpeg-sys crate uses a pregenerated Rust binding code (so
you don't need the C headers) and the default linker flags -l turbojpeg.
However, this behavior can be altered in several ways:
- Feature flag
pkg-configuses thepkg-configtool to find the linker flags and the include paths for C headers that are specific for your system. - Environment variable
TURBOJPEG_INCLUDE_PATH, if specified, adds an extra include path for C headers. - Feature flag
bindgenuses thebindgentool to generate Rust binding code at build time, instead of using the pregenerated code. If no include paths are specified (usingpkg-configorTURBOJPEG_INCLUDE_PATH), we use headers that are bundled withturbojpeg-sys.
All this magic is implemented in the build.rs script in turbojpeg-sys. If
you think that it could be improved, or if you encounter an error on your
system, please open an issue or a pull request.
Contributing
All contributions are welcome! Please contact me (@honzasp) or open a pull request. This crate is rather minimal, the main areas of improvement are:
- Improving the build process of
turbojpeg-syscrate, so that it works seamlessly on a wide range of systems. - Testing.
- Extending the safe Rust API provided by
turbojpegcrate.
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.