Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / gfx / qcms / README.md
blob1997abcabec40a59af8e99012f8fc83638c533ef
1 # qcms
2 [![Crates.io](https://img.shields.io/crates/v/qcms.svg)](https://crates.io/crates/qcms)
3 [![Documentation](https://docs.rs/qcms/badge.svg)](https://docs.rs/qcms)
6 Firefox's library for transforming image data between ICC profiles.
8 ## Example
9 ```rust
10     // Decode the jpeg
11     let mut d = jpeg_decoder::Decoder::new(std::fs::File::open("/Users/jrmuizel/Desktop/DSCF2460.jpg").unwrap());
12     let mut data = d.decode().unwrap();
13     let info = d.info().unwrap();
15     // Extract the profile after decode
16     let profile = d.icc_profile().unwrap();
18     // Create a new qcms Profile
19     let input = qcms::Profile::new_from_slice(&profile).unwrap();
20     let mut output = qcms::Profile::new_sRGB();
21     output.precache_output_transform();
23     // Create a transform between input and output profiles and apply it.
24     let xfm = qcms::Transform::new(&input, &output, qcms::DataType::RGB8, qcms::Intent::default()).unwrap();
25     xfm.apply(&mut data);
27     // write the result to a PNG
28     let mut encoder = png::Encoder::new(std::fs::File::create("out.png").unwrap(), info.width as u32, info.height as u32);
29     encoder.set_color(png::ColorType::Rgb);
30     encoder.set_srgb(png::SrgbRenderingIntent::Perceptual);
31     let mut writer = encoder.write_header().unwrap();
32     writer.write_image_data(&data).unwrap(); // Save
33 ```
35 This library was originally written in C, was converted to Rust using [c2rust](https://c2rust.com/), and then refactored to be mostly
36 safe and more idiomatic Rust.