Basic Color support
This commit is contained in:
@@ -8,4 +8,5 @@ edition = "2021"
|
||||
[dependencies]
|
||||
clap = {version = "*", features = ["derive"]}
|
||||
image = "*"
|
||||
paste = "*"
|
||||
tool_helper = {path = "../tool_helper"}
|
53
src/Tools/jaby_engine_fconv/src/images/reduced_tim/color.rs
Normal file
53
src/Tools/jaby_engine_fconv/src/images/reduced_tim/color.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use tool_helper::{*, bits::BitRange};
|
||||
|
||||
#[repr(packed(1))]
|
||||
#[allow(dead_code)]
|
||||
struct Color {
|
||||
value: u16
|
||||
}
|
||||
|
||||
macro_rules! set_member_value {
|
||||
($dst:expr, $color:ident, $shift:expr) => {
|
||||
paste::item! {
|
||||
bits::set_value_u16($dst, ($color >> $shift) as u16, &Self::[< $color:upper _BIT_RANGE >])
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! make_member_getter_setter {
|
||||
($color:ident, $shift:expr) => {
|
||||
paste::item! {
|
||||
pub fn [< set_ $color >](&mut self, $color: u8) {
|
||||
self.value = set_member_value!(self.value, $color, $shift);
|
||||
}
|
||||
|
||||
pub fn [< get_ $color >](&self) -> u8 {
|
||||
(bits::get_value_u16(self.value, &Self::[< $color:upper _BIT_RANGE >]) as u8) << $shift
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Color {
|
||||
const COLOR_SHIFT: u16 = 3;
|
||||
const STP_BIT_RANGE: BitRange = BitRange::from_to(15, 15);
|
||||
const RED_BIT_RANGE: BitRange = BitRange::from_to(0, 4);
|
||||
const GREEN_BIT_RANGE: BitRange = BitRange::from_to(5, 9);
|
||||
const BLUE_BIT_RANGE: BitRange = BitRange::from_to(10, 14);
|
||||
|
||||
pub 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),
|
||||
red, Self::COLOR_SHIFT),
|
||||
green, Self::COLOR_SHIFT),
|
||||
blue, Self::COLOR_SHIFT);
|
||||
|
||||
Color{value}
|
||||
}
|
||||
|
||||
make_member_getter_setter!(stp, 0);
|
||||
make_member_getter_setter!(red, Self::COLOR_SHIFT);
|
||||
make_member_getter_setter!(green, Self::COLOR_SHIFT);
|
||||
make_member_getter_setter!(blue, Self::COLOR_SHIFT);
|
||||
}
|
@@ -3,6 +3,8 @@ use image::io::Reader as ImageReader;
|
||||
use std::io::Cursor;
|
||||
use tool_helper::{Error, Input, Output};
|
||||
|
||||
mod color;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||
pub enum ColorDepth {
|
||||
Clut4,
|
||||
@@ -16,8 +18,19 @@ pub struct Arguments {
|
||||
color_depth: ColorDepth
|
||||
}
|
||||
|
||||
pub fn convert(_args: Arguments, input: Input, _output: Output) -> Result<(), Error> {
|
||||
ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?));
|
||||
fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
|
||||
match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() {
|
||||
Ok(image) => {
|
||||
|
||||
Ok(())
|
||||
},
|
||||
Err(error) => Err(Error::from_error(error))
|
||||
}
|
||||
}
|
||||
|
||||
Err(Error::not_implemented("convert"))
|
||||
pub fn convert(args: Arguments, input: Input, output: Output) -> Result<(), Error> {
|
||||
match args.color_depth {
|
||||
ColorDepth::Full16 => convert_full16(input, output),
|
||||
_ => Err(Error::not_implemented("Converting anything else then full16")),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user