[][src]Function lab::simd::rgbs_to_labs_chunk

pub fn rgbs_to_labs_chunk(rgbs: &[[u8; 3]]) -> [Lab; 8]

Convert a slice of 8 [u8; 3] RGB tripes into an array of 8 Lab structs.

This is the fundamental unit of work that lab::simd::rgbs_to_labs 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::rgbs_to_labs. 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 = rgbs.chunks_exact(8);
        let remainder = chunks.remainder();
        // Parallelizing work with Rayon? Do it here, at `.fold()`
        let mut vs = chunks.fold(Vec::with_capacity(rgbs.len()), |mut v, rgbs| {
            let labs = lab::simd::rgbs_to_labs_chunk(rgbs);
            v.extend_from_slice(&labs);
            v
        });

        if remainder.len() > 0 {
            const BLANK_RGB: [u8; 3] = [0u8; 3];
            let rgbs: Vec<[u8; 3]> =
                remainder.iter().cloned().chain(iter::repeat(BLANK_RGB))
                .take(8)
                .collect();

            let labs = lab::simd::rgbs_to_labs_chunk(&rgbs);
            vs.extend_from_slice(&labs[..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.