#[inline(always)]
fn load_u32<const BE: bool>(v: u32) -> u32 {
if BE { u32::from_be(v) } else { u32::from_le(v) }
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgb96_to_rgb_row<const BE: bool>(rgb96: &[u32], rgb_out: &mut [u8], width: usize) {
debug_assert!(rgb96.len() >= width * 3, "rgb96 row too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out row too short");
for x in 0..width {
let src = x * 3;
let dst = x * 3;
rgb_out[dst] = (load_u32::<BE>(rgb96[src]) >> 24) as u8;
rgb_out[dst + 1] = (load_u32::<BE>(rgb96[src + 1]) >> 24) as u8;
rgb_out[dst + 2] = (load_u32::<BE>(rgb96[src + 2]) >> 24) as u8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgb96_to_rgb_u16_row<const BE: bool>(
rgb96: &[u32],
rgb_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(rgb96.len() >= width * 3, "rgb96 row too short");
debug_assert!(rgb_u16_out.len() >= width * 3, "rgb_u16_out row too short");
for x in 0..width {
let src = x * 3;
let dst = x * 3;
rgb_u16_out[dst] = (load_u32::<BE>(rgb96[src]) >> 16) as u16;
rgb_u16_out[dst + 1] = (load_u32::<BE>(rgb96[src + 1]) >> 16) as u16;
rgb_u16_out[dst + 2] = (load_u32::<BE>(rgb96[src + 2]) >> 16) as u16;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgb96_to_rgba_row<const BE: bool>(rgb96: &[u32], rgba_out: &mut [u8], width: usize) {
debug_assert!(rgb96.len() >= width * 3, "rgb96 row too short");
debug_assert!(rgba_out.len() >= width * 4, "rgba_out row too short");
for x in 0..width {
let src = x * 3;
let dst = x * 4;
rgba_out[dst] = (load_u32::<BE>(rgb96[src]) >> 24) as u8;
rgba_out[dst + 1] = (load_u32::<BE>(rgb96[src + 1]) >> 24) as u8;
rgba_out[dst + 2] = (load_u32::<BE>(rgb96[src + 2]) >> 24) as u8;
rgba_out[dst + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgb96_to_rgba_u16_row<const BE: bool>(
rgb96: &[u32],
rgba_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(rgb96.len() >= width * 3, "rgb96 row too short");
debug_assert!(
rgba_u16_out.len() >= width * 4,
"rgba_u16_out row too short"
);
for x in 0..width {
let src = x * 3;
let dst = x * 4;
rgba_u16_out[dst] = (load_u32::<BE>(rgb96[src]) >> 16) as u16;
rgba_u16_out[dst + 1] = (load_u32::<BE>(rgb96[src + 1]) >> 16) as u16;
rgba_u16_out[dst + 2] = (load_u32::<BE>(rgb96[src + 2]) >> 16) as u16;
rgba_u16_out[dst + 3] = 0xFFFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba128_to_rgb_row<const BE: bool>(
rgba128: &[u32],
rgb_out: &mut [u8],
width: usize,
) {
debug_assert!(rgba128.len() >= width * 4, "rgba128 row too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out row too short");
for x in 0..width {
let src = x * 4;
let dst = x * 3;
rgb_out[dst] = (load_u32::<BE>(rgba128[src]) >> 24) as u8;
rgb_out[dst + 1] = (load_u32::<BE>(rgba128[src + 1]) >> 24) as u8;
rgb_out[dst + 2] = (load_u32::<BE>(rgba128[src + 2]) >> 24) as u8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba128_to_rgb_u16_row<const BE: bool>(
rgba128: &[u32],
rgb_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(rgba128.len() >= width * 4, "rgba128 row too short");
debug_assert!(rgb_u16_out.len() >= width * 3, "rgb_u16_out row too short");
for x in 0..width {
let src = x * 4;
let dst = x * 3;
rgb_u16_out[dst] = (load_u32::<BE>(rgba128[src]) >> 16) as u16;
rgb_u16_out[dst + 1] = (load_u32::<BE>(rgba128[src + 1]) >> 16) as u16;
rgb_u16_out[dst + 2] = (load_u32::<BE>(rgba128[src + 2]) >> 16) as u16;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba128_to_rgba_row<const BE: bool>(
rgba128: &[u32],
rgba_out: &mut [u8],
width: usize,
) {
debug_assert!(rgba128.len() >= width * 4, "rgba128 row too short");
debug_assert!(rgba_out.len() >= width * 4, "rgba_out row too short");
for x in 0..width {
let i = x * 4;
rgba_out[i] = (load_u32::<BE>(rgba128[i]) >> 24) as u8;
rgba_out[i + 1] = (load_u32::<BE>(rgba128[i + 1]) >> 24) as u8;
rgba_out[i + 2] = (load_u32::<BE>(rgba128[i + 2]) >> 24) as u8;
rgba_out[i + 3] = (load_u32::<BE>(rgba128[i + 3]) >> 24) as u8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba128_to_rgba_u16_row<const BE: bool>(
rgba128: &[u32],
rgba_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(rgba128.len() >= width * 4, "rgba128 row too short");
debug_assert!(
rgba_u16_out.len() >= width * 4,
"rgba_u16_out row too short"
);
for x in 0..width {
let i = x * 4;
rgba_u16_out[i] = (load_u32::<BE>(rgba128[i]) >> 16) as u16;
rgba_u16_out[i + 1] = (load_u32::<BE>(rgba128[i + 1]) >> 16) as u16;
rgba_u16_out[i + 2] = (load_u32::<BE>(rgba128[i + 2]) >> 16) as u16;
rgba_u16_out[i + 3] = (load_u32::<BE>(rgba128[i + 3]) >> 16) as u16;
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgb96_to_rgb_u32_row<const BE: bool>(
rgb96: &[u32],
rgb_u32_out: &mut [u32],
width: usize,
) {
debug_assert!(rgb96.len() >= width * 3, "rgb96 row too short");
debug_assert!(rgb_u32_out.len() >= width * 3, "rgb_u32_out row too short");
for (o, &raw) in rgb_u32_out[..width * 3].iter_mut().zip(rgb96.iter()) {
*o = load_u32::<BE>(raw);
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba128_to_rgba_u32_row<const BE: bool>(
rgba128: &[u32],
rgba_u32_out: &mut [u32],
width: usize,
) {
debug_assert!(rgba128.len() >= width * 4, "rgba128 row too short");
debug_assert!(
rgba_u32_out.len() >= width * 4,
"rgba_u32_out row too short"
);
for (o, &raw) in rgba_u32_out[..width * 4].iter_mut().zip(rgba128.iter()) {
*o = load_u32::<BE>(raw);
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba128_to_rgb_u32_row<const BE: bool>(
rgba128: &[u32],
rgb_u32_out: &mut [u32],
width: usize,
) {
debug_assert!(rgba128.len() >= width * 4, "rgba128 row too short");
debug_assert!(rgb_u32_out.len() >= width * 3, "rgb_u32_out row too short");
for x in 0..width {
let src = x * 4;
let dst = x * 3;
rgb_u32_out[dst] = load_u32::<BE>(rgba128[src]);
rgb_u32_out[dst + 1] = load_u32::<BE>(rgba128[src + 1]);
rgb_u32_out[dst + 2] = load_u32::<BE>(rgba128[src + 2]);
}
}
#[cfg(all(test, feature = "std"))]
mod tests;