Make jaby_engine_fconv output lz4 files on request
This commit is contained in:
parent
3b014b4c75
commit
09195f9093
|
@ -1,10 +1,10 @@
|
|||
export PATH := $(HOME)/.cargo/bin/:$(PATH)
|
||||
|
||||
test_cpp_out: always
|
||||
@echo "Planschbecken" | ./../cpp_out/target/x86_64-unknown-linux-musl/release/cpp_out --name Dino -o "Test_Planschbecken.cpp"
|
||||
@echo "Planschbecken" | ./../cpp_out/target/x86_64-unknown-linux-musl/release/cpp_out --name Dino -o "Test_Planschbecken.hpp"
|
||||
@echo "Planschbecken" | ./../cpp_out/target/x86_64-unknown-linux-gnu/release/cpp_out --name Dino -o "Test_Planschbecken.cpp"
|
||||
@echo "Planschbecken" | ./../cpp_out/target/x86_64-unknown-linux-gnu/release/cpp_out --name Dino -o "Test_Planschbecken.hpp"
|
||||
|
||||
test_jaby_engine_fconv: always
|
||||
# @./../jaby_engine_fconv/target/x86_64-unknown-linux-musl/release/jaby_engine_fconv -o Test_Planschi.bin Test_PNG.PNG simple-tim full16
|
||||
@./../jaby_engine_fconv/target/x86_64-unknown-linux-musl/release/jaby_engine_fconv -o Test_Planschi.bin Test_PNG_pal.PNG simple-tim clut8
|
||||
@./../jaby_engine_fconv/target/x86_64-unknown-linux-gnu/release/jaby_engine_fconv --lz4 -o Test_Planschi.bin ../../Library/ressources/Splash.PNG simple-tim full16
|
||||
always: ;
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "jaby_engine_fconv"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -2,8 +2,8 @@ use clap::{Args, ValueEnum};
|
|||
use image::{DynamicImage, io::Reader as ImageReader};
|
||||
use color_clut::IndexedImage;
|
||||
use color_full16::{RgbaImage, RgbImage};
|
||||
use std::io::Cursor;
|
||||
use tool_helper::{Error, Input, Output};
|
||||
use std::io::{Cursor, Write};
|
||||
use tool_helper::{Error, Input};
|
||||
use types::{Header, Color as PSXColor, PSXImageConverter};
|
||||
|
||||
mod types;
|
||||
|
@ -33,7 +33,7 @@ pub struct Arguments {
|
|||
clut_align: ClutAlignment
|
||||
}
|
||||
|
||||
fn encode<T: PSXImageConverter>(image: T, clut_align: ClutAlignment, mut output: Output) -> Result<(), Error> {
|
||||
fn encode<T: PSXImageConverter>(image: T, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> {
|
||||
let width = image.width();
|
||||
let height = image.height();
|
||||
let palette = image.get_palette();
|
||||
|
@ -53,28 +53,28 @@ fn encode<T: PSXImageConverter>(image: T, clut_align: ClutAlignment, mut output:
|
|||
|
||||
let header = Header::encode(width, height, pal_width, pal_height).ok_or(Error::from_callback(|| {format!("Image size (width: {}, height: {}) needs to be even", width, height)}))?;
|
||||
|
||||
tool_helper::raw::write_generic(&mut output, header)?;
|
||||
tool_helper::raw::write_generic(output, header)?;
|
||||
if let Some(palette) = palette {
|
||||
let mut color_count = pal_width*pal_height;
|
||||
for color in palette {
|
||||
tool_helper::raw::write_generic(&mut output, color)?;
|
||||
tool_helper::raw::write_generic(output, color)?;
|
||||
color_count -= 1;
|
||||
}
|
||||
|
||||
while color_count > 0 {
|
||||
tool_helper::raw::write_generic(&mut output, PSXColor::black())?;
|
||||
tool_helper::raw::write_generic(output, PSXColor::black())?;
|
||||
color_count -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
for color in image {
|
||||
tool_helper::raw::write_generic(&mut output, color)?;
|
||||
tool_helper::raw::write_generic(output, color)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
|
||||
fn convert_full16(input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||
match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() {
|
||||
Ok(image) => {
|
||||
match image {
|
||||
|
@ -88,7 +88,7 @@ fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_palette_based(input: Input, output: Output, color_type: ColorType, clut_align: ClutAlignment) -> Result<(), Error> {
|
||||
fn convert_palette_based(input: Input, output: &mut dyn Write, color_type: ColorType, clut_align: ClutAlignment) -> Result<(), Error> {
|
||||
match png::Decoder::new(input).read_info() {
|
||||
Ok(reader) => {
|
||||
let output_type = {
|
||||
|
@ -104,7 +104,7 @@ fn convert_palette_based(input: Input, output: Output, color_type: ColorType, cl
|
|||
}
|
||||
}
|
||||
|
||||
pub fn convert(args: Arguments, input: Input, output: Output) -> Result<(), Error> {
|
||||
pub fn convert(args: Arguments, input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||
match args.color_depth {
|
||||
ColorType::Full16 => convert_full16(input, output),
|
||||
_ => convert_palette_based(input, output, args.color_depth, args.clut_align),
|
||||
|
|
|
@ -6,6 +6,9 @@ use tool_helper::Error;
|
|||
#[derive(Parser)]
|
||||
#[clap(about = "Converts files to various JabyEngine related file formats", long_about = None)]
|
||||
struct CommandLine {
|
||||
#[clap(long="lz4", default_value_t=false)]
|
||||
compress_lz4: bool,
|
||||
|
||||
#[clap(short='o')]
|
||||
output_file: Option<PathBuf>,
|
||||
|
||||
|
@ -25,13 +28,41 @@ fn run_main() -> Result<(), Error> {
|
|||
match CommandLine::try_parse() {
|
||||
Ok(cmd) => {
|
||||
let input = tool_helper::open_input(cmd.input_file)?;
|
||||
let output = tool_helper::open_output(cmd.output_file)?;
|
||||
let mut buffer = Vec::<u8>::new();
|
||||
let mut output_file = tool_helper::open_output(cmd.output_file)?;
|
||||
let dst_buffer = {
|
||||
if cmd.compress_lz4 {
|
||||
&mut buffer as &mut dyn std::io::Write
|
||||
}
|
||||
|
||||
else {
|
||||
&mut output_file as &mut dyn std::io::Write
|
||||
}
|
||||
};
|
||||
|
||||
match cmd.sub_command {
|
||||
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, output),
|
||||
SubCommands::SimpleTIM(args) => {
|
||||
reduced_tim::convert(args, input, dst_buffer)?;
|
||||
}
|
||||
}
|
||||
|
||||
// We encoded the file to a temporary buffer and now need to write it
|
||||
if cmd.compress_lz4 {
|
||||
println!("Buffer-Size: {} ({} Sectors)", buffer.len(), (buffer.len() + 2047)/2048);
|
||||
let buffer = tool_helper::compress::lz4(&buffer, 16)?;
|
||||
println!("New buffer-Size: {} ({} Sectors)", buffer.len(), (buffer.len() + 2047)/2048);
|
||||
|
||||
output_file.write(&buffer)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
Err(error) => Err(Error::from_error(error))
|
||||
Err(error) => Err({
|
||||
let mut error = Error::from_error(error);
|
||||
|
||||
error.exit_code = 0;
|
||||
error
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::{Error, Output};
|
||||
use super::{Error, Write};
|
||||
|
||||
pub fn write_generic<T>(output: &mut Output, value: T) -> Result<usize, Error> {
|
||||
pub fn write_generic<T>(output: &mut dyn Write, value: T) -> Result<usize, Error> {
|
||||
let raw = unsafe {std::slice::from_raw_parts(&value as *const _ as *const u8, std::mem::size_of_val(&value))};
|
||||
|
||||
Error::try_or_new(output.write(raw))
|
||||
|
|
Loading…
Reference in New Issue