From bb33b6cb10ae40114d63c6cfeb20aa6232a4862c Mon Sep 17 00:00:00 2001 From: bendn Date: Mon, 30 Oct 2023 20:11:58 +0700 Subject: [PATCH] expand idk --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e1c8249..3f5d7a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -526,9 +526,18 @@ impl Image, CHANNELS> { #[cfg(feature = "save")] /// Open a PNG image pub fn open(f: impl AsRef) -> Self { + use png::Transformations as T; let p = std::fs::File::open(f).unwrap(); let r = std::io::BufReader::new(p); - let dec = png::Decoder::new(r); + let mut dec = png::Decoder::new(r); + match CHANNELS { + 1 => dec.set_transformations(T::STRIP_16 | T::EXPAND), + 2 => dec.set_transformations(T::STRIP_16 | T::ALPHA), + 3 => dec.set_transformations(T::STRIP_16 | T::EXPAND), + 4 => dec.set_transformations(T::STRIP_16 | T::ALPHA), + _ => (), + } + dec.set_transformations(png::Transformations::EXPAND); let mut reader = dec.read_info().unwrap(); let mut buf = vec![0; reader.output_buffer_size()]; let info = reader.next_frame(&mut buf).unwrap();