aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test2/src/encode.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/test2/src/encode.rs b/test2/src/encode.rs
index 8db88b0..7eb82e0 100644
--- a/test2/src/encode.rs
+++ b/test2/src/encode.rs
@@ -25,8 +25,8 @@ impl BitstreamFilter for Enc {
};
let mut out = Vec::new();
- let mut oldblock = Vec::new();
- let mut newblock = Vec::new();
+ let mut savblock = Vec::new();
+ let mut refblock = Vec::new();
for by in 0..frame.res.y / BLOCK_SIZE {
for bx in 0..frame.res.x / BLOCK_SIZE {
@@ -61,20 +61,29 @@ impl BitstreamFilter for Enc {
}
}
- oldblock.clear();
- frame.export_block(boff, &mut oldblock);
+ savblock.clear();
+ frame.export_block(boff, &mut savblock);
Frame::copy_block(&self.last, &mut frame, best_off, boff);
- newblock.clear();
- frame.export_block(boff, &mut newblock);
+ refblock.clear();
+ frame.export_block(boff, &mut refblock);
let reloff = best_off - boff;
out.push((reloff.x + 127) as u8);
out.push((reloff.y + 127) as u8);
for i in 0..(BLOCK_SIZE * BLOCK_SIZE + BLOCK_SIZE * BLOCK_SIZE / 2) {
- out.push(oldblock[i as usize] - newblock[i as usize])
+ let mut d = savblock[i as usize] - refblock[i as usize];
+ let neg = d > 127;
+ if neg {
+ d = (-(d as i8)) as u8;
+ }
+ d &= 0xff << (6 - d.leading_zeros()); // only keep 3 msb
+ if neg {
+ d = (-(d as i8)) as u8;
+ }
+ out.push(d)
}
frame.import_block_diff(