Support CLUT alignment
This commit is contained in:
parent
710ac213c8
commit
24afcde9f0
|
@ -17,6 +17,7 @@ pub enum ColorType{
|
||||||
Full16,
|
Full16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||||
pub enum ClutAlignment {
|
pub enum ClutAlignment {
|
||||||
None,
|
None,
|
||||||
Linear,
|
Linear,
|
||||||
|
@ -26,7 +27,10 @@ pub enum ClutAlignment {
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
#[clap(arg_enum, value_parser)]
|
#[clap(arg_enum, value_parser)]
|
||||||
color_depth: ColorType
|
color_depth: ColorType,
|
||||||
|
|
||||||
|
#[clap(arg_enum, value_parser, default_value_t=ClutAlignment::None)]
|
||||||
|
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, mut output: Output) -> Result<(), Error> {
|
||||||
|
@ -84,7 +88,7 @@ fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_palette_based(input: Input, output: Output, color_type: ColorType) -> Result<(), Error> {
|
fn convert_palette_based(input: Input, output: Output, color_type: ColorType, clut_align: ClutAlignment) -> Result<(), 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 = {
|
||||||
|
@ -94,7 +98,7 @@ fn convert_palette_based(input: Input, output: Output, color_type: ColorType) ->
|
||||||
_ => return Err(Error::from_str("ColorType not supported"))
|
_ => return Err(Error::from_str("ColorType not supported"))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
encode(IndexedImage::new(reader, output_type)?, ClutAlignment::None, output)
|
encode(IndexedImage::new(reader, output_type)?, clut_align, output)
|
||||||
},
|
},
|
||||||
Err(error) => Err(Error::from_error(error))
|
Err(error) => Err(Error::from_error(error))
|
||||||
}
|
}
|
||||||
|
@ -103,6 +107,6 @@ fn convert_palette_based(input: Input, output: Output, color_type: ColorType) ->
|
||||||
pub fn convert(args: Arguments, input: Input, output: Output) -> Result<(), Error> {
|
pub fn convert(args: Arguments, input: Input, output: Output) -> Result<(), Error> {
|
||||||
match args.color_depth {
|
match args.color_depth {
|
||||||
ColorType::Full16 => convert_full16(input, output),
|
ColorType::Full16 => convert_full16(input, output),
|
||||||
_ => convert_palette_based(input, output, args.color_depth),
|
_ => convert_palette_based(input, output, args.color_depth, args.clut_align),
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue