[−][src]Trait purrmitive::ImageDecoder
The trait that all decoders implement
Associated Types
Loading content...Required methods
pub fn dimensions(&self) -> (u32, u32)
[src]
Returns a tuple containing the width and height of the image
pub fn color_type(&self) -> ColorType
[src]
Returns the color type of the image data produced by this decoder
pub fn into_reader(self) -> Result<Self::Reader, ImageError>
[src]
Returns a reader that can be used to obtain the bytes of the image. For the best
performance, always try to read at least scanline_bytes
from the reader at a time. Reading
fewer bytes will cause the reader to perform internal buffering.
Provided methods
pub fn original_color_type(&self) -> ExtendedColorType
[src]
Retuns the color type of the image file before decoding
pub fn total_bytes(&self) -> u64
[src]
Returns the total number of bytes in the decoded image.
This is the size of the buffer that must be passed to read_image
or
read_image_with_progress
. The returned value may exceed usize::MAX, in
which case it isn't actually possible to construct a buffer to decode all the image data
into.
pub fn scanline_bytes(&self) -> u64
[src]
Returns the minimum number of bytes that can be efficiently read from this decoder. This may
be as few as 1 or as many as total_bytes()
.
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
Returns all the bytes in the image.
This function takes a slice of bytes and writes the pixel data of the image into it. Although not required, for certain color types callers may want to pass buffers which are aligned to 2 or 4 byte boundaries to the slice can be cast to a u16 or u32. To accommodate such casts, the returned contents will always be in native endian.
Panics
This function panics if buf.len() != self.total_bytes().
Examples
use zerocopy::{AsBytes, FromBytes};
fn read_16bit_image(decoder: impl ImageDecoder) -> Vec<16> {
let mut buf: Vec<u16> = vec![0; decoder.total_bytes()/2];
decoder.read_image(buf.as_bytes());
buf
}
pub fn read_image_with_progress<F>(
self,
buf: &mut [u8],
progress_callback: F
) -> Result<(), ImageError> where
F: Fn(Progress),
[src]
self,
buf: &mut [u8],
progress_callback: F
) -> Result<(), ImageError> where
F: Fn(Progress),
Same as read_image
but periodically calls the provided callback to give updates on loading
progress.
Implementors
impl<'a, R> ImageDecoder<'a> for BmpDecoder<R> where
R: 'a + Read + Seek,
[src]
R: 'a + Read + Seek,
type Reader = BmpReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<BmpDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<BmpDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for DdsDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = DXTReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn scanline_bytes(&self) -> u64
[src]
pub fn into_reader(
self
) -> Result<<DdsDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<DdsDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for DxtDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = DXTReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn scanline_bytes(&self) -> u64
[src]
pub fn into_reader(
self
) -> Result<<DxtDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<DxtDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for FarbfeldDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = FarbfeldReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<FarbfeldDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<FarbfeldDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn scanline_bytes(&self) -> u64
[src]
impl<'a, R> ImageDecoder<'a> for GifDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = GifReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<GifDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<GifDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for HDRAdapter<R> where
R: 'a + BufRead,
[src]
R: 'a + BufRead,
type Reader = HdrReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<HDRAdapter<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<HDRAdapter<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for IcoDecoder<R> where
R: 'a + Read + Seek,
[src]
R: 'a + Read + Seek,
type Reader = IcoReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<IcoDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<IcoDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for JpegDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = JpegReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<JpegDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<JpegDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for PngDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = PNGReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<PngDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<PngDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
pub fn scanline_bytes(&self) -> u64
[src]
impl<'a, R> ImageDecoder<'a> for PnmDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = PnmReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn original_color_type(&self) -> ExtendedColorType
[src]
pub fn into_reader(
self
) -> Result<<PnmDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<PnmDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for TgaDecoder<R> where
R: 'a + Read + Seek,
[src]
R: 'a + Read + Seek,
type Reader = TGAReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn scanline_bytes(&self) -> u64
[src]
pub fn into_reader(
self
) -> Result<<TgaDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<TgaDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for TiffDecoder<R> where
R: 'a + Read + Seek,
[src]
R: 'a + Read + Seek,
type Reader = TiffReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<TiffDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<TiffDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
pub fn read_image(self, buf: &mut [u8]) -> Result<(), ImageError>
[src]
impl<'a, R> ImageDecoder<'a> for WebPDecoder<R> where
R: 'a + Read,
[src]
R: 'a + Read,
type Reader = WebpReader<R>
pub fn dimensions(&self) -> (u32, u32)
[src]
pub fn color_type(&self) -> ColorType
[src]
pub fn into_reader(
self
) -> Result<<WebPDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>
[src]
self
) -> Result<<WebPDecoder<R> as ImageDecoder<'a>>::Reader, ImageError>