expand idk

This commit is contained in:
bendn 2023-10-30 20:11:58 +07:00
parent 47a299d9ae
commit bb33b6cb10
No known key found for this signature in database
GPG key ID: 0D9D3A2A3B2A93D6

View file

@ -526,9 +526,18 @@ impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> {
#[cfg(feature = "save")]
/// Open a PNG image
pub fn open(f: impl AsRef<std::path::Path>) -> 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();