All Projects → kornelski → rust-lcms2

kornelski / rust-lcms2

Licence: other
ICC color profiles in Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rust-lcms2

i2p-rs
Rust client library for interacting with I2P
Stars: ✭ 62 (+148%)
Mutual labels:  rust-library
tentacle
A multiplexed p2p network framework that supports custom protocols
Stars: ✭ 41 (+64%)
Mutual labels:  rust-library
shell2batch
Coverts simple basic shell scripts to windows batch scripts.
Stars: ✭ 42 (+68%)
Mutual labels:  rust-library
arangors
Easy to use rust driver for arangoDB
Stars: ✭ 120 (+380%)
Mutual labels:  rust-library
contour-rs
Contour polygon creation in Rust (using marching squares algorithm)
Stars: ✭ 33 (+32%)
Mutual labels:  rust-library
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (+296%)
Mutual labels:  rust-library
mozjpeg-sys
Rust bindings for mozjpeg
Stars: ✭ 26 (+4%)
Mutual labels:  ffi-wrapper
rsmorphy
Morphological analyzer / inflection engine for Russian and Ukrainian languages rewritten in Rust
Stars: ✭ 27 (+8%)
Mutual labels:  rust-library
twitter-stream-rs
A Rust library for listening on Twitter Streaming API.
Stars: ✭ 66 (+164%)
Mutual labels:  rust-library
codebreaker-rs
A Rust library to decrypt & encrypt any cheat code for CodeBreaker PS2
Stars: ✭ 18 (-28%)
Mutual labels:  rust-library
crc32c
Fast CRC-32-Castagnoli implementation in Rust
Stars: ✭ 26 (+4%)
Mutual labels:  rust-library
vfin
🦈 GUI framework agnostic virtual DOM library
Stars: ✭ 17 (-32%)
Mutual labels:  rust-library
colorful
Make your terminal output colorful.
Stars: ✭ 43 (+72%)
Mutual labels:  rust-library
Awesome-Rust-MachineLearning
This repository is a list of machine learning libraries written in Rust. It's a compilation of GitHub repositories, blogs, books, movies, discussions, papers, etc. 🦀
Stars: ✭ 1,110 (+4340%)
Mutual labels:  rust-library
rustgraphblas
rust-library to wrap GraphBLAS.h
Stars: ✭ 23 (-8%)
Mutual labels:  rust-library
hidapi-rs
Rust bindings for the hidapi C library
Stars: ✭ 103 (+312%)
Mutual labels:  rust-library
rust-ffi-examples
FFI examples written in Rust
Stars: ✭ 42 (+68%)
Mutual labels:  ffi-wrapper
type-metadata
Rust type metadata reflection library
Stars: ✭ 27 (+8%)
Mutual labels:  rust-library
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (+0%)
Mutual labels:  rust-library
ghakuf
A Rust library for parsing/building SMF (Standard MIDI File).
Stars: ✭ 30 (+20%)
Mutual labels:  rust-library

Little CMS wrapper for Rust

Convert and apply color profiles with a safe abstraction layer for the LCMS library.

See API reference for Rust functions and the LCMS2 documentation HTML/PDF for more background information about the functions.

use lcms2::*;

fn example() -> Result<(), std::io::Error> {
    let icc_file = include_bytes!("custom_profile.icc"); // You can use Profile::new_file("path"), too
    let custom_profile = Profile::new_icc(icc_file)?;

    let srgb_profile = Profile::new_srgb();

    let t = Transform::new(&custom_profile, PixelFormat::RGB_8, &srgb_profile, PixelFormat::RGB_8, Intent::Perceptual);

    // Pixel struct must have layout compatible with PixelFormat specified in new()
    let source_pixels: &[rgb::RGB<u8>] = …;
    t.transform_pixels(source_pixels, destination_pixels);

    // If input and output pixel formats are the same, you can overwrite them instead of copying
    t.transform_in_place(source_and_dest_pixels);

    Ok(())
}

To apply an ICC profile from a JPEG:

if b"ICC_PROFILE\0" == &app2_marker_data[0..12] {
   let icc = &app2_marker_data[14..]; // Lazy assumption that the profile is smaller than 64KB
   let profile = Profile::new_icc(icc)?;
   let t = Transform::new(&profile, PixelFormat::RGB_8,
       &Profile::new_srgb(), PixelFormat::RGB_8, Intent::Perceptual);
   t.transform_in_place(&mut rgb);
}

There's more in the examples directory.

This crate requires Rust 1.33 or later. It's up to date with LCMS 2.10, and should work with 2.6 to 2.11.

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 coontext, 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).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].