Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 5, 2023
1 parent df5f785 commit 30ba55a
Showing 1 changed file with 0 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/yaz0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,13 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> {
Vec::with_capacity(input_size + divide_round_up(input_size, 8) + 0x10);

output.extend(b"Yaz0");
//output.extend(index_out_ptr.to_be_bytes());
//output.extend(&[0, 0, 0, 0]);
output.extend((input_size as u32).to_be_bytes());
// padding
output.extend(&[0, 0, 0, 0, 0, 0, 0, 0]);

output.push(0);
let mut index_cur_layout_byte: usize = 0x10;
//uint8_t* cur_layout_byte = &output[0];
let mut index_out_ptr: usize = index_cur_layout_byte + 1;
//uint8_t* out_ptr = cur_layout_byte + 1;
let mut input_pos: usize = 0;
let mut cur_layout_bit: u8 = 0x80;

Expand All @@ -105,8 +101,6 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> {
if group_size <= 2 {
// Set the current layout bit to indicate that this is an uncompressed byte
output[index_cur_layout_byte] |= cur_layout_bit;
//*out_ptr++ = src[input_pos++];
//output[index_out_ptr] = bytes[input_pos];
output.push(bytes[input_pos]);
input_pos += 1;
index_out_ptr += 1;
Expand All @@ -128,8 +122,6 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> {
// Mark the current layout bit to skip compressing this byte, as the next input position yielded better compression
output[index_cur_layout_byte] |= cur_layout_bit;
// Copy the input byte to the output
//*out_ptr++ = src[input_pos++];
// output[index_out_ptr] = bytes[input_pos];
output.push(bytes[input_pos]);
input_pos += 1;
index_out_ptr += 1;
Expand All @@ -139,7 +131,6 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> {

if cur_layout_bit == 0 {
cur_layout_bit = 0x80;
//cur_layout_byte = out_ptr++;
index_cur_layout_byte = index_out_ptr;
index_out_ptr += 1;
output[index_cur_layout_byte] = 0;
Expand All @@ -155,21 +146,16 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> {
// Determine which encoding to use for the current group
if group_size >= 0x12 {
// Three bytes, 0RRRNN
// output[index_out_ptr] = (group_offset >> 8) as u8;
output.push((group_offset >> 8) as u8);
index_out_ptr += 1;
// output[index_out_ptr] = (group_offset & 0xFF) as u8;
output.push((group_offset & 0xFF) as u8);
index_out_ptr += 1;
// output[index_out_ptr] = (group_size - 0x12) as u8;
output.push((group_size - 0x12) as u8);
index_out_ptr += 1;
} else {
// Two bytes, NRRR
// output[index_out_ptr] = (group_offset >> 8) as u8 | ((group_size - 2) << 4) as u8;
output.push((group_offset >> 8) as u8 | ((group_size - 2) << 4) as u8);
index_out_ptr += 1;
// output[index_out_ptr] = (group_offset & 0xFF) as u8;
output.push((group_offset & 0xFF) as u8);
index_out_ptr += 1;
}
Expand All @@ -183,7 +169,6 @@ pub fn compress_yaz0(bytes: &[u8]) -> Box<[u8]> {

if cur_layout_bit == 0 {
cur_layout_bit = 0x80;
//cur_layout_byte = out_ptr++;
index_cur_layout_byte = index_out_ptr;
output.push(0);
index_out_ptr += 1;
Expand Down

0 comments on commit 30ba55a

Please sign in to comment.