Trait image::ImageDecoder [−][src]
pub trait ImageDecoder<'a>: Sized { type Reader: Read + 'a; fn dimensions(&self) -> (u32, u32); fn color_type(&self) -> ColorType; fn into_reader(self) -> ImageResult<Self::Reader>; fn original_color_type(&self) -> ExtendedColorType { ... } fn total_bytes(&self) -> u64 { ... } fn scanline_bytes(&self) -> u64 { ... } fn read_image(self, buf: &mut [u8]) -> ImageResult<()> { ... } fn read_image_with_progress<F: Fn(Progress)>(
self,
buf: &mut [u8],
progress_callback: F
) -> ImageResult<()> { ... } }
The trait that all decoders implement
Associated Types
Loading content...Required methods
fn dimensions(&self) -> (u32, u32)
[src]
Returns a tuple containing the width and height of the image
fn color_type(&self) -> ColorType
[src]
Returns the color type of the image data produced by this decoder
fn into_reader(self) -> ImageResult<Self::Reader>
[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
fn original_color_type(&self) -> ExtendedColorType
[src]
Retuns the color type of the image file before decoding
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.
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()
.
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[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
}
fn read_image_with_progress<F: Fn(Progress)>(
self,
buf: &mut [u8],
progress_callback: F
) -> ImageResult<()>
[src]
self,
buf: &mut [u8],
progress_callback: F
) -> ImageResult<()>
Same as read_image
but periodically calls the provided callback to give updates on loading
progress.
Implementors
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for BmpDecoder<R>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for BmpDecoder<R>
[src]type Reader = BmpReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for IcoDecoder<R>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for IcoDecoder<R>
[src]type Reader = IcoReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TgaDecoder<R>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TgaDecoder<R>
[src]type Reader = TGAReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn scanline_bytes(&self) -> u64
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TiffDecoder<R>
[src]
impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TiffDecoder<R>
[src]type Reader = TiffReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for DxtDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for DxtDecoder<R>
[src]type Reader = DxtReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn scanline_bytes(&self) -> u64
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for FarbfeldDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for FarbfeldDecoder<R>
[src]type Reader = FarbfeldReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn scanline_bytes(&self) -> u64
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for GifDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for GifDecoder<R>
[src]type Reader = GifReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for JpegDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for JpegDecoder<R>
[src]type Reader = JpegReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for PngDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for PngDecoder<R>
[src]type Reader = PngReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
fn scanline_bytes(&self) -> u64
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for PnmDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for PnmDecoder<R>
[src]type Reader = PnmReader<R>
fn dimensions(&self) -> (u32, u32)
[src]
fn color_type(&self) -> ColorType
[src]
fn original_color_type(&self) -> ExtendedColorType
[src]
fn into_reader(self) -> ImageResult<Self::Reader>
[src]
fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for WebPDecoder<R>
[src]
impl<'a, R: 'a + Read> ImageDecoder<'a> for WebPDecoder<R>
[src]