Little CMS wrapper for Rust
Convert and apply color profiles with a safe abstraction layer for the LCMS library. LCMS2 is a mature, fully-featured color management engine. These bindings have been stable for years, and used in production at scale.
See the API reference for the Rust functions, and the LCMS2 documentation in HTML/or the original PDF for more background information about the functions.
use *;
To apply an ICC profile from a JPEG:
if b"ICC_PROFILE\0" == &app2_marker_data
There's more in the examples
directory.
This crate requires Rust 1.64 or later. It's up to date with LCMS 2.15, and should work with a wide range of versions.
Threads
In LCMS all functions are in 2 flavors: global and *THR()
functions. In this crate this is represented by having functions with GlobalContext
and ThreadContext
. Create profiles, transforms, etc. using *_context()
constructors to give them their private context, which makes them sendable between threads (i.e. they're Send
).
By default Transform
does not implement Sync
, because LCMS2 has a thread-unsafe cache in the transform. You can set Flags::NO_CACHE
to make it safe (this is checked at compile time).
Upgrading from v5
If you're using a custom RGB type with Transform
, implement bytemuck::Pod
and Zeroable
for it. Make sure you use arrays or #[repr(C)]
struct types for pixels. Rust tuples have a technically undefined layout, and can't be used as as a pixel format.
unsafe impl Pod for RGB {}
unsafe impl Zeroable for RGB {}
You don't need to do this if you use the rgb
crate.