#color #pixel #rgb #lab

lab

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

11 releases (6 breaking)

0.7.0 Mar 6, 2019
0.6.0 Sep 30, 2018
0.5.0 Sep 25, 2018
0.4.3 Jun 1, 2018
0.3.0 Jan 30, 2017

#30 in Images

Download history 41/week @ 2018-12-20 12/week @ 2018-12-27 19/week @ 2019-01-03 16/week @ 2019-01-10 9/week @ 2019-01-17 12/week @ 2019-01-24 10/week @ 2019-01-31 10/week @ 2019-02-07 39/week @ 2019-02-14 35/week @ 2019-02-21 55/week @ 2019-02-28 23/week @ 2019-03-07 24/week @ 2019-03-14 312/week @ 2019-03-21 25/week @ 2019-03-28

195 downloads per month
Used in 3 crates

MIT license

37KB
598 lines

Rust library for converting RGB colors to the CIE-L*a*b* color space

AppVeyor Build Status

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 }
extern crate lab;
extern crate image;

use lab::Lab;
use image::Rgba;

let pixel: Rgba<u8> = Rgba { data: [253, 120, 138, 255] };
let lab = Lab::from_rgba(&pixel.data);
// Lab { l: 66.639084, a: 52.251457, b: 14.860654 }

lib.rs:

Lab

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

RGB colors, for this crate at least, are considered to be an array of u8 values ([u8; 3]), 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]

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]> To convert slices using SIMD (AVX, SSE 4.1) operations
  • lab::simd::rgbs_to_labs
  • lab::simd::labs_to_rgbs

Parallelization concerns

This crate makes no assumptions about how to parallelize work, so the above functions that convert slices do so in serial. Presently, parallelizing the functions that accept slices is a manual job of reimplementing them using their fundamental work function, and replacing one iterator method with its equivalent from Rayon.

lab::rgbs_to_labs and lab::labs_to_rgbs are convenience functions for rgbs.iter().map(Lab::from_rgb).collect(), which can easily be parallelized with Rayon by replacing iter() with par_iter().

For the SIMD based functions, their smallest unit of work is done by the functions lab::simd::rgbs_to_labs_chunk and lab::simd::labs_to_rgbs_chunk which both accept exactly 8 elements. See their respective docs for examples on where to add Rayon methods.

No runtime deps