Trait ImageDecoder
pub trait ImageDecoder
The trait that all decoders implement
Required Methods
fn dimensions(&self) -> (u32, u32)Returns a tuple containing the width and height of the image
fn color_type(&self) -> ColorTypeReturns the color type of the image data produced by this decoder
fn read_image(self, buf: &mut [u8]) -> ImageResult<()> where Self: Sized,Returns all the bytes in the image.
This function takes a slice of bytes and writes the pixel data of the image into it.
bufdoes not need to be aligned to any byte boundaries. However, alignment to 2 or 4 byte boundaries may result in small performance improvements for certain decoder implementations.The returned pixel data will always be in native endian. This allows
[u16]and[f32]slices to be cast to[u8]and used for this method.Panics
This function panics if
buf.len() != self.total_bytes().Examples
# use ImageDecoder;fn read_image_boxed(self: Box<Self>, buf: &mut [u8]) -> ImageResult<()>Use
read_imageinstead; this method is an implementation detail needed so the trait can be object safe.Note to implementors: This method should be implemented by calling
read_imageon the boxed decoder...fn read_image_boxed(self: Box<Self>, buf: &mut [u8]) -> ImageResult<()> { (*self).read_image(buf) }
Provided Methods
fn original_color_type(&self) -> ExtendedColorTypeReturns the color type of the image file before decoding
fn icc_profile(&mut self) -> ImageResult<Option<Vec<u8>>>Returns the ICC color profile embedded in the image, or
Ok(None)if the image does not have one.For formats that don't support embedded profiles this function should always return
Ok(None).fn exif_metadata(&mut self) -> ImageResult<Option<Vec<u8>>>Returns the raw Exif chunk, if it is present. A third-party crate such as
kamadak-exifis required to actually parse it.For formats that don't support embedded profiles this function should always return
Ok(None).fn xmp_metadata(&mut self) -> ImageResult<Option<Vec<u8>>>Returns the raw XMP chunk, if it is present. A third-party crate such as
roxmltreeis required to actually parse it.For formats that don't support embedded profiles this function should always return
Ok(None).fn iptc_metadata(&mut self) -> ImageResult<Option<Vec<u8>>>Returns the raw IPTC chunk, if it is present.
For formats that don't support embedded profiles this function should always return
Ok(None).fn orientation(&mut self) -> ImageResult<Orientation>Returns the orientation of the image.
This is usually obtained from the Exif metadata, if present. Formats that don't support indicating orientation in their image metadata will return
Ok(Orientation::NoTransforms).fn total_bytes(&self) -> u64Returns the total number of bytes in the decoded image.
This is the size of the buffer that must be passed to
read_imageorread_image_with_progress. The returned value may exceedusize::MAX, in which case it isn't actually possible to construct a buffer to decode all the image data into. If, however, the size does not fit in a u64 thenu64::MAXis returned.fn set_limits(&mut self, limits: Limits) -> ImageResult<()>Set the decoder to have the specified limits. See
Limitsfor the different kinds of limits that is possible to set.Note to implementors: make sure you call
Limits::check_supportso that decoding fails if any unsupported strict limits are set. Also make sure you callLimits::check_dimensionsto check themax_image_widthandmax_image_heightlimits.Note: By default, no limits are defined. This may be changed in future major version increases.
Implementors
impl<R: BufRead + Seek> ImageDecoder for BmpDecoder<R>impl<R: BufRead + Seek> ImageDecoder for GifDecoder<R>impl<R: BufRead + Seek> ImageDecoder for IcoDecoder<R>impl<R: BufRead + Seek> ImageDecoder for JpegDecoder<R>impl<R: BufRead + Seek> ImageDecoder for OpenExrDecoder<R>impl<R: BufRead + Seek> ImageDecoder for PngDecoder<R>impl<R: BufRead + Seek> ImageDecoder for TiffDecoder<R>impl<R: BufRead + Seek> ImageDecoder for WebPDecoder<R>impl<R: Read> ImageDecoder for DdsDecoder<R>impl<R: Read> ImageDecoder for FarbfeldDecoder<R>impl<R: Read> ImageDecoder for HdrDecoder<R>impl<R: Read> ImageDecoder for PnmDecoder<R>impl<R: Read> ImageDecoder for QoiDecoder<R>impl<R: Read> ImageDecoder for TgaDecoder<R>impl<T: ?Sized + ImageDecoder> ImageDecoder for Box<T>