start work on 320x240 screen version using the pi pico

This commit is contained in:
Crispy 2025-06-16 19:39:07 +02:00
parent 8acd684e59
commit 90f648e0b0
13 changed files with 112280 additions and 20 deletions

View file

@ -1,6 +1,6 @@
use crate::*;
pub fn cell_diff_4_vertical(prev_frame: &Frame, frame: &Frame, loss: usize) -> EncodedFrame {
pub fn cell_diff_4_vertical_small(prev_frame: &Frame, frame: &Frame, loss: usize) -> EncodedFrame {
let loss = loss / 4;
const CELLS_X: usize = WIDTH / 4;
const CELLS_Y: usize = HEIGHT / 4;
@ -48,11 +48,64 @@ pub fn cell_diff_4_vertical(prev_frame: &Frame, frame: &Frame, loss: usize) -> E
data.extend_from_slice(&rle_255_encode(&changed_pixels));
EncodedFrame {
encoding: Encoding::CellDiff4VV,
encoding: Encoding::CellDiff4VV_small,
data,
}
}
// pub fn cell_diff_4_vertical_large(prev_frame: &Frame, frame: &Frame, loss: usize) -> EncodedFrame {
// let loss = loss / 4;
// const CELLS_X: usize = WIDTH / 4;
// const CELLS_Y: usize = HEIGHT / 4;
// let mut modified_cells = [[0; CELLS_Y]; CELLS_X];
// for cellx in 0..CELLS_X {
// for celly in 0..CELLS_Y {
// let mut changed = 0;
// for dx in 0..4 {
// for dy in 0..4 {
// let x = cellx * 4 + dx;
// let y = celly * 4 + dy;
// let pixel = frame[x][y];
// if pixel != prev_frame[x][y] {
// changed += 1;
// }
// }
// }
// if changed > loss {
// modified_cells[cellx][celly] = 1;
// }
// }
// }
// let mut changed_pixels = Vec::new();
// for x in 0..WIDTH {
// for y in 0..HEIGHT {
// let cellx = x / 4;
// let celly = y / 4;
// if modified_cells[cellx][celly] != 0 {
// changed_pixels.push(frame[x][y]);
// }
// }
// }
// let mut modified_cells_flat = Vec::new();
// for x in 0..CELLS_X {
// for y in 0..CELLS_Y {
// modified_cells_flat.push(modified_cells[x][y]);
// }
// }
// let mut data = Vec::new();
// data.extend_from_slice(&pack_nybbles(rle_encode(&modified_cells_flat, 15)));
// data.extend_from_slice(&rle_255_encode(&changed_pixels));
// EncodedFrame {
// encoding: Encoding::CellDiff4VV_large,
// data,
// }
// }
pub fn cell_diff_8_vertical(prev_frame: &Frame, frame: &Frame, loss: usize) -> EncodedFrame {
const CELLS_X: usize = WIDTH / 8;
const CELLS_Y: usize = HEIGHT / 8;
@ -97,7 +150,8 @@ pub fn cell_diff_8_vertical(prev_frame: &Frame, frame: &Frame, loss: usize) -> E
}
}
pub fn bg_strips_horizontal(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
// meant for 42x32 mode
pub fn bg_strips_horizontal_16(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
let bg = most_common_pixel(frame);
fn pack_strip(x: usize, y: usize, width: usize) -> [u8; 2] {
// Y is 0..31 so will only need 5 bits
@ -145,7 +199,57 @@ pub fn bg_strips_horizontal(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame
frame_bytes.extend_from_slice(&pack_strip(x, y, width));
}
EncodedFrame {
encoding: Encoding::BGStripsH,
encoding: Encoding::BGStripsH16,
data: frame_bytes,
}
}
// meant for 320x240 mode
pub fn bg_strips_horizontal_24(_prev_frame: &Frame, frame: &Frame) -> EncodedFrame {
let bg = most_common_pixel(frame);
fn pack_strip(x: usize, y: usize, width: usize) -> [u8; 3] {
// Y is 0..240 so will need 8 bits
// x is 0..320 so needs 9 bits
// 7 bits remain for width
let x_width = ((x >> 1) & 0x80) as u8 | (width as u8);
[y as u8, (x & 0xff) as u8, x_width]
}
let mut strips = Vec::new();
'outer: for y in 0..HEIGHT {
let mut strip_start = 0;
let mut in_strip = false;
for x in 0..WIDTH {
let pixel = frame[x][y];
if !in_strip && pixel != bg {
in_strip = true;
strip_start = x;
}
if in_strip {
if pixel == bg {
strips.push((strip_start, y, x - strip_start));
in_strip = false;
} else if x - strip_start == 127 {
strips.push((strip_start, y, x - strip_start));
strip_start = x;
}
// if strips.len() == MAX_STRIPS {
// break 'outer;
// }
}
}
if in_strip {
strips.push((strip_start, y, WIDTH - strip_start));
}
}
let mut frame_bytes = Vec::with_capacity(2 + strips.len() * 2);
frame_bytes.push(bg << 7 | ((strips.len() >> 8) as u8));
frame_bytes.push(strips.len() as u8);
for (x, y, width) in strips {
frame_bytes.extend_from_slice(&pack_strip(x, y, width));
}
EncodedFrame {
encoding: Encoding::BGStripsH24,
data: frame_bytes,
}
}