Skip to main content

Levels

Struct Levels 

Source
pub struct Levels {
    pub width: u32,
    pub height: u32,
    pub levels: Vec<Vec<u8>>,
}
Expand description

An RGBA8 texture’s mip levels, each stored row by row, four bytes a texel. Level n is the base size halved n times (at least 1); Levels::size gives it.

Fields§

§width: u32

The base level’s width in texels.

§height: u32

The base level’s height in texels.

§levels: Vec<Vec<u8>>

The RGBA8 bytes of each level, base level first. The fields are public, so the sampling methods check the level they read: one that is missing, or does not hold exactly its Levels::size in texels, is refused.

Implementations§

Source§

impl Levels

Source

pub fn one(width: u32, height: u32, rgba: Vec<u8>) -> Result<Levels>

One level of RGBA8 texels.

Source

pub fn rows_reversed(self) -> Result<Levels>

Each level’s rows in reverse order, for a texture stored bottom row first when row 0 is wanted at v = 0: addressing then applies about that texture’s own origin. A level that isn’t its size’s whole rows is refused.

Source

pub fn size(&self, level: usize) -> (u32, u32)

Level level’s size: the base halved per level, at least 1.

Source

pub fn texel( &self, level: usize, x: i64, y: i64, address: [Address; 2], ) -> Result<[u8; 4]>

The texel at (x, y) of level level, addressed by address. A level that is not stored, or does not hold its size’s bytes, is refused, as is a coordinate outside a Address::Border axis (it reads no stored texel).

Source

pub fn bilinear( &self, level: usize, uv: [f64; 2], address: impl Into<Addressing<2>>, transfer: Transfer, ) -> Result<[f64; 4]>

Bilinear at uv of level level, in f64: weights (1 - tx)(1 - ty), tx (1 - ty), (1 - tx) ty, tx ty summed in that order, a texel outside a border axis the border colour. A coordinate that isn’t finite or past an i32’s range is refused, as is a border axis with no colour (Addressing::border).

Source

pub fn point( &self, level: usize, uv: [f64; 2], address: impl Into<Addressing<2>>, transfer: Transfer, ) -> Result<[f64; 4]>

The texel of level level that uv falls in (texel i covering [i, i + 1) after scaling by the level’s size), in f64: point filtering; outside a border axis, the border colour. A coordinate that isn’t finite or past an i32’s range is refused, as is a border axis with no colour.

Source

pub fn decoded(&self, level: usize, transfer: Transfer) -> Result<Decoded>

Level level decoded once to f32 by transfer, for Decoded::bilinear. A level that is not stored, or does not hold its size’s bytes, is refused.

Source§

impl Levels

Source

pub fn trilinear( &self, uv: [f64; 2], lod: f64, address: impl Into<Addressing<2>>, transfer: Transfer, ) -> Result<[f64; 4]>

Trilinear at uv: the level of detail lod clamped to the stored levels, the bilinear values (Levels::bilinear) of the level below it and the next mixed by its fraction (a + (b - a) f); a level of detail that isn’t a number, or a coordinate or addressing Levels::bilinear refuses, is refused.

Source

pub fn nearest_level(&self, lod: f64) -> Result<usize>

The stored level nearest the level of detail lod, as a point mip filter picks it: floor(lod + 0.5) (a half rounds up), clamped to the stored levels. A level of detail that isn’t a number is refused.

Trait Implementations§

Source§

impl Clone for Levels

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Levels

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.