add 8x8 cell partial update encoding
This commit is contained in:
parent
1f61cebd50
commit
b85cb52ce0
3 changed files with 83 additions and 4 deletions
|
@ -1,5 +1,43 @@
|
|||
use crate::*;
|
||||
|
||||
pub fn cell_diff_8_horizontal(prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
||||
let cells_x = WIDTH / 8;
|
||||
let cells_y = HEIGHT / 8;
|
||||
let loss = 0;
|
||||
|
||||
let mut bitmap: u32 = 0;
|
||||
let mut changed_pixels = Vec::new();
|
||||
|
||||
for celly in 0..cells_y {
|
||||
for cellx in 0..cells_x {
|
||||
let mut changed = 0;
|
||||
let mut cell_contents = Vec::new();
|
||||
// todo try encoding the cells in frame space instead of one cell at a time
|
||||
for dx in 0..8 {
|
||||
for dy in 0..8 {
|
||||
let x = cellx * 8 + dx;
|
||||
let y = celly * 8 + dy;
|
||||
let pixel = frame[x][y];
|
||||
cell_contents.push(pixel);
|
||||
if pixel != prev_frame[x][y] {
|
||||
changed += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed > loss {
|
||||
bitmap |= 1 << (cellx + cells_x * celly);
|
||||
changed_pixels.extend_from_slice(&cell_contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut data = vec![(bitmap >> 16) as u8, (bitmap >> 8) as u8, bitmap as u8];
|
||||
data.extend_from_slice(&rle_255_encode(&changed_pixels));
|
||||
EncodedFrame {
|
||||
encoding: Encoding::CellDiff8H,
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bg_strips_horizontal(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
||||
let bg = most_common_pixel(frame);
|
||||
fn pack_strip(x: usize, y: usize, width: usize) -> [u8; 2] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue