[][src]Crate lab

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.

Modules

simd

Experimental functions for parallel conversion using AVX and SSE4.1

Structs

Lab

Struct representing a color in L*a*b* space

Functions

labs_to_rgbs

Convenience function to map a slice of Lab values to RGB values in serial

rgbs_to_labs

Convenience function to map a slice of RGB values to Lab values in serial