implement ch32v003 decoder

This commit is contained in:
Crispy 2024-04-12 22:26:24 +02:00
parent dc26664372
commit 0e95a0a1bb
9 changed files with 2082 additions and 4 deletions

View file

@ -10,7 +10,7 @@ pub use util::*;
const INSPECT_ENC: bool = false;
const INSPECT_DEC: bool = false;
const MAX_ERROR: usize = 4; // max wrong pixels
const MAX_ERROR: usize = 0; // max wrong pixels
const MAX_LOSS: usize = 16; // highest "loss" value tried for all lossy encodings
const LOSSLESS_ENCODINGS: &[FrameEncoder] = &[
@ -43,7 +43,7 @@ fn main() {
last_frame = decoder(&last_frame, &encoded[reader..], &mut reader);
if INSPECT_DEC {
println!(
"\n{frame_type:?}, error: {}",
"\n{frame_type:?}, error: {}, index: {frame_index}",
frame_error(&frames[frame_index], &last_frame)
);
render_images(&frames[frame_index], &last_frame);
@ -63,7 +63,12 @@ fn main() {
);
let mut export_string = String::from("// Generated by the `encoder` rust app\n");
export_string += "typedef enum Encoding {\n";
for (encoding, count) in stats {
if count > 0 {
export_string += &format!("#define USE_{encoding:?}\n");
}
}
export_string += "\n\ntypedef enum Encoding {\n";
for (encoding, count) in stats {
if count > 0 {
export_string += &format!("\tEncoding_{encoding:?} = {},\n", encoding as u8);
@ -117,7 +122,7 @@ fn encode(frames: &[Frame]) -> Vec<u8> {
// render_images(&frame, &decoded);
// panic!("error in 'loss 0' compression");
// }
if error < MAX_ERROR {
if error <= MAX_ERROR {
options.push(encoded);
} else {
// higher loss value will mean more error so can be skipped