#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgba_to_rgb_row(rgba: &[u8], rgb_out: &mut [u8], width: usize) {
debug_assert!(rgba.len() >= width * 4, "rgba 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] = rgba[src];
rgb_out[dst + 1] = rgba[src + 1];
rgb_out[dst + 2] = rgba[src + 2];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn bgra_to_rgba_row(bgra: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(bgra.len() >= width * 4, "bgra 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] = bgra[i + 2];
rgba_out[i + 1] = bgra[i + 1];
rgba_out[i + 2] = bgra[i];
rgba_out[i + 3] = bgra[i + 3];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn bgra_to_rgb_row(bgra: &[u8], rgb_out: &mut [u8], width: usize) {
debug_assert!(bgra.len() >= width * 4, "bgra 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] = bgra[src + 2];
rgb_out[dst + 1] = bgra[src + 1];
rgb_out[dst + 2] = bgra[src];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn argb_to_rgb_row(argb: &[u8], rgb_out: &mut [u8], width: usize) {
debug_assert!(argb.len() >= width * 4, "argb 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] = argb[src + 1];
rgb_out[dst + 1] = argb[src + 2];
rgb_out[dst + 2] = argb[src + 3];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn abgr_to_rgb_row(abgr: &[u8], rgb_out: &mut [u8], width: usize) {
debug_assert!(abgr.len() >= width * 4, "abgr 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] = abgr[src + 3];
rgb_out[dst + 1] = abgr[src + 2];
rgb_out[dst + 2] = abgr[src + 1];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn argb_to_rgba_row(argb: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(argb.len() >= width * 4, "argb 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] = argb[i + 1];
rgba_out[i + 1] = argb[i + 2];
rgba_out[i + 2] = argb[i + 3];
rgba_out[i + 3] = argb[i];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn abgr_to_rgba_row(abgr: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(abgr.len() >= width * 4, "abgr 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] = abgr[i + 3];
rgba_out[i + 1] = abgr[i + 2];
rgba_out[i + 2] = abgr[i + 1];
rgba_out[i + 3] = abgr[i];
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn xrgb_to_rgba_row(xrgb: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(xrgb.len() >= width * 4, "xrgb 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] = xrgb[i + 1];
rgba_out[i + 1] = xrgb[i + 2];
rgba_out[i + 2] = xrgb[i + 3];
rgba_out[i + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn rgbx_to_rgba_row(rgbx: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(rgbx.len() >= width * 4, "rgbx 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] = rgbx[i];
rgba_out[i + 1] = rgbx[i + 1];
rgba_out[i + 2] = rgbx[i + 2];
rgba_out[i + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn xbgr_to_rgba_row(xbgr: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(xbgr.len() >= width * 4, "xbgr 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] = xbgr[i + 3];
rgba_out[i + 1] = xbgr[i + 2];
rgba_out[i + 2] = xbgr[i + 1];
rgba_out[i + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn bgrx_to_rgba_row(bgrx: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(bgrx.len() >= width * 4, "bgrx 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] = bgrx[i + 2];
rgba_out[i + 1] = bgrx[i + 1];
rgba_out[i + 2] = bgrx[i];
rgba_out[i + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn x2rgb10_to_rgb_row<const BE: bool>(x2rgb10: &[u8], rgb_out: &mut [u8], width: usize) {
debug_assert!(x2rgb10.len() >= width * 4, "x2rgb10 row too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out row too short");
for x in 0..width {
let i = x * 4;
let bytes = [x2rgb10[i], x2rgb10[i + 1], x2rgb10[i + 2], x2rgb10[i + 3]];
let pix = if BE {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
let r10 = (pix >> 20) & 0x3FF;
let g10 = (pix >> 10) & 0x3FF;
let b10 = pix & 0x3FF;
let dst = x * 3;
rgb_out[dst] = (r10 >> 2) as u8;
rgb_out[dst + 1] = (g10 >> 2) as u8;
rgb_out[dst + 2] = (b10 >> 2) as u8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn x2rgb10_to_rgba_row<const BE: bool>(
x2rgb10: &[u8],
rgba_out: &mut [u8],
width: usize,
) {
debug_assert!(x2rgb10.len() >= width * 4, "x2rgb10 row too short");
debug_assert!(rgba_out.len() >= width * 4, "rgba_out row too short");
for x in 0..width {
let i = x * 4;
let bytes = [x2rgb10[i], x2rgb10[i + 1], x2rgb10[i + 2], x2rgb10[i + 3]];
let pix = if BE {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
let r10 = (pix >> 20) & 0x3FF;
let g10 = (pix >> 10) & 0x3FF;
let b10 = pix & 0x3FF;
rgba_out[i] = (r10 >> 2) as u8;
rgba_out[i + 1] = (g10 >> 2) as u8;
rgba_out[i + 2] = (b10 >> 2) as u8;
rgba_out[i + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn x2rgb10_to_rgb_u16_row<const BE: bool>(
x2rgb10: &[u8],
rgb_out: &mut [u16],
width: usize,
) {
debug_assert!(x2rgb10.len() >= width * 4, "x2rgb10 row too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out row too short");
for x in 0..width {
let i = x * 4;
let bytes = [x2rgb10[i], x2rgb10[i + 1], x2rgb10[i + 2], x2rgb10[i + 3]];
let pix = if BE {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
let dst = x * 3;
rgb_out[dst] = ((pix >> 20) & 0x3FF) as u16;
rgb_out[dst + 1] = ((pix >> 10) & 0x3FF) as u16;
rgb_out[dst + 2] = (pix & 0x3FF) as u16;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn x2bgr10_to_rgb_row<const BE: bool>(x2bgr10: &[u8], rgb_out: &mut [u8], width: usize) {
debug_assert!(x2bgr10.len() >= width * 4, "x2bgr10 row too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out row too short");
for x in 0..width {
let i = x * 4;
let bytes = [x2bgr10[i], x2bgr10[i + 1], x2bgr10[i + 2], x2bgr10[i + 3]];
let pix = if BE {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
let r10 = pix & 0x3FF;
let g10 = (pix >> 10) & 0x3FF;
let b10 = (pix >> 20) & 0x3FF;
let dst = x * 3;
rgb_out[dst] = (r10 >> 2) as u8;
rgb_out[dst + 1] = (g10 >> 2) as u8;
rgb_out[dst + 2] = (b10 >> 2) as u8;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn x2bgr10_to_rgba_row<const BE: bool>(
x2bgr10: &[u8],
rgba_out: &mut [u8],
width: usize,
) {
debug_assert!(x2bgr10.len() >= width * 4, "x2bgr10 row too short");
debug_assert!(rgba_out.len() >= width * 4, "rgba_out row too short");
for x in 0..width {
let i = x * 4;
let bytes = [x2bgr10[i], x2bgr10[i + 1], x2bgr10[i + 2], x2bgr10[i + 3]];
let pix = if BE {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
let r10 = pix & 0x3FF;
let g10 = (pix >> 10) & 0x3FF;
let b10 = (pix >> 20) & 0x3FF;
rgba_out[i] = (r10 >> 2) as u8;
rgba_out[i + 1] = (g10 >> 2) as u8;
rgba_out[i + 2] = (b10 >> 2) as u8;
rgba_out[i + 3] = 0xFF;
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn x2bgr10_to_rgb_u16_row<const BE: bool>(
x2bgr10: &[u8],
rgb_out: &mut [u16],
width: usize,
) {
debug_assert!(x2bgr10.len() >= width * 4, "x2bgr10 row too short");
debug_assert!(rgb_out.len() >= width * 3, "rgb_out row too short");
for x in 0..width {
let i = x * 4;
let bytes = [x2bgr10[i], x2bgr10[i + 1], x2bgr10[i + 2], x2bgr10[i + 3]];
let pix = if BE {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
let dst = x * 3;
rgb_out[dst] = (pix & 0x3FF) as u16;
rgb_out[dst + 1] = ((pix >> 10) & 0x3FF) as u16;
rgb_out[dst + 2] = ((pix >> 20) & 0x3FF) as u16;
}
}