in src/convert_image/sse2.rs [1382:1467]
fn rgb_i444<const SAMPLER: usize, const DEPTH: usize, const COLORIMETRY: usize>(
width: u32,
height: u32,
_last_src_plane: usize,
src_strides: &[usize],
src_buffers: &[&[u8]],
_last_dst_plane: usize,
dst_strides: &[usize],
dst_buffers: &mut [&mut [u8]],
) -> bool {
// Degenerate case, trivially accept
if width == 0 || height == 0 {
return true;
}
// Check there are sufficient strides and buffers
if src_strides.is_empty()
|| src_buffers.is_empty()
|| dst_strides.len() < 3
|| dst_buffers.len() < 3
{
return false;
}
let w = width as usize;
let h = height as usize;
let rgb_stride = DEPTH * w;
// Compute actual strides
let src_stride = compute_stride(src_strides[0], rgb_stride);
let dst_strides = (
compute_stride(dst_strides[0], w),
compute_stride(dst_strides[1], w),
compute_stride(dst_strides[2], w),
);
// Ensure there is sufficient data in the buffers according
// to the image dimensions and computed strides
let src_buffer = &src_buffers[0];
let (y_plane, uv_plane) = dst_buffers.split_at_mut(1);
let (u_plane, v_plane) = uv_plane.split_at_mut(1);
let (y_plane, u_plane, v_plane) = (&mut *y_plane[0], &mut *u_plane[0], &mut *v_plane[0]);
if out_of_bounds(src_buffer.len(), src_stride, h - 1, rgb_stride)
|| out_of_bounds(y_plane.len(), dst_strides.0, h - 1, w)
|| out_of_bounds(u_plane.len(), dst_strides.1, h - 1, w)
|| out_of_bounds(v_plane.len(), dst_strides.2, h - 1, w)
{
return false;
}
// Process vector part and scalar one
let vector_part = if DEPTH == 3 {
(DEPTH * RGB_TO_YUV_WAVES) * (w / (DEPTH * RGB_TO_YUV_WAVES))
} else {
lower_multiple_of_pot(w, RGB_TO_YUV_WAVES)
};
let scalar_part = w - vector_part;
if vector_part > 0 {
unsafe {
rgb_to_i444_sse2::<SAMPLER, DEPTH, COLORIMETRY>(
vector_part,
h,
src_stride,
src_buffer,
dst_strides,
&mut (y_plane, u_plane, v_plane),
);
}
}
if scalar_part > 0 {
let x = vector_part;
let sx = x * DEPTH;
x86::rgb_to_i444::<SAMPLER, DEPTH, COLORIMETRY>(
scalar_part,
h,
src_stride,
&src_buffer[sx..],
dst_strides,
&mut (&mut y_plane[x..], &mut u_plane[x..], &mut v_plane[x..]),
);
}
true
}