[−][src]Function lab::simd::labs_to_rgbs_chunk
pub fn labs_to_rgbs_chunk(labs: &[Lab]) -> [[u8; 3]; 8]
Convert a slice of 8 Lab
structs into an array of 8 RGB ([u8; 3]
) triples.
This is the fundamental unit of work that lab::simd::labs_to_rgbs
performs.
If you need to control how to parallelize this work, use this function.
Only the first 8 elements of the input slice will be converted. The example given
is very close to the implementation of lab::simd::labs_to_rgbs
. Because this
library makes no assumptions about how to parallelize work, use this function
to add parallelization with Rayon, etc.
Example
#[cfg(target_arch = "x86_64")] { if is_x86_feature_detected!("avx") && is_x86_feature_detected!("sse4.1") { let chunks = labs.chunks_exact(8); let remainder = chunks.remainder(); // Parallelizing work with Rayon? Do it here, at `.fold()` let mut vs = chunks.fold(Vec::with_capacity(labs.len()), |mut v, labs| { let rgbs = lab::simd::labs_to_rgbs_chunk(labs); v.extend_from_slice(&rgbs); v }); if remainder.len() > 0 { const BLANK_LAB: Lab = Lab { l: f32::NAN, a: f32::NAN, b: f32::NAN }; let labs: Vec<Lab> = remainder.iter().cloned().chain(iter::repeat(BLANK_LAB)) .take(8) .collect(); let rgbs = lab::simd::labs_to_rgbs_chunk(&labs); vs.extend_from_slice(&rgbs[..remainder.len()]); } } }
Panics
This function will panic of the input slice has fewer than 8 elements. Consider padding the input slice with blank values and then truncating the result.
Additionally, it will panic if run on a CPU that does not support x86_64's AVX and SSE 4.1 instructions.