apng_encoder/
apng.rs

1
2use std::default::Default;
3
4
5
6pub mod encoder;
7pub mod errors;
8
9
10
11#[derive(Debug, Clone)]
12pub struct Meta {
13    pub color: Color,
14    /// Number of animation frames
15    pub frames: u32,
16    pub height: u32,
17    /// Number of plays
18    pub plays: Option<u32>,
19    pub width: u32,
20}
21
22#[derive(Debug, PartialEq, Clone, Copy)]
23pub enum Color {
24    Grayscale(u8),
25    GrayscaleA(u8),
26    // Palette,
27    RGB(u8),
28    RGBA(u8),
29}
30
31#[derive(Debug, Default, Clone)]
32pub struct Frame {
33    pub width: Option<u32>,
34    pub height: Option<u32>,
35    pub x: Option<u32>,
36    pub y: Option<u32>,
37    pub delay: Option<Delay>,
38    pub dispose_operator: Option<DisposeOperator>,
39    pub blend_operator: Option<BlendOperator>,
40}
41
42#[derive(Debug, Default, Clone, Copy)]
43pub struct Delay {
44    pub numerator: u16,
45    pub denominator: u16,
46}
47
48#[derive(Debug, Clone, Copy)]
49pub enum DisposeOperator {
50    None = 0,
51    Background = 1,
52    Previous = 2,
53}
54
55#[derive(Debug, Clone, Copy)]
56pub enum BlendOperator {
57    Source = 0,
58    Over = 1,
59}
60
61
62impl Color {
63    pub fn bit_depth(self) -> u8 {
64        use self::Color::*;
65
66        match self {
67            Grayscale(b) | GrayscaleA(b) | RGB(b) | RGBA(b) => b,
68        }
69    }
70
71    pub fn pixel_bytes(self) -> usize {
72        use self::Color::*;
73
74        match self {
75            Grayscale(16) => 2,
76            Grayscale(_) => 1,
77            GrayscaleA(16) => 4,
78            GrayscaleA(_) => 2,
79            RGB(16) => 6,
80            RGB(_) => 3,
81            RGBA(16) => 8,
82            RGBA(_) => 4,
83        }
84    }
85}
86
87
88impl Delay {
89    pub fn new(numerator: u16, denominator: u16) -> Self {
90        Delay { numerator, denominator }
91    }
92}
93
94
95impl Default for DisposeOperator {
96    fn default() -> Self {
97        DisposeOperator::None
98    }
99}
100
101impl Default for BlendOperator {
102    fn default() -> Self {
103        BlendOperator::Source
104    }
105}