about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gifed/Cargo.toml9
-rw-r--r--gifed/src/block/indexedimage.rs2
-rw-r--r--gifed/src/gif_builder.rs26
-rw-r--r--gifed/src/lib.rs2
4 files changed, 20 insertions, 19 deletions
diff --git a/gifed/Cargo.toml b/gifed/Cargo.toml
index ae9f5a8..ce49947 100644
--- a/gifed/Cargo.toml
+++ b/gifed/Cargo.toml
@@ -9,16 +9,13 @@ repository = "https://github.com/genuinebyte/gifed"
 
 [dependencies]
 bitvec = "1.0.1"
-colorsquash = { git = "https://github.com/novedevo/colorsquash", version = "0.2.0", optional = true }
-rgb = {version="0.8", optional = true}
+color_quant = "1.1.0"
+rgb = { version = "0.8", optional = true }
 weezl = "0.1.5"
 
 [features]
 weezl-encode = []
-default = [
-	"colorsquash",
-	"rgb"
-]
+default = ["rgb"]
 
 [dev-dependencies]
 rand = "0.8.5"
diff --git a/gifed/src/block/indexedimage.rs b/gifed/src/block/indexedimage.rs
index 659d0af..eb74aab 100644
--- a/gifed/src/block/indexedimage.rs
+++ b/gifed/src/block/indexedimage.rs
@@ -47,7 +47,7 @@ impl IndexedImage {
 		let compressed = crate::LZW::new(mcs).encode(&self.indicies);
 
 		#[cfg(feature = "weezl-encode")]
-		let compressed = Encoder::new(weezl::BitOrder::Lsb, mcs)
+		let compressed = weezl::encode::Encoder::new(weezl::BitOrder::Lsb, mcs)
 			.encode(&self.indicies)
 			.unwrap();
 
diff --git a/gifed/src/gif_builder.rs b/gifed/src/gif_builder.rs
index a6f9f95..9d039bf 100644
--- a/gifed/src/gif_builder.rs
+++ b/gifed/src/gif_builder.rs
@@ -4,8 +4,8 @@ use crate::{
 	EncodeError, Gif,
 };
 
-use colorsquash::Squasher;
-use rgb::RGB8;
+use color_quant::NeuQuant;
+use rgb::{ComponentBytes, FromSlice, RGB8};
 
 use std::convert::TryFrom;
 
@@ -56,15 +56,13 @@ impl GifBuilder {
 			} = frame;
 
 			let delay = interval
-				.map(|interval| interval * 10)
+				.map(|interval| interval)
 				.or(framerate.map(|fr| 100 / fr))
 				.unwrap_or(10);
 			ImageBuilder::new(width, height)
 				.delay(delay)
 				.palette(palette)
-				.build(image_indices)?
-				.image
-				.compress(None)
+				.build(image_indices)
 		});
 
 		for compressed_image in images {
@@ -103,13 +101,19 @@ impl From<Vec<Vec<RGB8>>> for Frame {
 	fn from(image: Vec<Vec<RGB8>>) -> Self {
 		let flat = image.concat();
 
-		let squasher = Squasher::new(255u8, flat.as_slice());
+		let flat_rgba = flat.as_rgba();
+		let quant = NeuQuant::new(1, 256, &flat_rgba.as_bytes());
+
+		let mut indicies = vec![0; flat.len()];
+		for (image_idx, px) in flat.iter().enumerate() {
+			let color_idx = quant.index_of(&[px.r, px.g, px.b, 255]);
+			indicies[image_idx] = color_idx as u8;
+		}
+
+		let palette = Palette::try_from(quant.color_map_rgb().as_slice()).unwrap();
 
-		let mut image_indices = vec![0; flat.len()];
-		squasher.map_unsafe(flat.as_slice(), &mut image_indices);
-		let palette = Palette::try_from(squasher.palette_bytes().as_slice()).unwrap();
 		Self {
-			image_indices,
+			image_indices: indicies,
 			interval: None,
 			palette,
 		}
diff --git a/gifed/src/lib.rs b/gifed/src/lib.rs
index 508ef5c..3990e33 100644
--- a/gifed/src/lib.rs
+++ b/gifed/src/lib.rs
@@ -2,7 +2,7 @@ mod gif;
 mod lzw;
 
 pub mod block;
-#[cfg(all(feature = "colorsquash", feature = "rgb"))]
+#[cfg(all(feature = "rgb"))]
 pub mod gif_builder;
 pub mod reader;
 pub mod writer;