Compare commits
No commits in common. "242724d7fd2053acc76959846828d8e59f959615" and "1f61cebd500247b36b5ac30b70d59b3181d5e8b6" have entirely different histories.
242724d7fd
...
1f61cebd50
4 changed files with 4 additions and 85 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,6 +5,3 @@
|
|||
*.map
|
||||
*.pdf
|
||||
target/
|
||||
*.png
|
||||
*.mp4
|
||||
*.webm
|
||||
|
|
|
@ -1,37 +1,5 @@
|
|||
use crate::*;
|
||||
|
||||
pub fn cell_diff_8_vertical(prev_frame: &Frame, encoded: &[u8], reader: &mut usize) -> Frame {
|
||||
let bitmap = {
|
||||
*reader += 3;
|
||||
let mut bitmap = (encoded[0] as u32) << 16;
|
||||
bitmap |= (encoded[1] as u32) << 8;
|
||||
bitmap | encoded[2] as u32
|
||||
};
|
||||
let encoded = &encoded[3..];
|
||||
|
||||
let mut frame = *prev_frame;
|
||||
let changed_pixel_count = bitmap.count_ones() as usize * 8 * 8;
|
||||
let (runs, new_pixels) = rle_255_decode_until(encoded, changed_pixel_count);
|
||||
*reader += runs;
|
||||
|
||||
let cells_x = WIDTH / 8;
|
||||
let mut index = 0;
|
||||
|
||||
for x in 0..WIDTH {
|
||||
for y in 0..HEIGHT {
|
||||
let cellx = x / 8;
|
||||
let celly = y / 8;
|
||||
let is_changed = (bitmap >> (cellx + cells_x * celly)) & 1;
|
||||
if is_changed == 1 {
|
||||
frame[x][y] = new_pixels[index];
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frame
|
||||
}
|
||||
|
||||
pub fn bg_strips_horizontal(_prev_frame: &Frame, encoded: &[u8], reader: &mut usize) -> Frame {
|
||||
*reader += 1;
|
||||
let bg = encoded[0] >> 7;
|
||||
|
|
|
@ -1,50 +1,5 @@
|
|||
use crate::*;
|
||||
|
||||
pub fn cell_diff_8_vertical(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 cellx in 0..cells_x {
|
||||
for celly in 0..cells_y {
|
||||
let mut changed = 0;
|
||||
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];
|
||||
|
||||
if pixel != prev_frame[x][y] {
|
||||
changed += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed > loss {
|
||||
bitmap |= 1 << (cellx + cells_x * celly);
|
||||
}
|
||||
}
|
||||
}
|
||||
for x in 0..WIDTH {
|
||||
for y in 0..HEIGHT {
|
||||
let cellx = x / 8;
|
||||
let celly = y / 8;
|
||||
let bit = 1 << (cellx + cells_x * celly);
|
||||
if (bitmap & bit) != 0 {
|
||||
changed_pixels.push(frame[x][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
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::CellDiff8V,
|
||||
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] {
|
||||
|
|
|
@ -8,7 +8,6 @@ pub use util::*;
|
|||
|
||||
const INSPECT_ENC: bool = false;
|
||||
const INSPECT_DEC: bool = false;
|
||||
const MAX_ERROR: usize = 0;
|
||||
|
||||
fn main() {
|
||||
let frames = get_all_frames("../video/frames/");
|
||||
|
@ -57,8 +56,8 @@ fn encode(frames: &[Frame]) -> Vec<u8> {
|
|||
enc::rle_diff_horizontal,
|
||||
enc::rle_diff_vertical,
|
||||
enc::bg_strips_horizontal,
|
||||
enc::cell_diff_8_vertical,
|
||||
];
|
||||
let max_error = 0;
|
||||
|
||||
let mut last_frame = FRAME_0;
|
||||
for (i, frame) in frames.iter().enumerate() {
|
||||
|
@ -68,7 +67,7 @@ fn encode(frames: &[Frame]) -> Vec<u8> {
|
|||
let decode = get_matching_decoder(encoded.encoding);
|
||||
let decoded = decode(&last_frame, &encoded.data, &mut 0);
|
||||
let error = frame_error(frame, &decoded);
|
||||
if error <= MAX_ERROR {
|
||||
if error <= max_error {
|
||||
options.push(encoded);
|
||||
} else {
|
||||
// dbg!(&encoded);
|
||||
|
@ -110,7 +109,7 @@ enum Encoding {
|
|||
// QuadTree,
|
||||
// DrawCommands,
|
||||
// CellDiff8H,
|
||||
CellDiff8V,
|
||||
// CellDiff8V,
|
||||
// CellDiff4HH,
|
||||
// CellDiff4HV,
|
||||
// CellDiff4VH,
|
||||
|
@ -130,7 +129,7 @@ fn get_matching_decoder(encoding: Encoding) -> FrameDecoder {
|
|||
// Encoding::QuadTree => todo!(),
|
||||
// Encoding::DrawCommands => todo!(),
|
||||
// Encoding::CellDiff8H => todo!(),
|
||||
Encoding::CellDiff8V => dec::cell_diff_8_vertical,
|
||||
// Encoding::CellDiff8V => todo!(),
|
||||
// Encoding::CellDiff4HH => todo!(),
|
||||
// Encoding::CellDiff4HV => todo!(),
|
||||
// Encoding::CellDiff4VH => todo!(),
|
||||
|
|
Loading…
Reference in a new issue