mirror of
https://github.com/Dangoware/sqp.git
synced 2025-04-19 07:12:55 -05:00
Ran cargo fmt
This commit is contained in:
parent
b0e4037f2a
commit
85cc2dea22
7 changed files with 25 additions and 26 deletions
|
@ -99,14 +99,15 @@ impl<'a, O: Write + WriteBytesExt> BitWriter<'a, O> {
|
|||
panic!("Must write 1 or more bytes.")
|
||||
}
|
||||
|
||||
self.output.write_all(&data.to_le_bytes()[..byte_len]).unwrap();
|
||||
self.output
|
||||
.write_all(&data.to_le_bytes()[..byte_len])
|
||||
.unwrap();
|
||||
self.byte_offset += byte_len;
|
||||
|
||||
self.byte_size = self.byte_offset + (self.bit_offset + 7) / 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A simple way to read individual bits from an input implementing [Read].
|
||||
pub struct BitReader<'a, I: Read + ReadBytesExt> {
|
||||
input: &'a mut I,
|
||||
|
|
1
src/compression/dct.rs
Normal file
1
src/compression/dct.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
use std::{collections::HashMap, io::{Cursor, Read, Write}};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::{Cursor, Read, Write},
|
||||
};
|
||||
|
||||
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
|
||||
|
||||
|
@ -118,7 +121,7 @@ fn compress_lzw(data: &[u8], last: Vec<u8>) -> (usize, Vec<u8>, Vec<u8>) {
|
|||
|
||||
if dictionary_count >= 0x3FFFE {
|
||||
count -= 1;
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,10 +148,7 @@ fn compress_lzw(data: &[u8], last: Vec<u8>) -> (usize, Vec<u8>, Vec<u8>) {
|
|||
(count, output_buf, last_element)
|
||||
}
|
||||
|
||||
pub fn decompress<T: ReadBytesExt + Read>(
|
||||
input: &mut T,
|
||||
chunk_info: &CompressionInfo,
|
||||
) -> Vec<u8> {
|
||||
pub fn decompress<T: ReadBytesExt + Read>(input: &mut T, chunk_info: &CompressionInfo) -> Vec<u8> {
|
||||
let mut output_buf: Vec<u8> = vec![];
|
||||
|
||||
for block in &chunk_info.chunks {
|
||||
|
@ -173,7 +173,6 @@ fn decompress_lzw(input_data: &[u8], size: usize) -> Vec<u8> {
|
|||
}
|
||||
let mut dictionary_count = dictionary.len() as u64;
|
||||
|
||||
|
||||
let mut result = Vec::with_capacity(size);
|
||||
let data_size = input_data.len();
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
mod lossless;
|
|
@ -1,5 +1,5 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use byteorder::{WriteBytesExt, LE};
|
||||
use std::io::{Cursor, Write};
|
||||
|
||||
pub struct Header {
|
||||
pub magic: [u8; 8],
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -1,23 +1,24 @@
|
|||
mod compression {
|
||||
pub mod dct;
|
||||
pub mod lossless;
|
||||
}
|
||||
mod binio;
|
||||
mod header;
|
||||
mod operations;
|
||||
mod binio;
|
||||
mod picture;
|
||||
|
||||
use std::{fs::File, io::{BufReader, BufWriter}, time::Instant};
|
||||
use picture::DangoPicture;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufReader, BufWriter},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use image::RgbaImage;
|
||||
|
||||
fn main() {
|
||||
let image_data = image::open("littlespace.png").unwrap().to_rgba8();
|
||||
let encoded_dpf = DangoPicture::from_raw(
|
||||
image_data.width(),
|
||||
image_data.height(),
|
||||
&image_data
|
||||
);
|
||||
let encoded_dpf = DangoPicture::from_raw(image_data.width(), image_data.height(), &image_data);
|
||||
|
||||
let timer = Instant::now();
|
||||
let mut outfile = BufWriter::new(File::create("test.dpf").unwrap());
|
||||
|
@ -32,7 +33,8 @@ fn main() {
|
|||
let out_image = RgbaImage::from_raw(
|
||||
decoded_dpf.header.width,
|
||||
decoded_dpf.header.height,
|
||||
decoded_dpf.bitmap.into()
|
||||
).unwrap();
|
||||
decoded_dpf.bitmap.into(),
|
||||
)
|
||||
.unwrap();
|
||||
out_image.save("test.png").unwrap();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use thiserror::Error;
|
|||
use crate::{
|
||||
compression::lossless::{compress, decompress, ChunkInfo, CompressionInfo},
|
||||
header::Header,
|
||||
operations::{diff_line, line_diff}
|
||||
operations::{diff_line, line_diff},
|
||||
};
|
||||
|
||||
pub struct DangoPicture {
|
||||
|
@ -45,7 +45,7 @@ impl DangoPicture {
|
|||
input.read_exact(&mut magic).unwrap();
|
||||
|
||||
if magic != *b"dangoimg" {
|
||||
return Err(Error::InvalidIdentifier(magic))
|
||||
return Err(Error::InvalidIdentifier(magic));
|
||||
}
|
||||
|
||||
let header = Header {
|
||||
|
@ -70,10 +70,7 @@ impl DangoPicture {
|
|||
|
||||
let bitmap = line_diff(header.width, header.height, &preprocessed_bitmap);
|
||||
|
||||
Ok(DangoPicture {
|
||||
header,
|
||||
bitmap
|
||||
})
|
||||
Ok(DangoPicture { header, bitmap })
|
||||
}
|
||||
|
||||
pub fn from_raw(width: u32, height: u32, bitmap: &[u8]) -> Self {
|
||||
|
|
Loading…
Reference in a new issue