#rgb #color-space #color #color-conversion #pixel

lab

Tools for converting RGB colors to the CIE-L*a*b* color space, and comparing differences in color

18 releases (10 breaking)

Uses old Rust 2015

0.11.0 Jul 30, 2021
0.9.0 Mar 20, 2021
0.8.2 Dec 10, 2020
0.8.1 Aug 14, 2020
0.3.0 Jan 30, 2017

#79 in Images

Download history 5578/week @ 2023-12-23 10959/week @ 2023-12-30 14634/week @ 2024-01-06 22227/week @ 2024-01-13 17936/week @ 2024-01-20 13537/week @ 2024-01-27 12982/week @ 2024-02-03 11773/week @ 2024-02-10 11204/week @ 2024-02-17 11551/week @ 2024-02-24 10803/week @ 2024-03-02 12053/week @ 2024-03-09 13016/week @ 2024-03-16 14152/week @ 2024-03-23 12145/week @ 2024-03-30 9892/week @ 2024-04-06

51,428 downloads per month
Used in 45 crates (15 directly)

MIT license

62KB
1.5K SLoC

Lab

Lab crate Lab documentation minimum rustc 1.31 TravisCI Build Status AppVeyor Build Status

Tools for converting RGB colors to L*a*b* measurements.

RGB colors, for this crate at least, are considered to be composed of u8 values from 0 to 255, while L*a*b* colors are represented by its own struct that uses f32 values.

Usage

Converting single values

To convert a single value, use one of the functions

  • lab::Lab::from_rgb(rgb: &[u8; 3]) -> Lab
  • lab::Lab::from_rgba(rgba: &[u8; 4]) -> Lab (drops the fourth alpha byte)
  • lab::Lab::to_rgb(&self) -> [u8; 3]
extern crate lab;
use lab::Lab;

let pink_in_lab = Lab::from_rgb(&[253, 120, 138]);
// Lab { l: 66.639084, a: 52.251457, b: 14.860654 }

Converting multiple values

To convert slices of values

  • lab::rgbs_to_labs(rgbs: &[[u8; 3]]) -> Vec<Lab>
  • lab::labs_to_rgbs(labs: &[Lab]) -> Vec<[u8; 3]>
  • lab::rgb_bytes_to_labs(bytes: &[u8]) -> Vec<Lab>
  • lab::labs_to_rgb_bytes(labs: &[Lab]) -> Vec<u8>
extern crate lab;
use lab::rgbs_to_labs;

let rgbs = vec![
    [0xFF, 0x69, 0xB6],
    [0xE7, 0x00, 0x00],
    [0xFF, 0x8C, 0x00],
    [0xFF, 0xEF, 0x00],
    [0x00, 0x81, 0x1F],
    [0x00, 0xC1, 0xC1],
    [0x00, 0x44, 0xFF],
    [0x76, 0x00, 0x89],
];

let labs = rgbs_to_labs(&rgbs);
extern crate lab;
use lab::rgb_bytes_to_labs;

let rgbs = vec![
    0xFF, 0x69, 0xB6,
    0xE7, 0x00, 0x00,
    0xFF, 0x8C, 0x00,
    0xFF, 0xEF, 0x00,
    0x00, 0x81, 0x1F,
    0x00, 0xC1, 0xC1,
    0x00, 0x44, 0xFF,
    0x76, 0x00, 0x89,
];

let labs = rgb_bytes_to_labs(&rgbs);

These functions will use x86_64 AVX2 instructions if compiled to a supported target.

Minimum Rust version

Lab 0.8.0 requires Rust >= 1.36.0 for the MaybeUninit struct

Lab 0.7.0 requires Rust >= 1.31.0 for the chunks_exact slice method

No runtime deps