pub struct ImageSource { /* private fields */ }Expand description
A decode-once, cheaply-clonable handle around a decoded RGBA8 image.
Identity is the inner Arc pointer: ImageSource::same compares by
pointer, not pixel content, in O(1) regardless of image size — the signal
ImageView’s rebuild relies on to know “same image, nothing to redo”
without ever touching the decoder again.
Implementations§
Source§impl ImageSource
impl ImageSource
Sourcepub fn decode(bytes: &[u8]) -> Result<ImageSource, ImageError>
pub fn decode(bytes: &[u8]) -> Result<ImageSource, ImageError>
Decode PNG/JPEG bytes into straight-alpha RGBA8 once, wrapping the
result in a shareable handle. Callers own the resulting ImageSource
(typically stashing it in app state) and re-pass it into Image
every frame — this never re-decodes.
Sourcepub fn from_rgba8(pixels: Vec<u8>, width: u32, height: u32) -> ImageSource
pub fn from_rgba8(pixels: Vec<u8>, width: u32, height: u32) -> ImageSource
Wrap already-decoded straight-alpha RGBA8 pixel data directly (e.g. a
procedurally generated image, or a test fixture) without going through
the image crate’s decoder.
pixels.len() must equal width * height * 4; a mismatched length is
a caller bug and is not checked here (mirrors peniko::ImageData’s own
contract — the renderer will simply read width * height * 4 bytes).
Sourcepub fn same(&self, other: &ImageSource) -> bool
pub fn same(&self, other: &ImageSource) -> bool
Whether self and other share the same decoded data (Arc pointer
identity, not content equality) — never true for two independently
decoded sources even if their bytes matched, since each decode
allocates a fresh Arc.
Sourcepub fn natural_size(&self) -> Size
pub fn natural_size(&self) -> Size
The natural (decoded pixel) size.
Sourcepub fn image_data(&self) -> &ImageData
pub fn image_data(&self) -> &ImageData
Borrow the decoded peniko::ImageData this source wraps, for painting.
This returns a borrow of already-decoded pixels and triggers no decode.
The source caches pixel data once at construction via Self::decode;
this accessor hands back a reference to that cache. Calling this
repeatedly with the same ImageSource is zero-cost and does not
re-trigger the image decoder.
Trait Implementations§
Source§impl Clone for ImageSource
impl Clone for ImageSource
Source§fn clone(&self) -> ImageSource
fn clone(&self) -> ImageSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ImageSource
impl !UnwindSafe for ImageSource
impl Freeze for ImageSource
impl Send for ImageSource
impl Sync for ImageSource
impl Unpin for ImageSource
impl UnsafeUnpin for ImageSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.