diff --git a/cz/Cargo.toml b/cz/Cargo.toml index 6eeab66..8348135 100644 --- a/cz/Cargo.toml +++ b/cz/Cargo.toml @@ -10,5 +10,4 @@ A encoder/decoder for CZ# image files used in [dependencies] byteorder = "1.5.0" thiserror = "1.0.59" -png = "0.17.13" -image = { version = "0.25.1", default-features = false } +image = "0.25.1" diff --git a/cz/src/compression.rs b/cz/src/compression.rs index 2f2abde..ebfc468 100644 --- a/cz/src/compression.rs +++ b/cz/src/compression.rs @@ -343,10 +343,9 @@ fn compress_lzw(data: &[u8], size: usize, last: String) -> (usize, Vec, Str } let mut dictionary_count = (dictionary.len() + 1) as u16; - let mut element = String::new(); if last.len() != 0 { - element = last.clone() + element = last } let mut compressed = Vec::with_capacity(size); @@ -373,7 +372,7 @@ fn compress_lzw(data: &[u8], size: usize, last: String) -> (usize, Vec, Str let last_element = element; if compressed.len() == 0 { if last_element.len() != 0 { - for c in last_element.bytes() { + for c in last_element.chars() { compressed.push(*dictionary.get(&c.to_string()).unwrap()); } } diff --git a/cz/src/dynamic.rs b/cz/src/dynamic.rs index c210b43..1e7643e 100644 --- a/cz/src/dynamic.rs +++ b/cz/src/dynamic.rs @@ -1,5 +1,5 @@ use std::{ - fs::File, io::{BufReader, Cursor, Read, Seek, SeekFrom, Write}, path::Path + fs::{self, File}, io::{BufReader, BufWriter, Read, Seek, SeekFrom, Write}, path::Path }; use byteorder::ReadBytesExt; @@ -22,20 +22,14 @@ impl DynamicCz { Self::decode(&mut img_file) } - pub fn save_as_png>(&self, path: &P) -> Result<(), png::EncodingError> { - let file = std::fs::File::create(path).unwrap(); - let writer = std::io::BufWriter::new(file); + pub fn save_as_png>(&self, path: &P) -> Result<(), image::error::EncodingError> { + let image = image::RgbaImage::from_raw( + self.header_common.width() as u32, + self.header_common.height() as u32, + self.bitmap.clone() + ).unwrap(); - let mut encoder = png::Encoder::new( - writer, - self.header().width() as u32, - self.header().height() as u32, - ); - encoder.set_color(png::ColorType::Rgba); - encoder.set_depth(png::BitDepth::Eight); - let mut writer = encoder.write_header()?; - - writer.write_image_data(self.bitmap())?; // Save + image.save_with_format(path, image::ImageFormat::Png).unwrap(); Ok(()) } diff --git a/utils/src/main.rs b/utils/src/main.rs index 59f5e94..f47c938 100644 --- a/utils/src/main.rs +++ b/utils/src/main.rs @@ -1,7 +1,11 @@ use cz::dynamic::DynamicCz; fn main() { - let img = DynamicCz::open("../../test_files/x5a3bvy.cz1").unwrap(); + let img = DynamicCz::open("font72.cz1").unwrap(); img.save_as_cz("test.cz1").unwrap(); + img.save_as_png("test1.png").unwrap(); + + let img2 = DynamicCz::open("test.cz1").unwrap(); + img2.save_as_png("test2.png").unwrap(); }