From db422e0c983d7543d4d5e742630b29e36c55cbd4 Mon Sep 17 00:00:00 2001
From: gennyble <gen@nyble.dev>
Date: Mon, 9 Oct 2023 19:17:36 -0500
Subject: update

---
 squash/.rustfmt.toml     |  1 +
 squash/src/.rustfmt.toml |  1 -
 squash/src/main.rs       | 38 +++++++++++++++++++++++---------------
 3 files changed, 24 insertions(+), 16 deletions(-)
 create mode 100644 squash/.rustfmt.toml
 delete mode 100644 squash/src/.rustfmt.toml

(limited to 'squash')

diff --git a/squash/.rustfmt.toml b/squash/.rustfmt.toml
new file mode 100644
index 0000000..218e203
--- /dev/null
+++ b/squash/.rustfmt.toml
@@ -0,0 +1 @@
+hard_tabs = true
diff --git a/squash/src/.rustfmt.toml b/squash/src/.rustfmt.toml
deleted file mode 100644
index 218e203..0000000
--- a/squash/src/.rustfmt.toml
+++ /dev/null
@@ -1 +0,0 @@
-hard_tabs = true
diff --git a/squash/src/main.rs b/squash/src/main.rs
index fe7f310..80c7cb0 100644
--- a/squash/src/main.rs
+++ b/squash/src/main.rs
@@ -51,7 +51,7 @@ fn main() -> Result<(), anyhow::Error> {
 		}
 	};
 
-	let squasher = Squasher::new(color_count, &image.data);
+	let mut squasher = Squasher::new(color_count, &image.data);
 	let size = squasher.map_over(&mut image.data);
 	image.data.resize(size, 0);
 
@@ -85,28 +85,36 @@ fn get_png<P: AsRef<Utf8Path>>(path: P) -> Result<Image, anyhow::Error> {
 	let decoder = Decoder::new(File::open(path.as_ref())?);
 	let mut reader = decoder.read_info()?;
 
-	let mut buf = vec![0; reader.output_buffer_size()];
-	let info = reader.next_frame(&mut buf)?;
-	let data = &buf[..info.buffer_size()];
-
-	println!(
-		"{}x{} * 3 = {} | out={}, bs={}",
-		info.width,
-		info.height,
-		info.width as usize * info.height as usize * 3,
-		buf.len(),
-		info.buffer_size()
-	);
+	let mut data = vec![0; reader.output_buffer_size()];
+	let info = reader.next_frame(&mut data)?;
+	data.resize(info.buffer_size(), 0);
 
 	let colors = info.color_type;
 	match colors {
-		ColorType::Grayscale | ColorType::GrayscaleAlpha | ColorType::Indexed | ColorType::Rgba => {
+		ColorType::Grayscale | ColorType::GrayscaleAlpha | ColorType::Indexed => {
 			bail!("colortype {colors:?} not supported")
 		}
+		ColorType::Rgba => {
+			let pixels = info.width as usize * info.height as usize;
+
+			// the first RGB is fine, we don't need to touch it
+			for idx in 1..pixels {
+				data[idx * 3] = data[idx * 4];
+				data[idx * 3 + 1] = data[idx * 4 + 1];
+				data[idx * 3 + 2] = data[idx * 4 + 2];
+			}
+			data.resize(pixels * 3, 0);
+
+			Ok(Image {
+				width: info.width as usize,
+				height: info.height as usize,
+				data,
+			})
+		}
 		ColorType::Rgb => Ok(Image {
 			width: info.width as usize,
 			height: info.height as usize,
-			data: data.to_vec(),
+			data,
 		}),
 	}
 }
-- 
cgit 1.4.1-3-g733a5