Support project conversion #27

Merged
jaby merged 9 commits from topic/jb/psyfileconv-tim-prj into main 2025-04-16 20:19:59 +00:00
22 changed files with 6008 additions and 145 deletions

View File

@ -5,3 +5,4 @@
*.o *.o
*.lba *.lba
**/bin **/bin
**/auto_gen

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "auto_gen/vram_layout.hpp"
#include <PSX/File/cd_file_types.hpp> #include <PSX/File/cd_file_types.hpp>
namespace Assets { namespace Assets {
@ -11,11 +12,6 @@ namespace Assets {
}; };
static constexpr auto PacoTIM = SimpleTIM::create(896, 0, 960, 510); static constexpr auto PacoTIM = SimpleTIM::create(896, 0, 960, 510);
static constexpr auto DoenerFishInfo = ImageInfo{
.tim = SimpleTIM::create(896 + 30, 0, 960 + 16, 510),
.size = GPU::SizeI16::create(128, 64)
};
namespace JabyLoader { namespace JabyLoader {
static constexpr auto TIMLoaction = SimpleTIM::create(PacoTIM.get_texture_x(), PacoTIM.get_texture_y() + 128, 960 + 48, 510); static constexpr auto TIMLoaction = SimpleTIM::create(PacoTIM.get_texture_x(), PacoTIM.get_texture_y() + 128, 960 + 48, 510);
static constexpr auto JabyFrame = GPU::AreaI16::create(0, 0, 32, 44); static constexpr auto JabyFrame = GPU::AreaI16::create(0, 0, 32, 44);

View File

@ -1,3 +1,4 @@
#include "../../../include/auto_gen/vram_layout.hpp"
#include "../../../include/shared.hpp" #include "../../../include/shared.hpp"
#include "include/controller_state.hpp" #include "include/controller_state.hpp"
#include <PSX/Periphery/periphery.hpp> #include <PSX/Periphery/periphery.hpp>

View File

@ -1,4 +1,4 @@
#include "include/controller_test_assets.hpp" #include "../../../include/auto_gen/vram_layout.hpp"
#include <PSX/File/Processor/cd_file_processor.hpp> #include <PSX/File/Processor/cd_file_processor.hpp>
#include <PSX/AutoLBA/auto_lba_declaration.hpp> #include <PSX/AutoLBA/auto_lba_declaration.hpp>
@ -13,6 +13,6 @@ namespace ControllerTest {
__declare_lba_header(LBA); __declare_lba_header(LBA);
CDFile Assets[1] = { CDFile Assets[1] = {
CDFileBuilder::simple_tim(LBA::CONT, ControllerButtonTIM), CDFileBuilder::simple_tim(LBA::CONT, Controller_png::tim),
}; };
} }

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "controller_test_assets.hpp" #include "../../../../include/auto_gen/vram_layout.hpp"
#include <FontWriter/font_writer.hpp> #include <FontWriter/font_writer.hpp>
#include <PSX/GPU/make_gpu_primitives.hpp> #include <PSX/GPU/make_gpu_primitives.hpp>
#include <PSX/Periphery/controller.hpp> #include <PSX/Periphery/controller.hpp>
@ -18,43 +18,43 @@ namespace ControllerTest {
ControllerState state; ControllerState state;
for(auto& tex_page : state.tex_page) { for(auto& tex_page : state.tex_page) {
tex_page = Make::TexPage(ControllerButtonTIM.get_texture_position(), GPU::TextureColorMode::clut4).linked(); tex_page = Make::TexPage(Controller_png::tim.get_texture_position(), GPU::TextureColorMode::clut4).linked();
} }
for(auto& buttons : state.buttons) { for(auto& buttons : state.buttons) {
// Triangle // Triangle
buttons[0] = Make::SPRT_16(Make::Vertex(71, 0).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(0, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[0] = Make::SPRT_16(Make::Vertex(71, 0).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(0, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// Circle // Circle
buttons[1] = Make::SPRT_16(Make::Vertex(82, 12).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(1, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[1] = Make::SPRT_16(Make::Vertex(82, 12).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(1, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// Cross // Cross
buttons[2] = Make::SPRT_16(Make::Vertex(71, 23).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(2, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[2] = Make::SPRT_16(Make::Vertex(71, 23).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(2, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// Square // Square
buttons[3] = Make::SPRT_16(Make::Vertex(60, 11).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(3, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[3] = Make::SPRT_16(Make::Vertex(60, 11).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(3, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// Play // Play
buttons[4] = Make::SPRT_16(Make::Vertex(51, 21).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(4, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[4] = Make::SPRT_16(Make::Vertex(51, 21).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(4, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// Block // Block
buttons[5] = Make::SPRT_16(Make::Vertex(24, 21).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(5, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[5] = Make::SPRT_16(Make::Vertex(24, 21).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(5, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// L1 // L1
buttons[6] = Make::SPRT_16(Make::Vertex(7, 39).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(7, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[6] = Make::SPRT_16(Make::Vertex(7, 39).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(7, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// L2 // L2
buttons[7] = Make::SPRT_16(Make::Vertex(7, 49).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(8, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[7] = Make::SPRT_16(Make::Vertex(7, 49).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(8, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// R1 // R1
buttons[8] = Make::SPRT_16(Make::Vertex(71, 39).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(7, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[8] = Make::SPRT_16(Make::Vertex(71, 39).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(7, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// R2 // R2
buttons[9] = Make::SPRT_16(Make::Vertex(71, 49).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(8, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[9] = Make::SPRT_16(Make::Vertex(71, 49).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(8, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// L3 // L3
buttons[10] = Make::SPRT_16(Make::Vertex(24, 34).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(9, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[10] = Make::SPRT_16(Make::Vertex(24, 34).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(9, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// R3 // R3
buttons[11] = Make::SPRT_16(Make::Vertex(52, 34).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(9, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[11] = Make::SPRT_16(Make::Vertex(52, 34).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(9, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
// Connection Symbol // Connection Symbol
buttons[12] = Make::SPRT_16(Make::Vertex(37, 9).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(10, Make::SizeI16(16, 16)), Make::PageClut(ControllerButtonTIM.get_clut_position()))).linked(); buttons[12] = Make::SPRT_16(Make::Vertex(37, 9).move(offset.x, offset.y), Make::OffsetPageWithClut(GPU::PageOffset::from_tile_id16(10, Make::SizeI16(16, 16)), Make::PageClut(Controller_png::tim.get_clut_position()))).linked();
} }
for(auto& arrows : state.arrows) { for(auto& arrows : state.arrows) {
arrows[0] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect( Make::AreaI16(Make::PositionI16( 7, 5).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(ControllerButtonTIM.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(ControllerButtonTIM.get_clut_position())).linked(); arrows[0] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect( Make::AreaI16(Make::PositionI16( 7, 5).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(Controller_png::tim.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(Controller_png::tim.get_clut_position())).linked();
arrows[1] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect270(Make::AreaI16(Make::PositionI16(14, 11).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(ControllerButtonTIM.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(ControllerButtonTIM.get_clut_position())).linked(); arrows[1] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect270(Make::AreaI16(Make::PositionI16(14, 11).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(Controller_png::tim.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(Controller_png::tim.get_clut_position())).linked();
arrows[2] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect180(Make::AreaI16(Make::PositionI16( 7, 17).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(ControllerButtonTIM.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(ControllerButtonTIM.get_clut_position())).linked(); arrows[2] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect180(Make::AreaI16(Make::PositionI16( 7, 17).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(Controller_png::tim.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(Controller_png::tim.get_clut_position())).linked();
arrows[3] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect90( Make::AreaI16(Make::PositionI16( 0, 11).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(ControllerButtonTIM.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(ControllerButtonTIM.get_clut_position())).linked(); arrows[3] = Make::POLY_FT4(__jabyengine_polyFT4_vertex_rect90( Make::AreaI16(Make::PositionI16( 0, 11).move(offset.x, offset.y), Make::SizeI16(16, 16)), Make::PositionI16(6*16, 0)), Make::TPage(Controller_png::tim.get_texture_position(), GPU::SemiTransparency::B_Half_add_F_Half, GPU::TextureColorMode::clut4), Make::PageClut(Controller_png::tim.get_clut_position())).linked();
} }
return state; return state;

View File

@ -1,8 +0,0 @@
#pragma once
#include <PSX/File/cd_file_types.hpp>
namespace ControllerTest {
using namespace JabyEngine;
static constexpr auto ControllerButtonTIM = SimpleTIM::create(384, 0, 384, 511);
}

View File

@ -86,10 +86,10 @@ namespace GTETest {
} }
static auto doener_fish = GTE_Sprite::create(Make::POLY_FT4( static auto doener_fish = GTE_Sprite::create(Make::POLY_FT4(
Make::AreaI16(Make::PositionI16(0, 0), Assets::Main::DoenerFishInfo.size), Make::AreaI16(Make::PositionI16(0, 0), doener_fish_png::size),
Assets::Main::DoenerFishInfo.tim.get_page_offset_clut4(), doener_fish_png::tim.get_page_offset_clut4(),
Make::TPage(Assets::Main::DoenerFishInfo.tim.get_texture_position(), GPU::SemiTransparency::B_add_F, GPU::TextureColorMode::clut4), Make::TPage(doener_fish_png::tim.get_texture_position(), GPU::SemiTransparency::B_add_F, GPU::TextureColorMode::clut4),
Make::PageClut(Assets::Main::DoenerFishInfo.tim.get_clut_position()), Make::PageClut(doener_fish_png::tim.get_clut_position()),
GPU::Color24::Grey() GPU::Color24::Grey()
).linked()); ).linked());

View File

@ -6,8 +6,8 @@ namespace GTETest {
using namespace JabyEngine; using namespace JabyEngine;
static constexpr auto JabySTARTim = SimpleTIM::create( static constexpr auto JabySTARTim = SimpleTIM::create(
// v Doenerfisch rotates so we need some space // v Dönerfisch rotates so we need some space
Assets::Main::DoenerFishInfo.tim.get_texture_x(), Assets::Main::DoenerFishInfo.tim.get_texture_y() + Assets::Main::DoenerFishInfo.size.height + 2, doener_fish_png::tim.get_texture_x(), doener_fish_png::tim.get_texture_y() + doener_fish_png::size.height + 2,
Assets::Main::DoenerFishInfo.tim.get_clut_x() + 16, Assets::Main::DoenerFishInfo.tim.get_clut_y() doener_fish_png::tim.get_clut_x() + 16, doener_fish_png::tim.get_clut_y()
); );
} }

View File

@ -108,8 +108,9 @@ static const Menu::SimpleMenu::Entry MenuEntries[] = {
}; };
static const auto doener_fish = Make::SPRT( static const auto doener_fish = Make::SPRT(
Make::AreaI16(Make::PositionI16(8, GPU::Display::Height - Assets::Main::DoenerFishInfo.size.height), Assets::Main::DoenerFishInfo.size), // v this needs to be nicer! Has to be Make::AreaI16(Make::PositionI16(8, GPU::Display::Height - doener_fish_png::size.height), doener_fish_png::size),
Make::OffsetPageWithClut(Assets::Main::DoenerFishInfo.tim.get_page_offset_clut4(), Make::PageClut(Assets::Main::DoenerFishInfo.tim.get_clut_position())), // v this needs to be nicer! Has to be
Make::OffsetPageWithClut(doener_fish_png::tim.get_page_offset_clut4(), Make::PageClut(doener_fish_png::tim.get_clut_position())),
GPU::Color24::Grey() GPU::Color24::Grey()
); );

View File

@ -68,7 +68,7 @@ namespace Assets {
static const CDFile Files[] = { static const CDFile Files[] = {
CDFileBuilder::simple_tim(LBA::PACO, PacoTIM), CDFileBuilder::simple_tim(LBA::PACO, PacoTIM),
CDFileBuilder::simple_tim(LBA::DFISH, DoenerFishInfo.tim), CDFileBuilder::simple_tim(LBA::DFISH, doener_fish_png::tim),
CDFileBuilder::simple_tim(LBA::JABY_LOAD, JabyLoader::TIMLoaction), CDFileBuilder::simple_tim(LBA::JABY_LOAD, JabyLoader::TIMLoaction),
CDFileBuilder::sony_vag(LBA::APPLE_SFX, VAG::create(0, 1.0_vol)), CDFileBuilder::sony_vag(LBA::APPLE_SFX, VAG::create(0, 1.0_vol)),
CDFileBuilder::sony_vag(LBA::BLUBB_SFX, VAG::create(1, 1.0_vol)), CDFileBuilder::sony_vag(LBA::BLUBB_SFX, VAG::create(1, 1.0_vol)),

View File

@ -2,6 +2,7 @@ include $(JABY_ENGINE_DIR)/mkfile/common/ExportPath.mk
include $(JABY_ENGINE_DIR)/mkfile/common/RebuildTarget.mk include $(JABY_ENGINE_DIR)/mkfile/common/RebuildTarget.mk
OUTPUT_DIR = bin OUTPUT_DIR = bin
AUTO_GEN_DIR = ../application/include/auto_gen
CLUT_4_COLOR_TRANS_FLAGS = simple-tim clut4 --color-trans CLUT_4_COLOR_TRANS_FLAGS = simple-tim clut4 --color-trans
# Ressources to convert # Ressources to convert
@ -22,12 +23,6 @@ IconTexture_FLAGS = simple-tim clut4 --semi-trans --color-trans
INPUT += $(OUTPUT_DIR)/Paco.img INPUT += $(OUTPUT_DIR)/Paco.img
Paco_FLAGS = $(CLUT_4_COLOR_TRANS_FLAGS) Paco_FLAGS = $(CLUT_4_COLOR_TRANS_FLAGS)
INPUT += $(OUTPUT_DIR)/Controller.img
Controller_FLAGS = $(CLUT_4_COLOR_TRANS_FLAGS)
INPUT += $(OUTPUT_DIR)/doener_fish.img
doener_fish_FLAGS = $(CLUT_4_COLOR_TRANS_FLAGS)
INPUT += $(OUTPUT_DIR)/JabyStar.img INPUT += $(OUTPUT_DIR)/JabyStar.img
JabyStar_FLAGS = $(CLUT_4_COLOR_TRANS_FLAGS) JabyStar_FLAGS = $(CLUT_4_COLOR_TRANS_FLAGS)
@ -60,7 +55,12 @@ $(OUTPUT_DIR)/%.tim: %.png
@mkdir -p $(OUTPUT_DIR) @mkdir -p $(OUTPUT_DIR)
psxfileconv --lz4 $< -o $@ $($*_TIM_FLAGS) psxfileconv --lz4 $< -o $@ $($*_TIM_FLAGS)
all: $(INPUT) $(AUTO_GEN_DIR)/vram_layout.hpp: tim_example.tim_project Controller.png doener_fish.png
@mkdir -p $(AUTO_GEN_DIR)
psxfileconv tim_example.tim_project -o $(OUTPUT_DIR)/dummy.img project --hpp $(AUTO_GEN_DIR)/vram_layout.hpp
all: $(INPUT) $(AUTO_GEN_DIR)/vram_layout.hpp
clean: clean:
rm -fr $(OUTPUT_DIR) rm -fr $(OUTPUT_DIR)
rm -fr $(AUTO_GEN_DIR)

View File

@ -0,0 +1 @@
{"jobs":[{"name":"doener_fish.png","file_path":"doener_fish.png","image_pos":{"x":926,"y":0},"palette_rect":{"pos":{"x":976,"y":510},"size":{"width":16,"height":1}},"settings":{"compress":true,"transparency":"FirstColor","encoding":"FourBit"}},{"name":"Controller.png","file_path":"Controller.png","image_pos":{"x":384,"y":0},"palette_rect":{"pos":{"x":384,"y":511},"size":{"width":16,"height":1}},"settings":{"compress":true,"transparency":"FirstColor","encoding":"FourBit"}}]}

File diff suppressed because it is too large Load Diff

View File

@ -28,11 +28,15 @@ symphonia-vorbis = ["symphonia", "symphonia/vorbis"]
[dependencies] [dependencies]
bitflags = "2.8.0" bitflags = "2.8.0"
cdtypes = {path = "../cdtypes"} cdtypes = {path = "../cdtypes"}
cpp_out = {path = "../cpp_out"}
clap = {version = "4.5.27", features = ["derive"]} clap = {version = "4.5.27", features = ["derive"]}
image = "0.24.9" image = "0.24.9"
hound = "3.5.1" hound = "3.5.1"
paste = "1.0.15" paste = "1.0.15"
png = "0.17.16" png = "0.17.16"
rubato = "0.16.1" rubato = "0.16.1"
serde = {version = "1.0.219", features = ["derive"]}
serde_json = "1.0"
symphonia = {version = "0.5.4", optional = true, default-features = false} symphonia = {version = "0.5.4", optional = true, default-features = false}
tim_tool = {path = "../tim_tool"}
tool_helper = {path = "../tool_helper"} tool_helper = {path = "../tool_helper"}

View File

@ -36,7 +36,8 @@ fn modify_palette(mut image: IndexedImage, clut_align: ClutAlignment, semi_trans
image image
} }
fn encode<T: PSXImageConverter>(header_conv: &mut dyn HeaderEncoder, image: T, tex_pos: Point, clut_pos: Point, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> { fn encode<T: PSXImageConverter>(header_conv: &mut dyn HeaderEncoder, image: T, tex_pos: Point, clut_pos: Point, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(u16, u16), Error> {
let image_size = (image.width(), image.height());
let (width, height) = { let (width, height) = {
fn return_error(clut_type: u32, div: u32, width: u16, height: u16) -> Result<(u16, u16), Error> { fn return_error(clut_type: u32, div: u32, width: u16, height: u16) -> Result<(u16, u16), Error> {
return Err(Error::from_callback(|| {format!("CLUT {} images require a width divideable by {} (found width: {}/{}={}, height: {})", clut_type, div, width, div, (width as f32/div as f32), height)})); return Err(Error::from_callback(|| {format!("CLUT {} images require a width divideable by {} (found width: {}/{}={}, height: {})", clut_type, div, width, div, (width as f32/div as f32), height)}));
@ -115,10 +116,10 @@ fn encode<T: PSXImageConverter>(header_conv: &mut dyn HeaderEncoder, image: T, t
tool_helper::raw::write_raw(output, &color)?; tool_helper::raw::write_raw(output, &color)?;
} }
Ok(()) Ok(image_size)
} }
fn convert_full16(header_conv: &mut dyn HeaderEncoder, input: Input, output: &mut dyn Write, tex_pos: Point) -> Result<(), Error> { fn convert_full16(header_conv: &mut dyn HeaderEncoder, input: Input, output: &mut dyn Write, tex_pos: Point) -> Result<(u16, u16), Error> {
match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() { match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() {
Ok(image) => { Ok(image) => {
match image { match image {
@ -132,7 +133,7 @@ fn convert_full16(header_conv: &mut dyn HeaderEncoder, input: Input, output: &mu
} }
} }
fn convert_palette_based(header_conv: &mut dyn HeaderEncoder, input: Input, output: &mut dyn Write, tex_pos: Point, clut_pos: Point, color_type: ColorType, clut_align: ClutAlignment, semi_transparent: bool, transparent_palette: bool) -> Result<(), Error> { fn convert_palette_based(header_conv: &mut dyn HeaderEncoder, input: Input, output: &mut dyn Write, tex_pos: Point, clut_pos: Point, color_type: ColorType, clut_align: ClutAlignment, semi_transparent: bool, transparent_palette: bool) -> Result<(u16, u16), Error> {
match png::Decoder::new(input).read_info() { match png::Decoder::new(input).read_info() {
Ok(reader) => { Ok(reader) => {
let output_type = { let output_type = {

View File

@ -7,7 +7,7 @@ use tool_helper::{Error, Input};
pub type Arguments = super::args::Arguments; pub type Arguments = super::args::Arguments;
pub fn convert(args: Arguments, input: Input, output: &mut dyn Write) -> Result<(), Error> { pub fn convert(args: Arguments, input: Input, output: &mut dyn Write) -> Result<(u16, u16), Error> {
let mut header_conv = Header::default(); let mut header_conv = Header::default();
match args.color_depth { match args.color_depth {
ColorType::Full16 => super::convert_full16(&mut header_conv, input, output, Point::default()), ColorType::Full16 => super::convert_full16(&mut header_conv, input, output, Point::default()),

View File

@ -9,16 +9,16 @@ use tool_helper::{Error, Input};
#[derive(Args)] #[derive(Args)]
pub struct Arguments { pub struct Arguments {
#[clap(flatten)] #[clap(flatten)]
global: super::args::Arguments, pub(crate) global: super::args::Arguments,
#[clap(long, value_parser, default_value_t, value_name = Point::POINT_VALUE_NAME)] #[clap(long, value_parser, default_value_t, value_name = Point::POINT_VALUE_NAME)]
clut_pos: Point, pub(crate) clut_pos: Point,
#[clap(long, value_parser, default_value_t, value_name = Point::POINT_VALUE_NAME)] #[clap(long, value_parser, default_value_t, value_name = Point::POINT_VALUE_NAME)]
tex_pos: Point, pub(crate) tex_pos: Point,
} }
pub fn convert(args: Arguments, input: Input, output: &mut dyn Write) -> Result<(), Error> { pub fn convert(args: Arguments, input: Input, output: &mut dyn Write) -> Result<(u16, u16), Error> {
let global_args = args.global; let global_args = args.global;
let mut header_conv = Header::default(); let mut header_conv = Header::default();

View File

@ -1,3 +1,88 @@
pub mod audio; pub mod audio;
pub mod images; pub mod images;
pub mod nothing; pub mod nothing;
pub mod project;
use crate::audio::*;
use crate::images::*;
use clap::Subcommand;
use std::path::PathBuf;
use tool_helper::Error;
#[derive(Subcommand)]
pub enum SubCommands {
Nothing,
SimpleTIM(reduced_tim::Arguments),
TIM(tim::Arguments),
VAG(vag::Arguments),
XA(xa::Arguments),
Project(project::Arguments),
}
pub fn run_subcommand(compress_lz4: bool, input_path: Option<PathBuf>, output_path: Option<PathBuf>, sub_command: SubCommands) -> Result<Option<(u16, u16)>, Error> {
let mut input = tool_helper::open_input(&input_path)?;
let mut buffer = Vec::<u8>::new();
let mut output_file = tool_helper::open_output(&output_path)?;
let dst_buffer = {
if compress_lz4 {
&mut buffer as &mut dyn std::io::Write
}
else {
&mut output_file as &mut dyn std::io::Write
}
};
let cmd_result: Result<Option<(u16, u16)>, Error> = {
match sub_command {
SubCommands::Nothing => {
nothing::copy(&mut input, dst_buffer)?;
Ok(None)
},
SubCommands::SimpleTIM(args) => {
Ok(Some(reduced_tim::convert(args, input, dst_buffer)?))
},
SubCommands::TIM(args) => {
Ok(Some(tim::convert(args, input, dst_buffer)?))
},
SubCommands::VAG(args) => {
audio::vag::convert(args, &output_path, input, dst_buffer)?;
Ok(None)
}
SubCommands::XA(args) => {
audio::xa::convert(args, input, dst_buffer)?;
Ok(None)
}
SubCommands::Project(args) => {
project::run_project(input, args, input_path, &output_path)?;
if let Some(file_path) = &output_path {
let _result = std::fs::remove_file(file_path);
}
Ok(None)
},
}
};
match cmd_result {
Ok(cmd_result) => {
// We encoded the file to a temporary buffer and now need to write it
if compress_lz4 {
let buffer = tool_helper::compress::psx_default::lz4(&buffer)?;
output_file.write(&buffer)?;
}
Ok(cmd_result)
}
Err(cmd_error) => {
if let Some(file_path) = output_path {
let _result = std::fs::remove_file(file_path);
}
else {
tool_helper::print_warning("Open stream detected! Incomplete file can not be deleted".to_owned());
}
Err(cmd_error)
}
}
}

View File

@ -1,11 +1,11 @@
use clap::{Parser, Subcommand}; use clap::Parser;
use psxfileconv::{audio::{self, *}, images::*, nothing};
use std::path::PathBuf; use std::path::PathBuf;
use tool_helper::{exit_with_error, Error}; use psxfileconv::{SubCommands, run_subcommand};
use tool_helper::exit_with_error;
#[derive(Parser)] #[derive(Parser)]
#[clap(about = "Converts files to various JabyEngine related file formats", long_about = None)] #[clap(about = "Converts files to various JabyEngine related file formats", long_about = None)]
struct CommandLine { pub struct CommandLine {
#[clap(long="lz4", default_value_t=false)] #[clap(long="lz4", default_value_t=false)]
compress_lz4: bool, compress_lz4: bool,
@ -19,64 +19,10 @@ struct CommandLine {
sub_command: SubCommands, sub_command: SubCommands,
} }
#[derive(Subcommand)]
enum SubCommands {
Nothing,
SimpleTIM(reduced_tim::Arguments),
TIM(tim::Arguments),
VAG(vag::Arguments),
XA(xa::Arguments),
}
fn run_main(cmd: CommandLine) -> Result<(), Error> {
let mut input = tool_helper::open_input(&cmd.input_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
}
};
let cmd_result: Result<(), Error> = {
match cmd.sub_command {
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer),
SubCommands::TIM(args) => tim::convert(args, input, dst_buffer),
SubCommands::VAG(args) => audio::vag::convert(args, &cmd.output_file, input, dst_buffer),
SubCommands::XA(args) => audio::xa::convert(args, input, dst_buffer),
}
};
if let Err(cmd_error) = cmd_result {
if let Some(file_path) = cmd.output_file {
let _result = std::fs::remove_file(file_path);
}
else {
tool_helper::print_warning("Open stream detected! Incomplete file can not be deleted".to_owned());
}
return Err(cmd_error);
}
// We encoded the file to a temporary buffer and now need to write it
if cmd.compress_lz4 {
let buffer = tool_helper::compress::psx_default::lz4(&buffer)?;
output_file.write(&buffer)?;
}
Ok(())
}
fn main() { fn main() {
match CommandLine::try_parse() { match CommandLine::try_parse() {
Ok(cmd) => { Ok(cmd) => {
if let Err(error) = run_main(cmd) { if let Err(error) = run_subcommand(cmd.compress_lz4, cmd.input_file, cmd.output_file, cmd.sub_command) {
exit_with_error(error); exit_with_error(error);
} }
}, },

View File

@ -0,0 +1,39 @@
use std::path::PathBuf;
use tim_tool::logic::project::Job;
use tool_helper::{Error, Output};
pub struct CppHeader {
file_out: Output,
}
impl CppHeader {
pub fn new(file_path: &Option<PathBuf>) -> Result<CppHeader, Error> {
let mut file_out = tool_helper::open_output(file_path)?;
writeln!(file_out, "#pragma once")?;
writeln!(file_out, "#include <PSX/File/cd_file_types.hpp>")?;
writeln!(file_out, "")?;
Ok(CppHeader{file_out})
}
pub fn push_job(&mut self, job: &Job, size: (u16, u16)) -> Result<(), Error> {
let name = job.name.replace('.', "_");
let (clut_x, clut_y) = if let Some(palette_rect) = &job.palette_rect {(palette_rect.pos.x, palette_rect.pos.y)} else {(0, 0)};
writeln!(self.file_out, "namespace {} {{", name)?;
writeln!(self.file_out, "\tusing namespace JabyEngine;")?;
writeln!(self.file_out, "")?;
writeln!(self.file_out, "\tstatic constexpr auto tim = SimpleTIM::create({}, {}, {}, {});", job.image_pos.x, job.image_pos.y, clut_x, clut_y)?;
writeln!(self.file_out, "\tstatic constexpr auto size = GPU::SizeI16::create({}, {});", size.0, size.1)?;
writeln!(self.file_out, "}}")?;
Ok(())
}
}
impl Drop for CppHeader {
fn drop(&mut self) {
}
}

View File

@ -0,0 +1,90 @@
mod hpp_out;
use crate::images::args::{Arguments as IMGArguments, ClutAlignment, ColorType};
use clap::Args;
use hpp_out::CppHeader;
use std::path::PathBuf;
use tool_helper::{Error, Input};
use tim_tool::logic::{tim::types::Encoding, project::*};
#[derive(Args)]
pub struct Arguments {
#[clap(long="hpp", value_parser)]
hpp_out_path: Option<PathBuf>
}
pub fn run_project(input: Input, args: Arguments, input_path: Option<PathBuf>, output_path: &Option<PathBuf>) -> Result<(), Error> {
let location_path = if let Some(input_path) = input_path {input_path} else {PathBuf::from(".")};
let output_path = if let Some(output_path) = &output_path {
let mut output_path = output_path.clone();
if output_path.is_file() {
output_path.pop();
}
output_path
} else {PathBuf::from(".")};
let project = serde_json::from_reader::<Input, Project>(input).map_err(|error|{Error::from_text(format!("Reading project failed: {}", error))})?;
let mut hpp_out = CppHeader::new(&args.hpp_out_path)?;
for mut job in project.jobs {
let args = to_arguments(&job)?;
let output_path = {
let mut path = output_path.clone();
path.push(&job.name);
path.set_extension("img");
path
};
let sub_command = crate::SubCommands::SimpleTIM(args);
let org_img_size = crate::run_subcommand(job.settings.compress, Some(Job::create_file_path(job.file_path, &location_path)), Some(output_path), sub_command)?;
job.file_path = PathBuf::new();
hpp_out.push_job(&job, org_img_size.unwrap_or((0, 0)))?;
}
Ok(())
}
fn to_arguments(job: &Job) -> Result<IMGArguments, Error> {
let (semi_transparent, transparent_palette) = get_transparency(&job.settings.transparency);
return Ok(IMGArguments {
color_depth: get_encoding(&job.settings.encoding),
clut_align: get_palette_rect(&job.palette_rect)?,
semi_transparent,
transparent_palette,
});
fn get_transparency(transparency: &Transparency) -> (bool, bool) {
match transparency {
Transparency::None => (false, false),
Transparency::FirstColor => (false, true),
Transparency::PSXSemi => (true, false),
Transparency::Both => (true, true),
}
}
fn get_encoding(encoding: &Encoding) -> ColorType {
match encoding {
Encoding::FourBit => ColorType::Clut4,
Encoding::EightBit => ColorType::Clut8,
Encoding::FullColor => ColorType::Full16,
}
}
fn get_palette_rect(rect: &Option<PaletteRect>) -> Result<ClutAlignment, Error> {
if let Some(rect) = rect {
if rect.size.height == 1 {
return Ok(ClutAlignment::Linear);
}
if rect.size.width%16 == 0 {
return Ok(ClutAlignment::Block);
}
return Err(Error::from_text(format!("psxfileconv currently only supports linear or block CLUTs with a width of 16px")));
}
Ok(ClutAlignment::None)
}
}