unityrs_texture/decode/
length.rs1use super::{Format, Library, astc, crunch};
4
5#[must_use]
13pub fn bcn_length(len: usize) -> u64 {
14 let low = u64::try_from(len).unwrap_or(u64::MAX) & 0xFFFF_FFFF;
15 if low >= 1 << 31 { 0 } else { low }
18}
19
20pub(super) fn scratch_charge(format: Format, unpacked_bytes: u64, width: u64) -> u64 {
22 if format.is_unity_crunched() {
23 crunch::unity::scratch(unpacked_bytes, width)
24 } else if format.is_crunched() {
25 crunch::scratch(unpacked_bytes)
26 } else {
27 astc_footprint(format).map_or(0, astc::Tables::charge)
28 }
29}
30
31pub(super) fn raw_pixel_bytes(format: Format) -> u64 {
33 crate::tierb::layout(format).map_or_else(
34 || u64::from(format.raw_bits().unwrap_or(0) / 8),
35 crate::tierb::Layout::bytes,
36 )
37}
38
39pub(super) fn astc_footprint(format: Format) -> Option<astc::Footprint> {
41 if format.library() != Library::Astcenc {
42 return None;
43 }
44 let (w, h) = format.block_size()?;
45 astc::Footprint::new(w, h)
46}