Fix image conversion and CLUT placement

This commit is contained in:
2023-05-01 22:37:41 +02:00
parent 904509a65e
commit 513275fba8
6 changed files with 50 additions and 24 deletions

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 {