Skip to main content

ImageData

Struct ImageData 

Source
pub struct ImageData {
    pub id: u64,
    pub width: u32,
    pub height: u32,
    /* private fields */
}

Fields§

§id: u64

Content address: equal pixels at equal dimensions give equal ids, whoever built them and whenever.

The renderers key their texture caches on this and nothing else, so the id has to identify the image. A per-construction counter identified the allocation instead: a caller that rebuilt the same image each frame — which is what building an ImageData inside a widget body does — minted a fresh key every time, and every entry behind it became unreachable weight the cache could only shed by hitting its byte budget.

An external texture cannot be hashed, so its owner supplies the id and carries the same duty: keep it stable while the texture is, and change it when the texture object is replaced.

§width: u32§height: u32

Implementations§

Source§

impl ImageData

Source

pub fn new(pixels: Vec<u8>, width: u32, height: u32) -> Self

Source

pub fn from_premultiplied(pixels: Vec<u8>, width: u32, height: u32) -> Self

Builds from bytes that are ALREADY premultiplied (e.g. a resvg Pixmap), skipping the premultiply step new() performs.

Source

pub fn external( texture: Arc<dyn ExternalTexture>, id: u64, width: u32, height: u32, ) -> Self

Refers to a texture the application owns and keeps filling, rather than pixels Telar uploads.

id addresses the texture object, not its contents: the whole point is that the contents change every frame without Telar being told. Bump it only when the texture itself is replaced — a resize, a format change — so the bind group built against the old one is dropped.

Source

pub fn pixels(&self) -> &[u8]

The premultiplied RGBA8 bytes; empty when the picture lives in a texture Telar does not own.

Empty rather than Option so a backend that cannot use an external texture needs no special case: every path that turns these bytes into a raster already has to reject a buffer too short for the dimensions, and an empty one takes that branch.

Source

pub fn external_texture(&self) -> Option<&Arc<dyn ExternalTexture>>

Trait Implementations§

Source§

impl Clone for ImageData

Source§

fn clone(&self) -> ImageData

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 ImageData

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<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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more