Deconstruct PNG imag

This commit is contained in:
Jaby 2022-09-25 16:31:11 +02:00 committed by Jaby
parent 7b18faabe3
commit bc83d6078b
2 changed files with 38 additions and 3 deletions

View File

@ -42,15 +42,46 @@ fn convert_full16(input: Input, output: Output) -> Result<(), Error> {
DynamicImage::ImageRgb8(image) => encode(RgbImage::new(image), output), DynamicImage::ImageRgb8(image) => encode(RgbImage::new(image), output),
DynamicImage::ImageRgba8(image) => encode(RgbaImage::new(image), output), DynamicImage::ImageRgba8(image) => encode(RgbaImage::new(image), output),
_ => Err(Error::from_text("Only RGB and RGBA images are supported for 16bit encoding".to_owned())) _ => Err(Error::from_str("Only RGB and RGBA images are supported for 16bit encoding"))
} }
}, },
Err(error) => Err(Error::from_error(error)) Err(error) => Err(Error::from_error(error))
} }
} }
fn convert_palette_based(_: Input, _: Output, _: ColorType) -> Result<(), Error> { fn convert_palette_based(input: Input, _: Output, _: ColorType) -> Result<(), Error> {
Err(Error::from_text("Not implemented yet".to_owned())) match png::Decoder::new(input).read_info() {
Ok(mut reader) => {
let mut buf = vec![0; reader.output_buffer_size()];
loop {
match reader.next_frame(&mut buf) {
Ok(_) => {
println!("Frame: {}", buf.len());
for byte in &buf {
print!("[{}] ", byte);
}
println!("");
}
Err(err) => {
println!("Wuff: {}", err);
break;
}
}
}
let info = reader.info();
println!("picture: {} - {}, ({:?}, {:?}) ", info.width, info.height, info.color_type, info.bit_depth);
if let Some(pal) = &info.palette {
println!("Size of PAL: {}", pal.len());
}
Err(Error::from_str("Under construction"))
},
Err(error) => Err(Error::from_error(error))
}
} }
pub fn convert(args: Arguments, input: Input, output: Output) -> Result<(), Error> { pub fn convert(args: Arguments, input: Input, output: Output) -> Result<(), Error> {

View File

@ -15,6 +15,10 @@ pub struct Error {
impl Error { impl Error {
const DEFAULT_EXITCODE:i32 = -1; const DEFAULT_EXITCODE:i32 = -1;
pub fn from_str(str: &str) -> Error {
Self::from_text(str.to_owned())
}
pub fn from_text(text: String) -> Error { pub fn from_text(text: String) -> Error {
Error{exit_code: Self::DEFAULT_EXITCODE, action: String::new(), text} Error{exit_code: Self::DEFAULT_EXITCODE, action: String::new(), text}
} }