| 1 | # Lab |
| 2 | |
| 3 | [](https://crates.io/crates/lab) |
| 4 | [](https://docs.rs/lab) |
| 5 |  |
| 6 | [](https://travis-ci.com/github/TooManyBees/lab) |
| 7 | [](https://ci.appveyor.com/project/TooManyBees/lab) |
| 8 | |
| 9 | Tools for converting RGB colors to L\*a\*b\* measurements. |
| 10 | |
| 11 | RGB colors, for this crate at least, are considered to be composed of `u8` |
| 12 | values from 0 to 255, while L\*a\*b\* colors are represented by its own struct |
| 13 | that uses `f32` values. |
| 14 | |
| 15 | # Usage |
| 16 | |
| 17 | ## Converting single values |
| 18 | |
| 19 | To convert a single value, use one of the functions |
| 20 | |
| 21 | * `lab::Lab::from_rgb(rgb: &[u8; 3]) -> Lab` |
| 22 | * `lab::Lab::from_rgba(rgba: &[u8; 4]) -> Lab` (drops the fourth alpha byte) |
| 23 | * `lab::Lab::to_rgb(&self) -> [u8; 3]` |
| 24 | |
| 25 | ```rust |
| 26 | extern crate lab; |
| 27 | use lab::Lab; |
| 28 | |
| 29 | let pink_in_lab = Lab::from_rgb(&[253, 120, 138]); |
| 30 | // Lab { l: 66.639084, a: 52.251457, b: 14.860654 } |
| 31 | ``` |
| 32 | |
| 33 | ## Converting multiple values |
| 34 | |
| 35 | To convert slices of values |
| 36 | |
| 37 | * `lab::rgbs_to_labs(rgbs: &[[u8; 3]]) -> Vec<Lab>` |
| 38 | * `lab::labs_to_rgbs(labs: &[Lab]) -> Vec<[u8; 3]>` |
| 39 | * `lab::rgb_bytes_to_labs(bytes: &[u8]) -> Vec<Lab>` |
| 40 | * `lab::labs_to_rgb_bytes(labs: &[Lab]) -> Vec<u8>` |
| 41 | |
| 42 | ```rust |
| 43 | extern crate lab; |
| 44 | use lab::rgbs_to_labs; |
| 45 | |
| 46 | let rgbs = vec![ |
| 47 | [0xFF, 0x69, 0xB6], |
| 48 | [0xE7, 0x00, 0x00], |
| 49 | [0xFF, 0x8C, 0x00], |
| 50 | [0xFF, 0xEF, 0x00], |
| 51 | [0x00, 0x81, 0x1F], |
| 52 | [0x00, 0xC1, 0xC1], |
| 53 | [0x00, 0x44, 0xFF], |
| 54 | [0x76, 0x00, 0x89], |
| 55 | ]; |
| 56 | |
| 57 | let labs = rgbs_to_labs(&rgbs); |
| 58 | ``` |
| 59 | |
| 60 | ```rust |
| 61 | extern crate lab; |
| 62 | use lab::rgb_bytes_to_labs; |
| 63 | |
| 64 | let rgbs = vec![ |
| 65 | 0xFF, 0x69, 0xB6, |
| 66 | 0xE7, 0x00, 0x00, |
| 67 | 0xFF, 0x8C, 0x00, |
| 68 | 0xFF, 0xEF, 0x00, |
| 69 | 0x00, 0x81, 0x1F, |
| 70 | 0x00, 0xC1, 0xC1, |
| 71 | 0x00, 0x44, 0xFF, |
| 72 | 0x76, 0x00, 0x89, |
| 73 | ]; |
| 74 | |
| 75 | let labs = rgb_bytes_to_labs(&rgbs); |
| 76 | ``` |
| 77 | |
| 78 | These functions will use x86_64 AVX2 instructions if compiled to a supported target. |
| 79 | |
| 80 | ## Minimum Rust version |
| 81 | |
| 82 | Lab 0.8.0 requires Rust >= 1.36.0 for the [MaybeUninit](https://doc.rust-lang.org/std/mem/union.MaybeUninit.html) struct |
| 83 | |
| 84 | Lab 0.7.0 requires Rust >= 1.31.0 for the [chunks_exact](https://doc.rust-lang.org/std/primitive.slice.html#method.chunks_exact) slice method |