Struct Encoder

Source
pub struct Encoder<'a, F: Write> { /* private fields */ }
Expand description

APNG Encoder

§Example

use apng_encoder::{Color, Delay, Frame, Meta};
use apng_encoder::Encoder;
use std::fs::File;

// Generate 2x2 Animated PNG (4 frames)
let meta = Meta {
    width: 2,
    height: 2,
    color: Color::RGB(8),
    frames: 4,
    plays: None, // Infinite loop
};

// Delay = 1/2 (0.5) seconds
let frame = Frame {
    delay: Some(Delay::new(1, 2)),
    ..Default::default()
};

let mut file = File::create("test-output/2x2.png").unwrap();
let mut encoder = Encoder::create(&mut file, meta).unwrap();

// RED   GREEN
// BLACK BLUE
encoder.write_frame(
    &[
 // (x=0,y=0)            (x=1,y=0)
    0xFF, 0x00, 0x00,    0x00, 0xFF, 0x00,
 // (x=0,y=1)            (x=1,y=1)
    0x00, 0x00, 0x00,    0x00, 0x00, 0xFF,
    ],
    Some(&frame),
    None,
    None).unwrap();
// BLACK RED
// BLUE  GREEN
encoder.write_frame(
    &[
    0x00, 0x00, 0x00,   0xFF, 0x00, 0x00,
    0x00, 0x00, 0xFF,   0x00, 0xFF, 0x00,
    ],
    Some(&frame),
    None,
    None).unwrap();
// BLUE  BLACK
// GREEN RED
encoder.write_frame(
    &[
    0x00, 0x00, 0xFF,   0x00, 0x00, 0x00,
    0x00, 0xFF, 0x00,   0xFF, 0x00, 0x00,
    ],
    Some(&frame),
    None,
    None).unwrap();
// GREEN BLUE
// RED   BLACK
encoder.write_frame(
    &[
    0x00, 0xFF, 0x00,   0x00, 0x00, 0xFF,
    0xFF, 0x00, 0x00,   0x00, 0x00, 0x00,
    ],
    Some(&frame),
    None,
    None).unwrap();
// !!IMPORTANT DONT FORGET!!
encoder.finish().unwrap();

Implementations§

Source§

impl<'a, F: Write> Encoder<'a, F>

Source

pub fn create(writer: &'a mut F, meta: Meta) -> ApngResult<Self>

Source

pub fn finish(self) -> ApngResult<()>

Source

pub fn write_default_image( &mut self, image_data: &[u8], filter: Option<Filter>, row_stride: Option<usize>, ) -> ApngResult<()>

Source

pub fn write_frame( &mut self, image_data: &[u8], frame: Option<&Frame>, filter: Option<Filter>, row_stride: Option<usize>, ) -> ApngResult<()>

Auto Trait Implementations§

§

impl<'a, F> Freeze for Encoder<'a, F>

§

impl<'a, F> RefUnwindSafe for Encoder<'a, F>
where F: RefUnwindSafe,

§

impl<'a, F> Send for Encoder<'a, F>
where F: Send,

§

impl<'a, F> Sync for Encoder<'a, F>
where F: Sync,

§

impl<'a, F> Unpin for Encoder<'a, F>

§

impl<'a, F> !UnwindSafe for Encoder<'a, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.