Struct Surface

Source
pub struct Surface<T> {
    pub width: u32,
    pub height: u32,
    pub depth: u32,
    pub layers: u32,
    pub mipmaps: u32,
    pub image_format: ImageFormat,
    pub data: T,
}
Expand description

A surface with an image format known at runtime.

Fields§

§width: u32

The width of the surface in pixels.

§height: u32

The height of the surface in pixels.

§depth: u32

The depth of the surface in pixels. This should be 1 for 2D surfaces.

§layers: u32

The number of array layers in the surface. This should be 1 for most surfaces and 6 for cube maps.

§mipmaps: u32

The number of mipmaps in the surface. This should be 1 if the surface has only the base mip level. All array layers are assumed to have the same number of mipmaps.

§image_format: ImageFormat

The format of the bytes in data.

§data: T

The combined image data ordered by layer and then mipmap without additional padding.

A surface with L layers and M mipmaps would have the following layout: Layer 0 Mip 0, Layer 0 Mip 1, …, Layer L-1 Mip M-1

Implementations§

Source§

impl<T: AsRef<[u8]>> Surface<T>

Source

pub fn get(&self, layer: u32, depth_level: u32, mipmap: u32) -> Option<&[u8]>

Get the range of image data corresponding to the specified layer, depth_level, and mipmap.

The dimensions of the returned data should be calculated using mip_dimension. Returns None if the expected range is not fully contained within the buffer.

Source§

impl<T: AsRef<[u8]>> Surface<T>

Source

pub fn decode_rgba8(&self) -> Result<SurfaceRgba8<Vec<u8>>, SurfaceError>

Decode all layers and mipmaps from surface to RGBA8.

Source

pub fn decode_layers_mipmaps_rgba8( &self, layers: Range<u32>, mipmaps: Range<u32>, ) -> Result<SurfaceRgba8<Vec<u8>>, SurfaceError>

Decode a specific range of layers and mipmaps from surface to RGBA8.

Source

pub fn decode_rgbaf32( &self, ) -> Result<SurfaceRgba32Float<Vec<f32>>, SurfaceError>

Decode all layers and mipmaps from surface to RGBAF32.

Non floating point formats are normalized to the range 0.0 to 1.0.

Source

pub fn decode_layers_mipmaps_rgbaf32( &self, layers: Range<u32>, mipmaps: Range<u32>, ) -> Result<SurfaceRgba32Float<Vec<f32>>, SurfaceError>

Decode a specific range of layers and mipmaps from surface to RGBAF32.

Non floating point formats are normalized to the range 0.0 to 1.0.

Source§

impl<T: AsRef<[u8]>> Surface<T>

Source

pub fn encode( &self, format: ImageFormat, quality: Quality, mipmaps: Mipmaps, ) -> Result<Surface<Vec<u8>>, SurfaceError>

Encode a surface to the given format.

The number of mipmaps generated depends on the mipmaps parameter.

Source§

impl<T: AsRef<[u8]>> Surface<T>

Source

pub fn to_dds(&self) -> Result<Dds, CreateDdsError>

Create a DDS file with the same image data and format.

Source§

impl<'a> Surface<&'a [u8]>

Source

pub fn from_dds(dds: &'a Dds) -> Result<Self, SurfaceError>

Create a view over the data in dds without any copies.

Trait Implementations§

Source§

impl<T: Debug> Debug for Surface<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for Surface<T>

Source§

fn eq(&self, other: &Surface<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for Surface<T>

Auto Trait Implementations§

§

impl<T> Freeze for Surface<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Surface<T>
where T: RefUnwindSafe,

§

impl<T> Send for Surface<T>
where T: Send,

§

impl<T> Sync for Surface<T>
where T: Sync,

§

impl<T> Unpin for Surface<T>
where T: Unpin,

§

impl<T> UnwindSafe for Surface<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.