Fix image conversion and CLUT placement

This commit is contained in:
Jaby 2023-05-01 22:37:41 +02:00
parent b758d7528e
commit de4ba5e1f3
6 changed files with 50 additions and 24 deletions

View File

@ -1,6 +1,7 @@
#ifndef __JABYENGINE_FILE_TYPES_HPP__
#define __JABYENGINE_FILE_TYPES_HPP__
#include "../Auxiliary/bits.hpp"
#include "../GPU/gpu_types.hpp"
#include "../jabyengine_defines.h"
namespace JabyEngine {
@ -19,24 +20,32 @@ namespace JabyEngine {
this->raw = 0;
}
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : raw(TextureX.as_value(texX >> 1) | TextureY.as_value(texY >> 1) | ClutX.as_value(clutX >> 4) | ClutY.as_value(clutY)) {
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : raw(TextureX.as_value(texX >> 1) | TextureY.as_value(texY >> 1) | ClutX.as_value(clutX >> 4) | ClutY.as_value(static_cast<uint32_t>(clutY))) {
}
constexpr uint16_t getTextureX() const {
constexpr uint16_t get_texture_x() const {
return bit::value::get_normalized(this->raw, TextureX) << 1;
}
constexpr uint16_t getTextureY() const {
constexpr uint16_t get_texture_y() const {
return bit::value::get_normalized(this->raw, TextureY) << 1;
}
constexpr uint16_t getClutX() const {
constexpr GPU::PositionU16 get_texture_position() const {
return {SimpleTIM::get_texture_x(), SimpleTIM::get_texture_y()};
}
constexpr uint16_t get_clut_x() const {
return bit::value::get_normalized(this->raw, SimpleTIM::ClutX) << 4;
}
constexpr uint16_t getClutY() const {
constexpr uint16_t get_clut_y() const {
return bit::value::get_normalized(this->raw, ClutY);
}
constexpr GPU::PositionU16 get_clut_position() const {
return {SimpleTIM::get_clut_x(), SimpleTIM::get_clut_y()};
}
};
struct __no_align CopyTo {

View File

@ -1,10 +1,12 @@
#include "../../../internal-include/GPU/gpu_internal.hpp"
#include "simplehelper.hpp"
#include <PSX/GPU/gpu_types.hpp>
#include <limits.h>
#include <stdio.h>
namespace JabyEngine {
namespace FileProcessor {
using GPU::AreaU16;
using GPU::PositionU16;
using GPU::SizeU16;
@ -12,20 +14,28 @@ namespace JabyEngine {
constexpr SimpleTIMSize() {
}
constexpr uint16_t getTextureWidth() const {
return SimpleTIM::getTextureX();
constexpr uint16_t get_texture_width() const {
return SimpleTIM::get_texture_x();
}
constexpr uint16_t getTextureHeight() const {
return SimpleTIM::getTextureY();
constexpr uint16_t get_texture_height() const {
return SimpleTIM::get_texture_y();
}
constexpr uint16_t getClutWidth() const {
return SimpleTIM::getClutX();
constexpr SizeU16 get_texture_size() const {
return {SimpleTIMSize::get_texture_width(), SimpleTIMSize::get_texture_height()};
}
constexpr uint16_t getClutHeight() const {
return SimpleTIM::getClutY();
constexpr uint16_t get_clut_width() const {
return SimpleTIM::get_clut_x();
}
constexpr uint16_t get_clut_height() const {
return SimpleTIM::get_clut_y();
}
constexpr SizeU16 get_clut_size() const {
return {SimpleTIMSize::get_clut_width(), SimpleTIMSize::get_clut_height()};
}
};
@ -44,9 +54,12 @@ namespace JabyEngine {
GPU::internal::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
}
static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) {
state.words_left = (width*height)/2;
set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), width, height);
static size_t set_gpu_receive_data(const uint32_t* src, const AreaU16& dst) {
const auto width = dst.size.width;
const auto height = dst.size.height;
set_gpu_receive(src, dst.position.x, dst.position.y, width, height);
return (width*height)/2;
}
static Progress parse_data(State::Configuration& config, SimpleTIMState& state) {
@ -91,7 +104,7 @@ namespace JabyEngine {
}
static Progress switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) {
set_gpu_receive_data(reinterpret_cast<const uint32_t*>(config.data_adr), state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight());
state.words_left = set_gpu_receive_data(reinterpret_cast<const uint32_t*>(config.data_adr), {state.dst_info.get_texture_position(), state.size_info.get_texture_size()});
return Helper::exchange_and_execute_process_function(parse_data, config, state);
}
@ -110,9 +123,9 @@ namespace JabyEngine {
Helper::simple_read(state.size_info, config);
//Check if we have a clut to care about
if(state.size_info.getClutWidth() > 0) {
if(state.size_info.get_clut_width() > 0) {
//CLUTs are 16bit full color anyway
set_gpu_receive_data(reinterpret_cast<const uint32_t*>(config.data_adr), state, state.size_info.getClutWidth(), state.size_info.getClutHeight());
state.words_left = set_gpu_receive_data(reinterpret_cast<const uint32_t*>(config.data_adr), {state.dst_info.get_clut_position(), state.size_info.get_clut_size()});
return Helper::exchange_and_execute_process_function(parse_clut, config, state);
}

View File

@ -64,18 +64,18 @@ fn encode<T: PSXImageConverter>(image: T, color_depth: ColorType, clut_align: Cl
if let Some(palette) = palette {
let mut color_count = pal_width*pal_height;
for color in palette {
tool_helper::raw::write_generic(output, color)?;
tool_helper::raw::write_generic(output, color.get_raw())?;
color_count -= 1;
}
while color_count > 0 {
tool_helper::raw::write_generic(output, PSXColor::black())?;
tool_helper::raw::write_generic(output, PSXColor::black().get_raw())?;
color_count -= 1;
}
}
for color in image {
tool_helper::raw::write_generic(output, color)?;
tool_helper::raw::write_generic(output, color.get_raw())?;
}
Ok(())

View File

@ -102,6 +102,10 @@ impl Color {
Color{value}
}
pub const fn get_raw(&self) -> u16 {
self.value.to_le()
}
const fn new(stp: u8, red: u8, green: u8, blue: u8) -> Color {
let value = set_member_value!(set_member_value!(set_member_value!(set_member_value!(0,
stp, 0, u16),

View File

@ -1,6 +1,6 @@
[package]
name = "tool_helper"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -57,7 +57,7 @@ macro_rules! create_bit_functions {
}
pub const fn [< get_value_ $type_val >](src: $type_val, range: &BitRange) -> $type_val {
(src & [< get_mask_ $type_val >](range)) >> range.start
(src & ([< get_mask_ $type_val >](range) << (range.start as $type_val))) >> range.start
}
pub const fn [< bit_set_ $type_val >](src: $type_val, bit: usize) -> bool {