#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_rgb_row<const BE: bool>(packed: &[u16], rgb_out: &mut [u8], width: usize) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out too short");
for x in 0..width {
let y_raw = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
let y8 = (y_raw >> 8) as u8;
let i = x * 3;
rgb_out[i] = y8;
rgb_out[i + 1] = y8;
rgb_out[i + 2] = y8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_rgba_row<const BE: bool>(packed: &[u16], rgba_out: &mut [u8], width: usize) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(rgba_out.len() >= width * 4, "rgba_out too short");
for x in 0..width {
let y_raw = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
let a_raw = if BE {
u16::from_be(packed[x * 2 + 1])
} else {
u16::from_le(packed[x * 2 + 1])
};
let y8 = (y_raw >> 8) as u8;
let a8 = (a_raw >> 8) as u8;
let i = x * 4;
rgba_out[i] = y8;
rgba_out[i + 1] = y8;
rgba_out[i + 2] = y8;
rgba_out[i + 3] = a8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_rgb_u16_row<const BE: bool>(
packed: &[u16],
rgb_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(rgb_u16_out.len() >= width * 3, "rgb_u16_out too short");
for x in 0..width {
let y = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
let i = x * 3;
rgb_u16_out[i] = y;
rgb_u16_out[i + 1] = y;
rgb_u16_out[i + 2] = y;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_rgba_u16_row<const BE: bool>(
packed: &[u16],
rgba_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(rgba_u16_out.len() >= width * 4, "rgba_u16_out too short");
for x in 0..width {
let y = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
let a = if BE {
u16::from_be(packed[x * 2 + 1])
} else {
u16::from_le(packed[x * 2 + 1])
};
let i = x * 4;
rgba_u16_out[i] = y;
rgba_u16_out[i + 1] = y;
rgba_u16_out[i + 2] = y;
rgba_u16_out[i + 3] = a;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_luma_row<const BE: bool>(packed: &[u16], luma_out: &mut [u8], width: usize) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(luma_out.len() >= width, "luma_out too short");
for x in 0..width {
let y = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
luma_out[x] = (y >> 8) as u8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_luma_u16_row<const BE: bool>(
packed: &[u16],
luma_u16_out: &mut [u16],
width: usize,
) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(luma_u16_out.len() >= width, "luma_u16_out too short");
for x in 0..width {
luma_u16_out[x] = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn ya16_to_hsv_row<const BE: bool>(
packed: &[u16],
h_out: &mut [u8],
s_out: &mut [u8],
v_out: &mut [u8],
width: usize,
) {
debug_assert!(packed.len() >= width * 2, "packed too short");
debug_assert!(h_out.len() >= width, "h_out too short");
debug_assert!(s_out.len() >= width, "s_out too short");
debug_assert!(v_out.len() >= width, "v_out too short");
for x in 0..width {
let y = if BE {
u16::from_be(packed[x * 2])
} else {
u16::from_le(packed[x * 2])
};
h_out[x] = 0;
s_out[x] = 0;
v_out[x] = (y >> 8) as u8;
}
}
#[cfg(all(test, feature = "std"))]
mod tests;