diff --git a/Cargo.toml b/Cargo.toml index f36525e..aa66fc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,14 @@ [package] -name = "dpf_format" +name = "sqp" +description = """ +The squishiest image format! +""" +license = "MIT" version = "0.1.0" edition = "2021" [dependencies] byteorder = "1.5.0" -image = "0.25.2" integer-encoding = "4.0.0" rayon = "1.10.0" thiserror = "1.0.63" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a7a1429 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +//! SQP (SQuishy Picture Format) is an image format. It can be used to store +//! image data in lossless or lossy compressed form, while remaining relatively +//! simple. + +mod compression { + pub mod dct; + pub mod lossless; +} +mod binio; +mod operations; + +pub mod picture; +pub mod header; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 2a860ea..0000000 --- a/src/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -mod compression { - pub mod dct; - pub mod lossless; -} -mod binio; -mod header; -mod operations; -pub mod picture; - -use std::{fs::File, io::{BufReader, BufWriter}, time::Instant}; -use header::{ColorFormat, CompressionType}; -use image::{ImageReader, RgbaImage}; -use picture::DangoPicture; - -fn main() { - let mut input = ImageReader::open("shit.png").unwrap(); - input.no_limits(); - let input = input.decode().unwrap().to_rgba8(); - input.save("original.png").unwrap(); - - let dpf_lossy = DangoPicture::from_raw( - input.width(), - input.height(), - ColorFormat::Rgba32, - CompressionType::LossyDct, - Some(80), - input.as_raw().clone() - ); - - let dpf_lossless = DangoPicture::from_raw( - input.width(), - input.height(), - ColorFormat::Rgba32, - CompressionType::Lossless, - None, - input.as_raw().clone() - ); - - println!("\n--- LOSSY ---"); - println!("Encoding"); - let timer = Instant::now(); - let mut outfile = BufWriter::new(std::fs::File::create("test-lossy.dpf").unwrap()); - let size = dpf_lossy.encode(&mut outfile).unwrap(); - println!("Encoding took {}ms", timer.elapsed().as_millis()); - println!("Size is {}Mb", (((size as f32 / 1_000_000.0) * 100.0) as u32 as f32) / 100.0); - - println!("Decoding"); - let timer = Instant::now(); - let mut infile = BufReader::new(File::open("test-lossy.dpf").unwrap()); - let decoded_dpf = DangoPicture::decode(&mut infile).unwrap(); - RgbaImage::from_raw(decoded_dpf.header.width, decoded_dpf.header.height, decoded_dpf.bitmap.into()).unwrap().save("test-lossy.png").unwrap(); - println!("Decoding took {}ms", timer.elapsed().as_millis()); - - println!("\n--- LOSSLESS ---"); - println!("Encoding"); - let timer = Instant::now(); - let mut outfile = BufWriter::new(std::fs::File::create("test-lossless.dpf").unwrap()); - let size = dpf_lossless.encode(&mut outfile).unwrap(); - println!("Encoding took {}ms", timer.elapsed().as_millis()); - println!("Size is {}Mb", (((size as f32 / 1_000_000.0) * 100.0) as u32 as f32) / 100.0); - - println!("Decoding"); - let timer = Instant::now(); - let mut infile = BufReader::new(File::open("test-lossless.dpf").unwrap()); - let decoded_dpf = DangoPicture::decode(&mut infile).unwrap(); - RgbaImage::from_raw(decoded_dpf.header.width, decoded_dpf.header.height, decoded_dpf.bitmap.into()).unwrap().save("test-lossless.png").unwrap(); - println!("Decoding took {}ms", timer.elapsed().as_millis()); -} diff --git a/src/picture.rs b/src/picture.rs index b1a749e..e86e914 100644 --- a/src/picture.rs +++ b/src/picture.rs @@ -29,7 +29,19 @@ pub enum Error { } impl DangoPicture { - /// Create a DPF + /// Create a DPF from raw bytes in a particular [`ColorFormat`]. + /// + /// ## Example + /// ``` + /// let dpf_lossy = DangoPicture::from_raw( + /// input.width(), + /// input.height(), + /// ColorFormat::Rgba32, + /// CompressionType::LossyDct, + /// Some(80), + /// input.as_raw().clone() + /// ); + /// ``` pub fn from_raw( width: u32, height: u32,