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>
impl<Fmt: ColorFmt> DynImage<Fmt>
Sourcepub fn load<Src: ImageSource>(
input: Src,
flags: LoadFlags,
alpha_mode: AlphaMode,
prefer_palette: bool,
) -> Result<Self>
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().
Sourcepub fn load_limited<Src: ImageSource>(
input: Src,
flags: LoadFlags,
alpha_mode: AlphaMode,
prefer_palette: bool,
nb_pixels_max: usize,
) -> Result<Self>
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.
Sourcepub fn as_dyn_image(&self) -> &dyn Image<Fmt>
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.
Sourcepub fn as_mut_dyn_image(&mut self) -> &mut dyn Image<Fmt>
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.