pub struct Decoder { /* private fields */ }Expand description
Decodes PNG files, with a configurable size limit.
use pltrs_codec::png::{self, ColorType, Decoder, ImageRef};
let gray = [0u8, 64, 128, 255];
let file = png::encode(ImageRef::new(2, 2, ColorType::Gray, png::BitDepth::Eight, &gray)?)?;
let image = Decoder::new().max_image_bytes(1 << 20).decode(&file)?;
assert_eq!((image.width(), image.height()), (2, 2));
assert_eq!(image.data(), gray);
assert_eq!(&image.to_rgba8()[4..8], [64, 64, 64, 255]);
let tiny_limit = Decoder::new().max_image_bytes(3);
assert!(tiny_limit.decode(&file).is_err());Implementations§
Source§impl Decoder
impl Decoder
Sourcepub const DEFAULT_MAX_IMAGE_BYTES: usize
pub const DEFAULT_MAX_IMAGE_BYTES: usize
The default limit on decoded pixel data: 1 GiB.
Sourcepub const fn max_image_bytes(self, limit: usize) -> Self
pub const fn max_image_bytes(self, limit: usize) -> Self
Sets the largest pixel buffer (in PNG layout, see
DecodedImage::data) the decoder will produce; larger images fail
with DecodeError::ImageTooLarge before any pixel memory is
allocated.
Sourcepub fn decode(&self, png: &[u8]) -> Result<DecodedImage, DecodeError>
pub fn decode(&self, png: &[u8]) -> Result<DecodedImage, DecodeError>
Decodes a complete PNG file.
Trait Implementations§
impl Copy for Decoder
impl Eq for Decoder
impl StructuralPartialEq for Decoder
Auto Trait Implementations§
impl Forget for Decoder
impl Freeze for Decoder
impl Move for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnsafeUnpin for Decoder
impl UnwindSafe for Decoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more