in benches/benches.rs [359:439]
fn convert_from(
width: u32,
height: u32,
from_format: PixelFormat,
to_format: PixelFormat,
seed: u8,
perf: &mut PerfEvent,
) -> Option<u64> {
let pixels = (width as usize) * (height as usize);
let src_channels = match from_format {
PixelFormat::Bgr => 3,
_ /* Bgra */ => 4,
};
let src = alloc_buffer(src_channels * pixels, None);
let input_buffer = slice_from_buffer(src, Some(seed));
let input_data = &[input_buffer];
let shift = match to_format {
PixelFormat::Rgb | PixelFormat::I444 => 0,
_ => 1,
};
let num_planes = match to_format {
PixelFormat::Rgb | PixelFormat::Nv12 => 1,
_ => 3,
};
let color_space = match to_format {
PixelFormat::Rgb => ColorSpace::Rgb,
_ => ColorSpace::Bt601FR,
};
let dst = alloc_buffer((3 * pixels) >> shift, Some(seed));
let output_buffer = slice_from_buffer_mut(dst, None);
let mut output_data = Vec::with_capacity(3);
match to_format {
PixelFormat::Rgb | PixelFormat::Nv12 => output_data.push(&mut output_buffer[..]),
_ => {
let (y_data, uv_data) = output_buffer.split_at_mut(pixels);
let (u_data, v_data) = uv_data.split_at_mut(pixels >> (2 * shift));
output_data.push(&mut *y_data);
output_data.push(&mut *u_data);
output_data.push(&mut *v_data);
}
}
let src_format = ImageFormat {
pixel_format: from_format,
color_space: ColorSpace::Rgb,
num_planes: 1,
};
let dst_format = ImageFormat {
pixel_format: to_format,
color_space,
num_planes,
};
perf.start();
let result = convert_image(
width,
height,
&src_format,
None,
input_data,
&dst_format,
None,
&mut output_data,
);
let elapsed = perf.end();
if result.is_ok() {
assert!(!output_buffer.iter().all(|&x| x == 0));
}
dealloc_buffer(src);
dealloc_buffer(dst);
result.ok().map(|_x| elapsed)
}