ImageFormat

Enum ImageFormat 

Source
pub enum ImageFormat {
    Unknown,
    Png,
    Jpeg,
    Gif,
    Bmp,
    Tiff,
    WebP,
}
Expand description

Represents the underlying encoding format of an image.

Variants§

§

Unknown

No known encoding is known for the image.

This is usually because the image was created manually. See Image::set_format to manually set the encoding format.

§

Png

The image is encoded in the PNG format.

§

Jpeg

The image is encoded in the JPEG format.

§

Gif

The image is encoded in the GIF format.

§

Bmp

The image is encoded in the BMP format.

§

Tiff

The image is encoded in the TIFF format.

§

WebP

The image is encoded in the WebP format.

Implementations§

Source§

impl ImageFormat

Source

pub fn is_unknown(&self) -> bool

Returns whether the extension is unknown.

Source

pub fn from_extension(ext: impl AsRef<OsStr>) -> Result<ImageFormat, Error>

Parses the given extension and returns the corresponding image format.

If the extension is an unknown extension, Ok(ImageFormat::Unknown) is returned.

If the extension is completely invalid and fails to be converted into a &str, the InvalidExtension error is returned.

§Errors
  • The extension is completely invalid and failed to be converted into a &str.
Source

pub fn from_path(path: impl AsRef<Path>) -> Result<ImageFormat, Error>

Returns the format specified by the given path.

This uses ImageFormat::from_extension to parse the extension.

This resolves via the extension of the path. See ImageFormat::infer_encoding for an implementation that can resolve the format from the data.

§Errors
  • No extension can be resolved from the path.
Source

pub fn from_mime_type(mime: impl AsRef<str>) -> ImageFormat

Returns the format specified by the given MIME type.

Source

pub fn infer_encoding(sample: &[u8]) -> ImageFormat

Infers the encoding format from the given data via a byte stream.

Source

pub fn run_encoder<P>( &self, image: &Image<P>, dest: impl Write, ) -> Result<(), Error>
where P: Pixel,

Encodes the Image into raw bytes.

§Errors
  • An error occured while encoding.
§Panics
  • No encoder implementation is found for this image encoding.
Source

pub fn run_sequence_encoder<P>( &self, seq: &ImageSequence<P>, dest: impl Write, ) -> Result<(), Error>
where P: Pixel,

Encodes the ImageSequence into raw bytes. If the encoding does not supported image sequences (or multi-frame images), it will only encode the first frame.

§Errors
  • An error occured while encoding.
§Panics
  • No encoder implementation is found for this image encoding.
Source

pub fn run_decoder<P>(&self, stream: impl Read) -> Result<Image<P>, Error>
where P: Pixel,

Decodes the image data from into an image.

§Errors
  • An error occured while decoding.
§Panics
  • No decoder implementation is found for this image encoding.
Source

pub fn run_sequence_decoder<'a, P, R>( &self, stream: R, ) -> Result<Box<dyn FrameIterator<P, Item = Result<Frame<P>, Error>> + 'a>, Error>
where P: Pixel + 'a, R: Read + 'a,

Decodes the image sequence data into an image sequence.

§Errors
  • An error occured while decoding.
§Panics
  • No decoder implementation is found for this image encoding.

Trait Implementations§

Source§

impl Clone for ImageFormat

Source§

fn clone(&self) -> ImageFormat

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageFormat

Source§

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

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

impl Default for ImageFormat

Source§

fn default() -> ImageFormat

Returns the “default value” for a type. Read more
Source§

impl Display for ImageFormat

Source§

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

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

impl Hash for ImageFormat

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ImageFormat

Source§

fn eq(&self, other: &ImageFormat) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ImageFormat

Source§

impl Eq for ImageFormat

Source§

impl StructuralPartialEq for ImageFormat

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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.