about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2022-08-23 11:44:00 -0500
committerGenny <gen@nyble.dev>2022-08-23 11:44:00 -0500
commit20ee6b267bc5ef384db9ecf37ae2969aadf5b082 (patch)
treebd3d037a8b6d1741e25274e21e8f4b503387d80e
parent6e12de4faa129ebe0f0e46ede46c1780bb23a315 (diff)
downloadgifed-20ee6b267bc5ef384db9ecf37ae2969aadf5b082.tar.gz
gifed-20ee6b267bc5ef384db9ecf37ae2969aadf5b082.zip
Use weezl for LZW encoding 😔
-rw-r--r--gifed/src/block/indexedimage.rs8
-rw-r--r--gifed/src/block/mod.rs12
2 files changed, 18 insertions, 2 deletions
diff --git a/gifed/src/block/indexedimage.rs b/gifed/src/block/indexedimage.rs
index 8834d33..730a02c 100644
--- a/gifed/src/block/indexedimage.rs
+++ b/gifed/src/block/indexedimage.rs
@@ -1,5 +1,7 @@
 use std::convert::TryFrom;
 
+use weezl::encode::Encoder;
+
 use super::{ColorTable, ImageDescriptor};
 use crate::LZW;
 
@@ -49,7 +51,11 @@ impl IndexedImage {
 		// First write out the MCS
 		out.push(mcs);
 
-		let compressed = LZW::encode(mcs, &self.indicies);
+		//FIXME: gen- This seems  broken
+		//let compressed = LZW::encode(mcs, &self.indicies);
+		let compressed = Encoder::new(weezl::BitOrder::Lsb, mcs)
+			.encode(&self.indicies)
+			.unwrap();
 
 		for chunk in compressed.chunks(255) {
 			out.push(chunk.len() as u8);
diff --git a/gifed/src/block/mod.rs b/gifed/src/block/mod.rs
index 31e78b1..28f8c86 100644
--- a/gifed/src/block/mod.rs
+++ b/gifed/src/block/mod.rs
@@ -62,7 +62,17 @@ fn encode_extension(block: &Block) -> Box<[u8]> {
 			vec.push(gce.transparency_index);
 		}
 		Block::CommentExtension(comment) => todo!(),
-		Block::ApplicationExtension(app) => todo!(),
+		Block::ApplicationExtension(app) => {
+			vec.push(0xFF); // Application extension label
+			vec.push(0x0B); // 11 bytes, fixed, for the ident and auth
+			vec.extend_from_slice(&app.identifier);
+			vec.extend_from_slice(&app.authentication_code);
+
+			for chnk in app.data.chunks(255) {
+				vec.push(chnk.len() as u8);
+				vec.extend_from_slice(chnk);
+			}
+		}
 		Block::LoopingExtension(lc) => {
 			vec.push(0xFF); // Application extension label
 			vec.push(0x0B); // 11 bytes in this block