Skip to main content

DynImage

Enum DynImage 

Source
pub enum DynImage<Fmt: ColorFmt> {
    Direct(DirectImage<Fmt>),
    Paletted(PalettedImage<Fmt>),
}
Expand description

Either a DirectImage, or a PalettedImage.

Like both of these types, most of DynImage’s API is provided by the Image trait.

Variants§

§

Direct(DirectImage<Fmt>)

The image is not paletted.

§

Paletted(PalettedImage<Fmt>)

The image is paletted.

Implementations§

Source§

impl<Fmt: ColorFmt> DynImage<Fmt>

Source

pub fn load<Src: ImageSource>( input: Src, flags: LoadFlags, alpha_mode: AlphaMode, prefer_palette: bool, ) -> Result<Self>

Loads an image from an image source.

If prefer_palette is true, this will attempt to generate a palette from a direct-color image; however, failure to do so (typically because the image contains more than 256 colours) is not considered an error, and instead returns a DirectImage.

If you don’t want to deal with the overhead of checking which image type is contained each time, consider either DirectImage::load() or PalettedImage::load().

Source

pub fn load_limited<Src: ImageSource>( input: Src, flags: LoadFlags, alpha_mode: AlphaMode, prefer_palette: bool, nb_pixels_max: usize, ) -> Result<Self>

Loads an image from an image source, limiting the amount of memory that can be allocated.

If prefer_palette is true, this will attempt to generate a palette from a direct-color image; however, failure to do so (typically because the image contains more than 256 colours) is not considered an error, and instead returns a DirectImage.

§Memory limit

Note that the nb_pixels_max argument only limits how much memory is allocated for the pixel data itself, not for the entire image or for temporary buffers.

The image struct, as well as the metadata nodes and other bookkeeping, can push the total allocation a little higher than that, though not much.

Source

pub fn as_dyn_image(&self) -> &dyn Image<Fmt>

Returns a trait object for accessing the Image API of the underlying image.

Using this instead of simply casting self as &dyn Image<Fmt> is a little faster, because it inspects the enumeration only once instead of at every method call.

Source

pub fn as_mut_dyn_image(&mut self) -> &mut dyn Image<Fmt>

Returns a trait object for accessing the Image API of the underlying image.

Using this instead of simply casting self as &mut dyn Image<Fmt> is a little faster, because it inspects the enumeration only once instead of at every method call.

Trait Implementations§

Source§

impl<Fmt: Clone + ColorFmt> Clone for DynImage<Fmt>

Source§

fn clone(&self) -> DynImage<Fmt>

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<Fmt: Debug + ColorFmt> Debug for DynImage<Fmt>

Source§

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

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

impl<Fmt: ColorFmt> From<DirectImage<Fmt>> for DynImage<Fmt>

Source§

fn from(value: DirectImage<Fmt>) -> Self

Converts to this type from the input type.
Source§

impl<Fmt: ColorFmt> From<PalettedImage<Fmt>> for DynImage<Fmt>

Source§

fn from(value: PalettedImage<Fmt>) -> Self

Converts to this type from the input type.
Source§

impl<Fmt: ColorFmt> Image<Fmt> for DynImage<Fmt>

Source§

fn nb_frames(&self) -> usize

Returns how many frames the image contains. Read more
Source§

fn width(&self) -> usize

Returns how many pixels wide the image is. Read more
Source§

fn height(&self) -> usize

Returns how many pixels tall the image is. Read more
Source§

fn format(&self) -> ImageFormat

The image’s format (PNG, JPEG…). Read more
Source§

fn set_format(&mut self, format: ImageFormat)

Sets a different format to store the image as.
Source§

fn alpha_mode(&self) -> AlphaMode

The image’s alpha mode. Read more
Source§

fn set_alpha_mode(&mut self, mode: AlphaMode)

Sets a different alpha mode to store the image as. Read more
Source§

fn palette(&self) -> Option<&[Fmt]>

Retrieves the image’s embedded colour palette, if there is one.
Source§

fn pixel(&self, frame_idx: usize, x: usize, y: usize) -> Fmt

Retrieves the pixel at the given position in the image. Read more
Source§

fn pixel_mut(&mut self, frame_idx: usize, x: usize, y: usize) -> &mut Fmt

Retrieves the pixel at the given position in the image. Read more
Source§

fn store<Dest: ImageDest>(&self, output: Dest) -> Result<NonZeroUsize>

Stores the image to an image destination.
Source§

fn metadata(&self) -> Metadata<'_>

Iterates through the image’s metadata nodes.
Source§

fn metadata_mut(&mut self) -> MetadataMut<'_>

Iterates through the image’s metadata nodes, allowing in-place modification of them.
Source§

fn nb_pixels(&self) -> usize

How many pixels are in each frame.
Source§

fn frame(&self, frame_idx: usize) -> Frame<'_, Fmt, Self>
where Self: Sized,

Provides more convenient access to a specific frame of the image’s. Read more
Source§

fn frame_mut(&mut self, frame_idx: usize) -> FrameMut<'_, Fmt, Self>
where Self: Sized,

Provides more convenient access to a specific frame of the image’s. Read more
Source§

fn frames(&self) -> Frames<'_, Fmt, Self>
where Self: Sized,

Iterates through the image’s frames.
Source§

fn foreach_frame_mut<F: FnMut(FrameMut<'_, Fmt, Self>)>(&mut self, f: F)
where Self: Sized,

Iterates through the image’s frames, with a callback that is allowed to mutate the image. Read more
Source§

fn try_foreach_frame_mut<E, F: FnMut(FrameMut<'_, Fmt, Self>) -> Result<(), E>>( &mut self, f: F, ) -> Result<(), E>
where Self: Sized,

Iterates through the image’s frames, with a faillible callback that is allowed to mutate the image. Read more

Auto Trait Implementations§

§

impl<Fmt> Freeze for DynImage<Fmt>

§

impl<Fmt> RefUnwindSafe for DynImage<Fmt>
where Fmt: RefUnwindSafe,

§

impl<Fmt> Send for DynImage<Fmt>
where Fmt: Send,

§

impl<Fmt> Sync for DynImage<Fmt>
where Fmt: Sync,

§

impl<Fmt> Unpin for DynImage<Fmt>
where Fmt: Unpin,

§

impl<Fmt> UnsafeUnpin for DynImage<Fmt>

§

impl<Fmt> UnwindSafe for DynImage<Fmt>
where Fmt: 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> 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> 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.