about summary refs log tree commit diff
path: root/gifed/src/block/extension
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-11-23 00:57:05 -0600
committerGenny <gen@nyble.dev>2021-11-23 00:57:05 -0600
commite2730a9990e13803f6fd6f3c7a6942e64b833f5f (patch)
treeaabcc26dde59256b62fe5edd8b29ff39bf4c56e8 /gifed/src/block/extension
parentc75b385f52b86bb31e13615086f5040074e3b77b (diff)
downloadgifed-e2730a9990e13803f6fd6f3c7a6942e64b833f5f.tar.gz
gifed-e2730a9990e13803f6fd6f3c7a6942e64b833f5f.zip
Collapse extension enum into block
Diffstat (limited to 'gifed/src/block/extension')
-rw-r--r--gifed/src/block/extension/graphiccontrol.rs8
-rw-r--r--gifed/src/block/extension/mod.rs46
2 files changed, 7 insertions, 47 deletions
diff --git a/gifed/src/block/extension/graphiccontrol.rs b/gifed/src/block/extension/graphiccontrol.rs
index b595554..8b62160 100644
--- a/gifed/src/block/extension/graphiccontrol.rs
+++ b/gifed/src/block/extension/graphiccontrol.rs
@@ -22,7 +22,7 @@ impl GraphicControl {
 		};
 
 		ret.set_disposal_method(disposal_method);
-		ret.user_input(user_input_flag);
+		ret.set_user_input(user_input_flag);
 		ret.transparency(transparency_flag);
 
 		ret
@@ -51,7 +51,11 @@ impl GraphicControl {
 		self.transparency_index
 	}
 
-	pub fn user_input(&mut self, flag: bool) {
+	pub fn user_input(&self) -> bool {
+		self.packed & 0b000_000_1_0 > 0
+	}
+
+	pub fn set_user_input(&mut self, flag: bool) {
 		if flag {
 			self.packed |= 0b000_000_1_0;
 		} else {
diff --git a/gifed/src/block/extension/mod.rs b/gifed/src/block/extension/mod.rs
index fb5eb20..99ac88b 100644
--- a/gifed/src/block/extension/mod.rs
+++ b/gifed/src/block/extension/mod.rs
@@ -1,49 +1,5 @@
 mod application;
 mod graphiccontrol;
 
-pub use graphiccontrol::{DisposalMethod, GraphicControl};
-
 pub use self::application::Application;
-
-pub enum Extension {
-	GraphicControl(GraphicControl),
-	Looping(u16),
-	Comment(Vec<u8>), // Plain Text
-	Application(Application),
-}
-
-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());
-			}
-			Extension::Comment(_) => todo!(),
-			Extension::Application(_) => todo!(),
-		}
-
-		vec.push(0x00); // Zero-length data block indicates end of extension
-		vec.into_boxed_slice()
-	}
-}
-
-impl From<GraphicControl> for Extension {
-	fn from(gce: GraphicControl) -> Self {
-		Extension::GraphicControl(gce)
-	}
-}
+pub use graphiccontrol::{DisposalMethod, GraphicControl};