moved create_png to implementation of CZFile

This commit is contained in:
G2 2023-04-20 10:15:57 -05:00
parent f9542a1540
commit aea6ad00b6
3 changed files with 23 additions and 21 deletions

View file

@ -21,23 +21,25 @@ pub struct CZFile {
bitmap: Vec<u8>,
}
/// Create and save a PNG of the image data
/// This errors if the image data is too short
pub fn create_png(image: &CZFile, out_name: &str) {
let process_bitmap = image.bitmap.clone();
impl CZFile {
/// Create and save a PNG of the image data
/// This errors if the image data is too short
pub fn create_png(&self, out_name: &str) {
let process_bitmap = self.bitmap.clone();
let image_data = RgbaImage::from_raw(
image.header.res.0 as u32,
image.header.res.1 as u32,
process_bitmap,
)
.expect("Error encoding the image");
let image_data = RgbaImage::from_raw(
self.header.res.0 as u32,
self.header.res.1 as u32,
process_bitmap,
)
.expect("Error encoding the image");
match image_data.save_with_format(out_name, ImageFormat::Png) {
Ok(()) => {}
Err(e) => {
eprintln!("ERROR SAVING IMAGE: {}", e);
eprintln!("You probably have an image with the CZ0 offset bug!")
match image_data.save_with_format(out_name, ImageFormat::Png) {
Ok(()) => {}
Err(e) => {
eprintln!("ERROR SAVING IMAGE: {}", e);
eprintln!("You probably have an image with the CZ0 offset bug!")
}
}
}
}
@ -103,7 +105,7 @@ pub mod cz0 {
pub fn decode_cz0(input_filename: &str) -> CZFile {
println!("");
println!("--Beginning CZ0 Decode--");
let mut input = fs::read(input_filename).unwrap();
let mut input = fs::read(input_filename).expect("Error, could not open image");
println!("Extracting Header...");
// TODO Research the header more!

View file

@ -1,6 +1,6 @@
pub mod cz_utils;
pub mod utils;
use cz_utils::create_png;
// Create the modules
pub mod cz_utils; // CZ file tools
pub mod utils; // Generic tools
use cz_utils::cz0::*;
fn main() {
@ -12,5 +12,5 @@ fn main() {
let image = decode_cz0("test.cz0");
display_info(&image);
create_png(&image, "tmp.png");
image.create_png("tmp.png");
}

View file

@ -1,4 +1,4 @@
/// Converts 8 bit bytes to a 16 bit little endian word or
/// Converts 8 bit bytes to a 16 bit little endian word
pub fn bytes_to_word(first: u8, second: u8) -> i16 {
let final_value = ((second as i16) << 8) | (first as i16);