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 u16 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 that dimensions fit within i32 (required
by the underlying C API) and that data is large enough for the given
stride and height.
§Panics
Panics if width, height, or stride exceed i32::MAX, or if
data.len() is less than stride * height.