add 16 wide, 2 deep tree with RLE at the end. turns out to be worse than other algs
This commit is contained in:
parent
a1bcf7d90b
commit
d44e5d9c55
3 changed files with 144 additions and 6 deletions
|
@ -293,6 +293,71 @@ pub fn rle_horizontal(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/// requires WIDTH and HEIGHT to be multiples of 16
|
||||
/// two-level tree with 4x4 branches per level
|
||||
pub fn tree_16(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
||||
let mut top_node: u16 = 0;
|
||||
let mut second_nodes = Vec::new();
|
||||
let mut included_pixels = Vec::new();
|
||||
// todo allow using white as bg
|
||||
let fg = 1;
|
||||
for cx in 0..4 {
|
||||
for cy in 0..4 {
|
||||
let mut any_filled_here = false;
|
||||
'a: for px in 0..(WIDTH / 4) {
|
||||
let x = cx * (WIDTH / 4) + px;
|
||||
for py in 0..(HEIGHT / 4) {
|
||||
let y = cy * (HEIGHT / 4) + py;
|
||||
if frame[x][y] == fg{
|
||||
any_filled_here = true;
|
||||
break 'a;
|
||||
}
|
||||
}
|
||||
}
|
||||
if any_filled_here {
|
||||
top_node |= 1 << (cy * 4 + cx);
|
||||
let mut second_node: u16 = 0;
|
||||
for ccx in 0..4 {
|
||||
for ccy in 0..4 {
|
||||
let mut any_filled_here = false;
|
||||
let mut node_pixels = Vec::new();
|
||||
for px in 0..(WIDTH / 16) {
|
||||
for py in 0..(HEIGHT / 16) {
|
||||
let x = cx * (WIDTH / 4) + ccx * (WIDTH / 16) + px;
|
||||
let y = cy * (HEIGHT / 4) + ccy * (HEIGHT / 16) + py;
|
||||
if frame[x][y] == fg {
|
||||
node_pixels.push(fg);
|
||||
any_filled_here = true;
|
||||
}else{
|
||||
node_pixels.push(1-fg);
|
||||
}
|
||||
}
|
||||
}
|
||||
if any_filled_here {
|
||||
second_node |= 1 << (ccy * 4 + ccx);
|
||||
included_pixels.extend_from_slice(&node_pixels);
|
||||
}
|
||||
}
|
||||
}
|
||||
second_nodes.push(second_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut data = Vec::new();
|
||||
data.push((top_node >>8) as u8);
|
||||
data.push(top_node as u8);
|
||||
for n in second_nodes{
|
||||
data.push((n>>8)as u8);
|
||||
data.push(n as u8);
|
||||
}
|
||||
data.extend_from_slice(&rle_255_encode(&included_pixels));
|
||||
|
||||
EncodedFrame {
|
||||
encoding: Encoding::Tree16,
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rle_vertical(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
||||
let mut pixels = Vec::new();
|
||||
for x in 0..WIDTH {
|
||||
|
@ -348,7 +413,6 @@ pub fn rle_vertical_ext(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn rle_vertical_16(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
|
||||
let mut data = Vec::new();
|
||||
let mut last_pixel = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue