about summary refs log tree commit diff
path: root/src/block/extension/mod.rs
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-03-10 02:44:45 -0600
committerGenny <gen@nyble.dev>2021-03-10 02:44:45 -0600
commitfa403b904c8596d8d1731d7f8bfafa6c0145e3dd (patch)
treeb1c0b89da9f51f35b7984a30d9c249788922bb9a /src/block/extension/mod.rs
parent743888ae0c1038a92f4a0b64709a313eba70c887 (diff)
downloadgifed-fa403b904c8596d8d1731d7f8bfafa6c0145e3dd.tar.gz
gifed-fa403b904c8596d8d1731d7f8bfafa6c0145e3dd.zip
Implement, roughly, extensions, animation, and looping
Diffstat (limited to 'src/block/extension/mod.rs')
-rw-r--r--src/block/extension/mod.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/block/extension/mod.rs b/src/block/extension/mod.rs
new file mode 100644
index 0000000..4d65c09
--- /dev/null
+++ b/src/block/extension/mod.rs
@@ -0,0 +1,36 @@
+mod graphiccontrol;
+
+pub use graphiccontrol::{DisposalMethod, GraphicControl};
+
+pub enum Extension {
+	GraphicControl(GraphicControl),
+	Looping(u16)
+}
+
+impl From<&Extension> for Box<[u8]> {
+	fn from(ext: &Extension) -> Self {
+		let mut vec = vec![];
+		vec.push(0x21); // Push the extension introducer
+
+		match ext {
+			Extension::GraphicControl(gc) => {
+				vec.push(0xF9); // Graphic control label
+				vec.push(0x04); // Block size for this extension is always 4
+				vec.push(gc.packed);
+				vec.extend_from_slice(&gc.delay_time.to_le_bytes());
+				vec.push(gc.transparency_index);
+			},
+			Extension::Looping(count) => {
+				vec.push(0xFF); // Application extension label
+				vec.push(0x0B); // 11 bytes in this block
+				vec.extend_from_slice(b"NETSCAPE2.0"); // App. ident. and "auth code"
+				vec.push(0x03); // Sub-block length
+				vec.push(0x01); // Identifies netscape looping extension
+				vec.extend_from_slice(&count.to_le_bytes());
+			} 
+		}
+
+		vec.push(0x00); // Zero-length data block indicates end of extension
+		vec.into_boxed_slice()
+	}
+}
\ No newline at end of file