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
94
use std::io::Read;
use components::header::{Header, SecondHeader};
use components::metadata::Metadata;
use components::transformations::Transform;
use decoding_image::DecodingImage;
pub use decoder::Decoder;
pub use error::{Error, Result};
pub mod components;
mod decoder;
mod decoding_image;
mod error;
mod maniac;
mod numbers;
mod pixels;
pub struct Flif {
info: FlifInfo,
raw: Box<[u8]>,
}
impl Flif {
pub fn decode<R: Read>(reader: R) -> Result<Self> {
Decoder::new(reader)?.decode_image()
}
pub fn decode_with_limits<R: Read>(reader: R, limits: Limits) -> Result<Self> {
Decoder::with_limits(reader, limits)?.decode_image()
}
pub fn info(&self) -> &FlifInfo {
&self.info
}
pub fn raw(&self) -> &Box<[u8]> {
&self.raw
}
pub fn into_raw(self) -> Box<[u8]> {
self.raw
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Limits {
pub metadata_chunk: u32,
pub metadata_count: u32,
pub pixels: u64,
pub maniac_nodes: u32,
}
impl Default for Limits {
fn default() -> Self {
Self {
metadata_chunk: 1 << 20,
metadata_count: 8,
pixels: 1 << 26,
maniac_nodes: 1 << 14,
}
}
}
#[derive(Debug)]
pub struct FlifInfo {
pub header: Header,
pub metadata: Vec<Metadata>,
pub second_header: SecondHeader,
transform: Box<Transform>,
}