1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::iter::Iterator;
use num_rational::Ratio;
use buffer::RgbaImage;
use image::ImageResult;
pub struct Frames<'a> {
iterator: Box<Iterator<Item = ImageResult<Frame>> + 'a>
}
impl<'a> Frames<'a> {
pub fn new(iterator: Box<Iterator<Item = ImageResult<Frame>> + 'a>) -> Self {
Frames { iterator }
}
pub fn collect_frames(self) -> ImageResult<Vec<Frame>> {
self.collect()
}
}
impl<'a> Iterator for Frames<'a> {
type Item = ImageResult<Frame>;
fn next(&mut self) -> Option<ImageResult<Frame>> {
self.iterator.next()
}
}
#[derive(Clone)]
pub struct Frame {
delay: Ratio<u16>,
left: u32,
top: u32,
buffer: RgbaImage,
}
impl Frame {
pub fn new(buffer: RgbaImage) -> Frame {
Frame {
delay: Ratio::from_integer(0),
left: 0,
top: 0,
buffer,
}
}
pub fn from_parts(buffer: RgbaImage, left: u32, top: u32, delay: Ratio<u16>) -> Frame {
Frame {
delay,
left,
top,
buffer,
}
}
pub fn delay(&self) -> Ratio<u16> {
self.delay
}
pub fn buffer(&self) -> &RgbaImage {
&self.buffer
}
pub fn into_buffer(self) -> RgbaImage {
self.buffer
}
pub fn left(&self) -> u32 {
self.left
}
pub fn top(&self) -> u32 {
self.top
}
}