#[cfg(feature = "prebuilt")]
extern crate ctt_intel_texture_compressor_prebuilt;
pub mod bindings;
pub mod bc1;
pub mod bc3;
pub mod bc4;
pub mod bc5;
pub mod bc6h;
pub mod bc7;
pub mod etc1;
#[derive(Debug, Copy, Clone)]
pub struct Surface<'a, const COMPONENTS: usize> {
pub data: &'a [u8],
pub width: u32,
pub height: u32,
pub stride: u32,
}
impl<'a, const COMPONENTS: usize> Surface<'a, COMPONENTS> {
pub fn new(data: &'a [u8], width: u32, height: u32, stride: u32) -> Self {
assert!(width > 0 && height > 0, "width and height must be non-zero");
assert!(
width.is_multiple_of(4),
"width {width} must be a multiple of 4 (ISPC kernels only process whole 4×4 blocks)",
);
assert!(
height.is_multiple_of(4),
"height {height} must be a multiple of 4 (ISPC kernels only process whole 4×4 blocks)",
);
assert!(
i32::try_from(width).is_ok(),
"width {width} exceeds i32::MAX"
);
assert!(
i32::try_from(height).is_ok(),
"height {height} exceeds i32::MAX"
);
assert!(
i32::try_from(stride).is_ok(),
"stride {stride} exceeds i32::MAX"
);
let width_components = (width as usize)
.checked_mul(COMPONENTS)
.expect("width * COMPONENTS overflows usize");
assert!(
stride as usize >= width_components,
"stride {stride} is less than width * COMPONENTS ({} * {COMPONENTS} = {width_components})",
width,
);
let required = (stride as usize)
.checked_mul(height as usize)
.expect("stride * height overflows usize");
assert!(
data.len() >= required,
"data length {} is less than stride * height ({required})",
data.len()
);
Self {
data,
width,
height,
stride,
}
}
}
pub type RgbaSurface<'a> = Surface<'a, 4>;
pub type RgSurface<'a> = Surface<'a, 2>;
pub type RSurface<'a> = Surface<'a, 1>;
pub type RgbaF16Surface<'a> = Surface<'a, 8>;