Removed image crate, moved main file to lib

This commit is contained in:
G2-Games 2024-07-28 19:57:50 -05:00
parent 32879731b8
commit c65ba5aaa0
4 changed files with 31 additions and 71 deletions

View file

@ -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"

13
src/lib.rs Normal file
View file

@ -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;

View file

@ -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());
}

View file

@ -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,