add diff rle and run decoding on final byte array

This commit is contained in:
Crispy 2024-04-11 20:52:12 +02:00
parent eca5344c66
commit 3af9be328c
6 changed files with 308 additions and 48 deletions

View file

@ -1,5 +1,31 @@
use crate::*;
pub fn rle_diff_horizontal(prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
let mut pixels = Vec::new();
for y in 0..HEIGHT {
for x in 0..WIDTH {
pixels.push(frame[x][y] ^ prev_frame[x][y]);
}
}
EncodedFrame {
encoding: Encoding::RLEDiffHorizontal,
data: rle_255_encode(&pixels),
}
}
pub fn rle_diff_vertical(prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
let mut pixels = Vec::new();
for x in 0..WIDTH {
for y in 0..HEIGHT {
pixels.push(frame[x][y] ^ prev_frame[x][y]);
}
}
EncodedFrame {
encoding: Encoding::RLEDiffVertical,
data: rle_255_encode(&pixels),
}
}
pub fn rle_horizontal(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
let mut pixels = Vec::new();
for y in 0..HEIGHT {
@ -9,7 +35,6 @@ pub fn rle_horizontal(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
}
EncodedFrame {
encoding: Encoding::RLEHorizontal,
head_u4: 0,
data: rle_255_encode(&pixels),
}
}
@ -23,7 +48,6 @@ pub fn rle_vertical(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
}
EncodedFrame {
encoding: Encoding::RLEVertical,
head_u4: 0,
data: rle_255_encode(&pixels),
}
}
@ -31,7 +55,6 @@ pub fn rle_vertical(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
pub fn fill_white(_prev_frame: &Frame, _frame: &Frame) -> EncodedFrame {
EncodedFrame {
encoding: Encoding::FillWhite,
head_u4: 0,
data: Vec::new(),
}
}
@ -39,7 +62,6 @@ pub fn fill_white(_prev_frame: &Frame, _frame: &Frame) -> EncodedFrame {
pub fn fill_black(_prev_frame: &Frame, _frame: &Frame) -> EncodedFrame {
EncodedFrame {
encoding: Encoding::FillBlack,
head_u4: 0,
data: Vec::new(),
}
}