diff --git a/src/main.rs b/src/main.rs index dea159e..0da8d3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,8 @@ const A5X_WIDTH: usize = 1404; const A5X_HEIGHT: usize = 1872; const A5X2_WIDTH: usize = 1920; const A5X2_HEIGHT: usize = 2560; +const A6X2_WIDTH: usize = 1404; +const A6X2_HEIGHT: usize = 1872; // precompile regex lazy_static! { @@ -127,11 +129,14 @@ fn detect_device_dimensions(file: &mut File, footer_map: &HashMap() { let header_map = parse_metadata_block(file, header_addr)?; if let Some(equipment) = header_map.get("APPLY_EQUIPMENT") { - if equipment == "N5" { - return Ok((A5X2_WIDTH, A5X2_HEIGHT)); - } else { - return Ok((A5X_WIDTH, A5X_HEIGHT)); - } + return match equipment.as_str() { + // A5 X2 (Manta) + "N5" => Ok((A5X2_WIDTH, A5X2_HEIGHT)), + // A6 X2 (Nomad) + "N6" => Ok((A6X2_WIDTH, A6X2_HEIGHT)), + // A5X / A6X and fallback devices currently share this size. + _ => Ok((A5X_WIDTH, A5X_HEIGHT)), + }; } } } @@ -203,6 +208,17 @@ fn parse_notebook(file: &mut File) -> Result { }) } +fn adjust_rle_tail_length(tail_length: u8, current_length: usize, total_length: usize) -> usize { + let gap = total_length.saturating_sub(current_length); + for shift in (0..8).rev() { + let candidate = (((tail_length & 0x7f) as usize) + 1) << shift; + if candidate <= gap { + return candidate; + } + } + 0 +} + /// Decodes a byte stream compressed with the RATTA_RLE algorithm. fn decode_rle(compressed_data: &[u8], width: usize, height: usize) -> Result> { // Screen dimensions @@ -221,43 +237,45 @@ fn decode_rle(compressed_data: &[u8], width: usize, height: usize) -> Result 0 { decompressed.extend(std::iter::repeat(color_code).take(tail_length)); }