-
Notifications
You must be signed in to change notification settings - Fork 14
/
gif.fathom
61 lines (55 loc) · 1.69 KB
/
gif.fathom
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
//! # Graphics Interchange Format
//!
//! ## References
//!
//! - [GIF89a Specification](https://www.w3.org/Graphics/GIF/spec-gif89a.txt)
//! - [Wikipedia](https://en.wikipedia.org/wiki/GIF)
//! - [Kaitai Format](https://formats.kaitai.io/gif/)
/// # Logical Screen Descriptor
///
/// ## References
///
/// - [GIF89a Specification: Section 18](https://www.w3.org/Graphics/GIF/spec-gif89a.txt)
def logical_screen_descriptor = {
image_width <- u16le,
image_height <- u16le,
flags <- u8,
bg_color_index <- u8,
pixel_aspect_ratio <- u8,
// TODO: interpret flags
// has_color_table : Bool = (flags & 0b10000000) != 0,
// color_table_size : U16 = 2 << (flags & 7),
};
/// # Header
///
/// ## References
///
/// - [GIF89a Specification: Section 17](https://www.w3.org/Graphics/GIF/spec-gif89a.txt)
def header = {
magic <- repeat_len8 3 u8, // TODO: where magic == ascii "GIF"`,
version <- repeat_len8 3 u8,
};
/// # Global Color Table Entry
///
/// ## References
///
/// - [GIF89a Specification: Section 19](https://www.w3.org/Graphics/GIF/spec-gif89a.txt)
def color_table_entry = {
red <- u8,
green <- u8,
blue <- u8,
};
/// # Global Color Table
///
/// ## References
///
/// - [GIF89a Specification: Section 19](https://www.w3.org/Graphics/GIF/spec-gif89a.txt)
def global_color_table (len : U16) = {
entries <- repeat_len16 len color_table_entry,
};
def main = {
header <- header,
screen <- logical_screen_descriptor,
// global_color_table <- global_color_table screen.color_table_size, // TODO: if `screen.has_color_table,`
// blocks <- array 0 block, // TODO: repeat while not EOF or BlockTerminator
};