From 35ad9c68c23e8a433b2f12805c17382f0dd8a9d7 Mon Sep 17 00:00:00 2001 From: jaby Date: Sun, 25 Sep 2022 16:31:11 +0200 Subject: [PATCH] Deconstruct PNG imag --- .../src/images/reduced_tim/mod.rs | 37 +++++++++++++++++-- src/Tools/tool_helper/src/lib.rs | 4 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs b/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs index ac481b64..1483ec7a 100644 --- a/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs +++ b/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs @@ -42,15 +42,46 @@ fn convert_full16(input: Input, output: Output) -> Result<(), Error> { DynamicImage::ImageRgb8(image) => encode(RgbImage::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)) } } -fn convert_palette_based(_: Input, _: Output, _: ColorType) -> Result<(), Error> { - Err(Error::from_text("Not implemented yet".to_owned())) +fn convert_palette_based(input: Input, _: Output, _: ColorType) -> Result<(), Error> { + 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> { diff --git a/src/Tools/tool_helper/src/lib.rs b/src/Tools/tool_helper/src/lib.rs index 904a8475..bd5ef2d7 100644 --- a/src/Tools/tool_helper/src/lib.rs +++ b/src/Tools/tool_helper/src/lib.rs @@ -15,6 +15,10 @@ pub struct Error { impl Error { 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 { Error{exit_code: Self::DEFAULT_EXITCODE, action: String::new(), text} }