pub struct Encoder { /* private fields */ }Expand description
Configures and runs PNG encoding.
The defaults match what matplotlib gets from Pillow: zlib level 6 and
Strategy::Filtered with Pillow’s adaptive filtering, and no
ancillary chunks.
use pltrs_codec::CompressionLevel;
use pltrs_codec::png::{Encoder, FilterStrategy, FilterType, ImageRef};
let pixels = vec![255u8; 64 * 48 * 4];
let png = Encoder::new()
.compression(CompressionLevel::BEST)
.filter(FilterStrategy::Fixed(FilterType::Up))
.dpi(72.0)
.text("Software", "pltrs")
.encode(ImageRef::rgba8(64, 48, &pixels)?)?;
assert!(png.starts_with(&pltrs_codec::png::SIGNATURE));Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn compression(self, level: CompressionLevel) -> Self
pub fn compression(self, level: CompressionLevel) -> Self
Sets the zlib compression level.
Sourcepub fn strategy(self, strategy: Strategy) -> Self
pub fn strategy(self, strategy: Strategy) -> Self
Sets the zlib strategy (Pillow’s compress_type;
Strategy::Filtered by default).
Sourcepub fn filter(self, strategy: FilterStrategy) -> Self
pub fn filter(self, strategy: FilterStrategy) -> Self
Sets how scanline filters are chosen.
Sourcepub fn physical_dimensions(self, dimensions: PhysicalDimensions) -> Self
pub fn physical_dimensions(self, dimensions: PhysicalDimensions) -> Self
Writes a pHYs chunk with these dimensions.
Sourcepub fn dpi(self, dpi: f64) -> Self
pub fn dpi(self, dpi: f64) -> Self
Writes a pHYs chunk for dpi dots per inch, as matplotlib does with
the figure’s dpi. An invalid value (see
PhysicalDimensions::from_dpi) makes encode fail
with EncodeError::InvalidDpi.
Trait Implementations§
impl StructuralPartialEq for Encoder
Auto Trait Implementations§
impl Forget for Encoder
impl Freeze for Encoder
impl Move for Encoder
impl RefUnwindSafe for Encoder
impl Send for Encoder
impl Sync for Encoder
impl Unpin for Encoder
impl UnsafeUnpin for Encoder
impl UnwindSafe for Encoder
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