From 5f0dafc0b92adf86a0db9b6a4906c0839f4b3f03 Mon Sep 17 00:00:00 2001 From: Jan Solanti Date: Sun, 29 Aug 2021 16:14:34 +0300 Subject: [PATCH] Update dependencies --- squish/Cargo.toml | 2 +- squish_cli/Cargo.toml | 9 ++++----- squish_cli/src/image/png.rs | 24 +++++++++++++----------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/squish/Cargo.toml b/squish/Cargo.toml index 13e9c15..02a327f 100644 --- a/squish/Cargo.toml +++ b/squish/Cargo.toml @@ -14,6 +14,6 @@ keywords = ["DDS", "DXT", "texture", "compression"] travis-ci = {repository = "jansol/squish-rs"} [dependencies] -libm = "0.1" +libm = "0.2" rayon = {version = "1", optional = true} diff --git a/squish_cli/Cargo.toml b/squish_cli/Cargo.toml index 1aeaa49..1c54963 100644 --- a/squish_cli/Cargo.toml +++ b/squish_cli/Cargo.toml @@ -20,10 +20,10 @@ path = "src/main.rs" doc = false [dependencies] -ddsfile = "0.2.3" -jpeg-decoder = "0.1.15" -png = "0.15.0" -structopt = "0.3.2" +ddsfile = "0.4.0" +jpeg-decoder = "0.1.18" +png = "0.17.0" +structopt = "0.3.7" [features] rayon = ["squish/rayon"] @@ -32,4 +32,3 @@ default = ["rayon"] [dependencies.squish] path = "../squish" version = "1.0" - diff --git a/squish_cli/src/image/png.rs b/squish_cli/src/image/png.rs index 493c724..50946c5 100644 --- a/squish_cli/src/image/png.rs +++ b/squish_cli/src/image/png.rs @@ -23,28 +23,30 @@ use std::fs::File; use std::io::BufWriter; use std::path::Path; -use png::{BitDepth, ColorType, Decoder, Encoder, Transformations}; +use png::{BitDepth, ColorType, Transformations}; use super::RawImage; pub fn read(path: &Path) -> RawImage { let file = File::open(path).expect("Failed to open file"); - let mut decoder = Decoder::new(file); + let mut decoder = png::Decoder::new(file); decoder.set_transformations(Transformations::EXPAND); - let (info, mut reader) = decoder + let mut reader = decoder .read_info() .expect("Failed to read PNG header. Is this really a PNG file?"); - if info.bit_depth != BitDepth::Eight { - panic!("Only images with 8 bits per channel are supported"); - } // Preallocate the output buffer. - let mut buf = vec![0; info.buffer_size()]; + let mut buf = vec![0; reader.output_buffer_size()]; // Read the next frame. Currently this function should only called once. reader.next_frame(&mut buf).unwrap(); + let info = reader.info(); + if info.bit_depth != BitDepth::Eight { + panic!("Only images with 8 bits per channel are supported"); + } + // expand to rgba buf = match info.color_type { ColorType::Grayscale => buf[..] @@ -55,11 +57,11 @@ pub fn read(path: &Path) -> RawImage { .chunks(2) .flat_map(|rg| vec![rg[0], rg[0], rg[0], rg[1]]) .collect::>(), - ColorType::RGB => buf[..] + ColorType::Rgb => buf[..] .chunks(3) .flat_map(|rgb| vec![rgb[0], rgb[1], rgb[2], 255]) .collect::>(), - ColorType::RGBA => buf, + ColorType::Rgba => buf, _ => unreachable!(), }; @@ -74,8 +76,8 @@ pub fn write(path: &Path, width: u32, height: u32, data: &[u8]) { let file = File::create(path).expect("Unable to create file"); let w = &mut BufWriter::new(file); - let mut encoder = Encoder::new(w, width, height); - encoder.set_color(ColorType::RGBA); + let mut encoder = png::Encoder::new(w, width, height); + encoder.set_color(ColorType::Rgba); encoder.set_depth(BitDepth::Eight); let mut writer = encoder.write_header().unwrap();