about summary refs log tree commit diff
path: root/gifed/src
diff options
context:
space:
mode:
authorGenevieve Alfirevic <gen@nyble.dev>2022-02-11 18:45:43 -0600
committerGenevieve Alfirevic <gen@nyble.dev>2022-02-11 18:45:43 -0600
commitd9aa9806d32cf717b3d22aae0514478d103f4aa8 (patch)
tree850da2e7b2d99fe811c6b2502e8d5c7f7d45f81d /gifed/src
parent6f79dd221125e599065fe06ce4d62b4cc97b4970 (diff)
downloadgifed-d9aa9806d32cf717b3d22aae0514478d103f4aa8.tar.gz
gifed-d9aa9806d32cf717b3d22aae0514478d103f4aa8.zip
Use paletted png for example
Diffstat (limited to 'gifed/src')
-rw-r--r--gifed/src/colorimage.rs2
-rw-r--r--gifed/src/gif.rs24
2 files changed, 22 insertions, 4 deletions
diff --git a/gifed/src/colorimage.rs b/gifed/src/colorimage.rs
index 93314ff..c9cae79 100644
--- a/gifed/src/colorimage.rs
+++ b/gifed/src/colorimage.rs
@@ -49,7 +49,7 @@ impl<'a> TryFrom<Image<'a>> for ColorImage {
 			img.height,
 			img.indicies,
 			img.palette,
-			img.trans_index(),
+			img.transparent_index(),
 		)
 	}
 }
diff --git a/gifed/src/gif.rs b/gifed/src/gif.rs
index 97da21e..3ccc185 100644
--- a/gifed/src/gif.rs
+++ b/gifed/src/gif.rs
@@ -122,7 +122,7 @@ impl<'a> Image<'a> {
 		let mut rgba = vec![0; self.indicies.len() * 4];
 
 		for (image_index, &color_index) in self.indicies.iter().enumerate() {
-			match self.trans_index() {
+			match self.transparent_index() {
 				Some(trans) if trans == color_index => {
 					rgba[image_index as usize * 4] = 0;
 					rgba[image_index * 4 + 1] = 0;
@@ -149,7 +149,7 @@ impl<'a> Image<'a> {
 		let mut rgb = vec![0; self.indicies.len() * 3];
 
 		for (image_index, &color_index) in self.indicies.iter().enumerate() {
-			match self.trans_index() {
+			match self.transparent_index() {
 				Some(trans) if trans == color_index => {
 					rgb[image_index as usize * 4] = transparent_replace.r;
 					rgb[image_index * 3 + 1] = transparent_replace.g;
@@ -180,11 +180,29 @@ impl<'a> Image<'a> {
 		None
 	}
 
-	pub fn trans_index(&self) -> Option<u8> {
+	pub fn transparent_index(&self) -> Option<u8> {
 		self.graphic_control()
 			.map(|gce| gce.transparent_index())
 			.flatten()
 	}
+
+	pub fn png_trns(&self) -> Option<Vec<u8>> {
+		if let Some(trans_idx) = self.transparent_index() {
+			let mut trns = Vec::with_capacity(self.palette.len());
+
+			for idx in 0..self.palette.len() as u8 {
+				if idx == trans_idx {
+					trns.push(0u8);
+				} else {
+					trns.push(255);
+				}
+			}
+
+			return Some(trns);
+		}
+
+		None
+	}
 }
 
 #[cfg(test)]