pub struct Surface<'a, const COMPONENTS: usize> {
pub data: &'a [u8],
pub width: u32,
pub height: u32,
pub stride: u32,
}Expand description
Describes a 2D image to block-compress.
COMPONENTS is the number of bytes per pixel in the source data. This
determines the expected tightly-packed stride (width * COMPONENTS) and is
used to validate that data is large enough. The actual channel layout
depends on which encoder consumes the surface — see the individual format
modules for details.
§Available surface type aliases
Fields§
§data: &'a [u8]The raw pixel data for the image.
The byte interpretation depends on the encoder that consumes this
surface. For most formats, each byte is one u8 channel sample. For
bc6h, every two bytes form a little-endian f16 channel sample.
The data does not need to be tightly packed, but if it isn’t, stride
must differ from width * COMPONENTS.
Expected to be at least stride * height bytes.
width: u32The width of the image in texels.
height: u32The height of the image in texels.
stride: u32The stride between rows of the image, in bytes.
For tightly-packed data this is width * COMPONENTS.
Implementations§
Source§impl<'a, const COMPONENTS: usize> Surface<'a, COMPONENTS>
impl<'a, const COMPONENTS: usize> Surface<'a, COMPONENTS>
Sourcepub fn new(data: &'a [u8], width: u32, height: u32, stride: u32) -> Self
pub fn new(data: &'a [u8], width: u32, height: u32, stride: u32) -> Self
Creates a new surface, validating the preconditions required by the underlying ISPC kernels.
§Panics
Panics if:
widthorheightis zero,widthorheightis not a multiple of 4 (the ISPC kernels process whole 4×4 blocks and will silently drop partial edge blocks otherwise),width,height, orstrideexceedi32::MAX,strideis less thanwidth * COMPONENTS,data.len()is less thanstride * height.