Skip to content

Commit

Permalink
add h/vflipped hashes on imageset format
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Jun 10, 2020
1 parent b52c6d7 commit 03fc87d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
25 changes: 22 additions & 3 deletions vera/src/imageset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub struct VeraImage {
/// Background colour on 1BPP mode
pub background: u8,
/// Also store hashes of each rotation
/// 90, 180, 270
pub rotation_hashes: [u64; 3],
/// h_flipped, v_flipped, h_flipped and v_flipped
pub flip_hashes: [u64; 3],
}

impl Hash for VeraImage {
Expand Down Expand Up @@ -194,7 +194,7 @@ impl VeraImage {
depth: VeraPixelDepth::BPP8,
foreground: 0,
background: 0,
rotation_hashes: [0; 3],
flip_hashes: [0; 3],
}
}

Expand Down Expand Up @@ -266,6 +266,16 @@ impl VeraImage {
}
ret
}

/// Store flip hashes
pub fn store_flip_hashes(&mut self) {
let h_flipped = self.h_flip();
self.flip_hashes[0] = h_flipped.calc_hash();
let v_flipped = self.v_flip();
self.flip_hashes[1] = v_flipped.calc_hash();
let both = h_flipped.v_flip();
self.flip_hashes[2] = both.calc_hash();
}
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -413,6 +423,14 @@ impl VeraImageSet {
Ok(())
}

/// Calc/Store all the hashes of vflipped or hflipped
/// versions of the frame
pub fn store_flip_hashes(&mut self) {
for f in self.frame_data.iter_mut() {
f.store_flip_hashes();
}
}

/// Format the stored indices with a given palette and colour depth
/// Should fail if any frame in the set contains a range of colours
/// that can't be found within a single 2^BPP length range in the
Expand Down Expand Up @@ -504,6 +522,7 @@ impl VeraImageSet {
}
}
self.depth = Some(depth);
self.store_flip_hashes();
self.formatted = true;
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions vera/tests/imageset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,16 @@ fn image_flip() -> Result<(), Error> {
set.format_indices(&palette, VeraPixelDepth::BPP4)?;

let orig = set.frame_data[2].clone();
println!("{:?}", orig.flip_hashes);
println!("{}", orig);
let h_flipped = orig.h_flip();
println!("{}", h_flipped);
assert_eq!(orig.flip_hashes[0], h_flipped.calc_hash());
assert_eq!(h_flipped.data[7].pal_index, Some(7));
let v_flipped = h_flipped.v_flip();
println!("{}", v_flipped);
assert_eq!(v_flipped.data[63].pal_index, Some(7));
assert_eq!(orig.flip_hashes[2], v_flipped.calc_hash());

let orig = set.frame_data[3].clone();
println!("{}", orig);
Expand Down

0 comments on commit 03fc87d

Please sign in to comment.