mirror of
https://github.com/G2-Games/lbee-utils.git
synced 2025-04-19 15:22:53 -05:00
moved create_png
to implementation of CZFile
This commit is contained in:
parent
f9542a1540
commit
aea6ad00b6
3 changed files with 23 additions and 21 deletions
|
@ -21,14 +21,15 @@ pub struct CZFile {
|
||||||
bitmap: Vec<u8>,
|
bitmap: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and save a PNG of the image data
|
impl CZFile {
|
||||||
/// This errors if the image data is too short
|
/// Create and save a PNG of the image data
|
||||||
pub fn create_png(image: &CZFile, out_name: &str) {
|
/// This errors if the image data is too short
|
||||||
let process_bitmap = image.bitmap.clone();
|
pub fn create_png(&self, out_name: &str) {
|
||||||
|
let process_bitmap = self.bitmap.clone();
|
||||||
|
|
||||||
let image_data = RgbaImage::from_raw(
|
let image_data = RgbaImage::from_raw(
|
||||||
image.header.res.0 as u32,
|
self.header.res.0 as u32,
|
||||||
image.header.res.1 as u32,
|
self.header.res.1 as u32,
|
||||||
process_bitmap,
|
process_bitmap,
|
||||||
)
|
)
|
||||||
.expect("Error encoding the image");
|
.expect("Error encoding the image");
|
||||||
|
@ -40,6 +41,7 @@ pub fn create_png(image: &CZFile, out_name: &str) {
|
||||||
eprintln!("You probably have an image with the CZ0 offset bug!")
|
eprintln!("You probably have an image with the CZ0 offset bug!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Utilities for decoding CZ0 images
|
/// Utilities for decoding CZ0 images
|
||||||
|
@ -103,7 +105,7 @@ pub mod cz0 {
|
||||||
pub fn decode_cz0(input_filename: &str) -> CZFile {
|
pub fn decode_cz0(input_filename: &str) -> CZFile {
|
||||||
println!("");
|
println!("");
|
||||||
println!("--Beginning CZ0 Decode--");
|
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...");
|
println!("Extracting Header...");
|
||||||
// TODO Research the header more!
|
// TODO Research the header more!
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pub mod cz_utils;
|
// Create the modules
|
||||||
pub mod utils;
|
pub mod cz_utils; // CZ file tools
|
||||||
use cz_utils::create_png;
|
pub mod utils; // Generic tools
|
||||||
use cz_utils::cz0::*;
|
use cz_utils::cz0::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -12,5 +12,5 @@ fn main() {
|
||||||
|
|
||||||
let image = decode_cz0("test.cz0");
|
let image = decode_cz0("test.cz0");
|
||||||
display_info(&image);
|
display_info(&image);
|
||||||
create_png(&image, "tmp.png");
|
image.create_png("tmp.png");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
pub fn bytes_to_word(first: u8, second: u8) -> i16 {
|
||||||
let final_value = ((second as i16) << 8) | (first as i16);
|
let final_value = ((second as i16) << 8) | (first as i16);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue