mirror of
https://github.com/G2-Games/lbee-utils.git
synced 2025-04-19 15:22:53 -05:00
Ran cargo fmt
to auto format the files in a standard way, cleaned up cz_utils.rs
This commit is contained in:
parent
cb3343c933
commit
f9542a1540
3 changed files with 45 additions and 35 deletions
|
@ -1,4 +1,4 @@
|
||||||
use image::{RgbaImage, ImageFormat};
|
use image::{ImageFormat, RgbaImage};
|
||||||
|
|
||||||
/// The header of a CZ* file
|
/// The header of a CZ* file
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -26,18 +26,14 @@ pub struct CZFile {
|
||||||
pub fn create_png(image: &CZFile, out_name: &str) {
|
pub fn create_png(image: &CZFile, out_name: &str) {
|
||||||
let process_bitmap = image.bitmap.clone();
|
let process_bitmap = image.bitmap.clone();
|
||||||
|
|
||||||
let tmp = match RgbaImage::from_raw(
|
let image_data = RgbaImage::from_raw(
|
||||||
image.header.res.0 as u32,
|
image.header.res.0 as u32,
|
||||||
image.header.res.1 as u32,
|
image.header.res.1 as u32,
|
||||||
process_bitmap,
|
process_bitmap,
|
||||||
) {
|
)
|
||||||
Some(img) => img,
|
.expect("Error encoding the image");
|
||||||
None => {
|
|
||||||
RgbaImage::new(0, 0)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match tmp.save_with_format(out_name, ImageFormat::Png) {
|
match image_data.save_with_format(out_name, ImageFormat::Png) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("ERROR SAVING IMAGE: {}", e);
|
eprintln!("ERROR SAVING IMAGE: {}", e);
|
||||||
|
@ -48,14 +44,14 @@ pub fn create_png(image:&CZFile, out_name:&str) {
|
||||||
|
|
||||||
/// Utilities for decoding CZ0 images
|
/// Utilities for decoding CZ0 images
|
||||||
pub mod cz0 {
|
pub mod cz0 {
|
||||||
use std::io;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use image::DynamicImage;
|
|
||||||
use crate::utils::*;
|
|
||||||
use crate::cz_utils::{CZFile, HeaderCZ};
|
use crate::cz_utils::{CZFile, HeaderCZ};
|
||||||
|
use crate::utils::*;
|
||||||
|
use image::DynamicImage;
|
||||||
|
|
||||||
/// Extract all the header information from a CZ0 file
|
/// Extract all the header information from a CZ0 file
|
||||||
fn extract_header_cz0(header_vec: &Vec<u8>) -> (HeaderCZ, usize) {
|
fn extract_header_cz0(header_vec: &Vec<u8>) -> (HeaderCZ, usize) {
|
||||||
|
@ -132,7 +128,11 @@ pub mod cz0 {
|
||||||
/// Provided an image, extract the bitstream and create the
|
/// Provided an image, extract the bitstream and create the
|
||||||
/// header information from a previous CZ0 file in order to
|
/// header information from a previous CZ0 file in order to
|
||||||
/// replace it
|
/// replace it
|
||||||
pub fn encode_cz0(original_file:CZFile, input_image:DynamicImage, out_name:&str) -> io::Result<()> {
|
pub fn encode_cz0(
|
||||||
|
original_file: CZFile,
|
||||||
|
input_image: DynamicImage,
|
||||||
|
out_name: &str,
|
||||||
|
) -> io::Result<()> {
|
||||||
println!("");
|
println!("");
|
||||||
println!("--Beginning CZ0 Encode--");
|
println!("--Beginning CZ0 Encode--");
|
||||||
|
|
||||||
|
@ -161,22 +161,19 @@ pub mod cz0 {
|
||||||
&[0],
|
&[0],
|
||||||
&[header.length],
|
&[header.length],
|
||||||
&vec![0u8; 3],
|
&vec![0u8; 3],
|
||||||
|
|
||||||
&word_to_bytes(header.res.0),
|
&word_to_bytes(header.res.0),
|
||||||
&word_to_bytes(header.res.1),
|
&word_to_bytes(header.res.1),
|
||||||
&[header.depth],
|
&[header.depth],
|
||||||
|
|
||||||
&header.mystery,
|
&header.mystery,
|
||||||
&word_to_bytes(header.crop.0),
|
&word_to_bytes(header.crop.0),
|
||||||
&word_to_bytes(header.crop.1),
|
&word_to_bytes(header.crop.1),
|
||||||
|
|
||||||
&word_to_bytes(header.bounds.0),
|
&word_to_bytes(header.bounds.0),
|
||||||
&word_to_bytes(header.bounds.1),
|
&word_to_bytes(header.bounds.1),
|
||||||
|
|
||||||
&word_to_bytes(header.offset.0),
|
&word_to_bytes(header.offset.0),
|
||||||
&word_to_bytes(header.offset.1),
|
&word_to_bytes(header.offset.1),
|
||||||
&vec![0u8; 4],
|
&vec![0u8; 4],
|
||||||
].concat();
|
]
|
||||||
|
.concat();
|
||||||
|
|
||||||
println!("Trimming Header...");
|
println!("Trimming Header...");
|
||||||
// Cut off unnecessary information from the header
|
// Cut off unnecessary information from the header
|
||||||
|
@ -214,11 +211,23 @@ pub mod cz0 {
|
||||||
println!("Image size : {:.2} KB", image_size);
|
println!("Image size : {:.2} KB", image_size);
|
||||||
println!("Magic Bytes : {:?}", image.header.magic);
|
println!("Magic Bytes : {:?}", image.header.magic);
|
||||||
println!("Header Length : {:?} bytes", image.header.length);
|
println!("Header Length : {:?} bytes", image.header.length);
|
||||||
println!("Resolution : {}x{}", image.header.res.0, image.header.res.1);
|
println!(
|
||||||
|
"Resolution : {}x{}",
|
||||||
|
image.header.res.0, image.header.res.1
|
||||||
|
);
|
||||||
println!("Bit Depth : {} bits", image.header.depth);
|
println!("Bit Depth : {} bits", image.header.depth);
|
||||||
println!("Mystery Bytes : {:?}", image.header.mystery);
|
println!("Mystery Bytes : {:?}", image.header.mystery);
|
||||||
println!("Crop Coords : {}x{}", image.header.crop.0, image.header.crop.1);
|
println!(
|
||||||
println!("Bound Coords : {}x{}", image.header.bounds.0, image.header.bounds.1);
|
"Crop Coords : {}x{}",
|
||||||
println!("Offset Coords : {}x{}", image.header.offset.0, image.header.offset.1);
|
image.header.crop.0, image.header.crop.1
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"Bound Coords : {}x{}",
|
||||||
|
image.header.bounds.0, image.header.bounds.1
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"Offset Coords : {}x{}",
|
||||||
|
image.header.offset.0, image.header.offset.1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
pub mod utils;
|
|
||||||
pub mod cz_utils;
|
pub mod cz_utils;
|
||||||
use cz_utils::cz0::*;
|
pub mod utils;
|
||||||
use cz_utils::create_png;
|
use cz_utils::create_png;
|
||||||
|
use cz_utils::cz0::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let original_image = decode_cz0("../test_files/775.cz0");
|
let original_image = decode_cz0("../test_files/775.cz0");
|
||||||
let replacement_image = image::open("../test_files/blue.png").expect("Failed to open image file");
|
let replacement_image =
|
||||||
|
image::open("../test_files/blue.png").expect("Failed to open image file");
|
||||||
|
|
||||||
encode_cz0(original_image, replacement_image, "test.cz0").expect("Error encoding the image");
|
encode_cz0(original_image, replacement_image, "test.cz0").expect("Error encoding the image");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue