use super::{Format, Library, astc, crunch};
#[must_use]
pub fn bcn_length(len: usize) -> u64 {
let low = u64::try_from(len).unwrap_or(u64::MAX) & 0xFFFF_FFFF;
if low >= 1 << 31 { 0 } else { low }
}
pub(super) fn scratch_charge(format: Format, unpacked_bytes: u64, width: u64) -> u64 {
if format.is_unity_crunched() {
crunch::unity::scratch(unpacked_bytes, width)
} else if format.is_crunched() {
crunch::scratch(unpacked_bytes)
} else {
astc_footprint(format).map_or(0, astc::Tables::charge)
}
}
pub(super) fn raw_pixel_bytes(format: Format) -> u64 {
crate::tierb::layout(format).map_or_else(
|| u64::from(format.raw_bits().unwrap_or(0) / 8),
crate::tierb::Layout::bytes,
)
}
pub(super) fn astc_footprint(format: Format) -> Option<astc::Footprint> {
if format.library() != Library::Astcenc {
return None;
}
let (w, h) = format.block_size()?;
astc::Footprint::new(w, h)
}