Update dependencies

This commit is contained in:
Jan Solanti
2021-08-29 16:23:01 +03:00
parent 97fc0ece5e
commit 5f0dafc0b9
3 changed files with 18 additions and 17 deletions
+1 -1
View File
@@ -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}
+4 -5
View File
@@ -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"
+13 -11
View File
@@ -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::<Vec<u8>>(),
ColorType::RGB => buf[..]
ColorType::Rgb => buf[..]
.chunks(3)
.flat_map(|rgb| vec![rgb[0], rgb[1], rgb[2], 255])
.collect::<Vec<u8>>(),
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();