diff --git a/src/video.rs b/src/video.rs index 4d989b5..a5ddeb8 100644 --- a/src/video.rs +++ b/src/video.rs @@ -106,15 +106,31 @@ pub struct Frame { pub dividers: Vec, } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct Capture { /// the colour table as the line capture has replayed it shadow: Vec, rows: Vec>, dividers: Vec, pub last_frame: Option, + /// The fork: `shadow` by pixel value, colour 0 of every palette already the backdrop or + /// overscan entry; empty when a palette write has made it stale. Not state. + #[serde(skip)] + shown: Vec, +} + +impl PartialEq for Capture { + fn eq(&self, other: &Capture) -> bool { + // not `shown`: it is derived from `shadow` + self.shadow == other.shadow + && self.rows == other.rows + && self.dividers == other.dividers + && self.last_frame == other.last_frame + } } +impl Eq for Capture {} + impl Capture { pub fn new(vce: &Vce) -> Capture { Capture { @@ -122,6 +138,7 @@ impl Capture { rows: Vec::new(), dividers: Vec::new(), last_frame: None, + shown: Vec::new(), } } @@ -144,18 +161,39 @@ impl Capture { let mut pending = 0; let shadow = &mut self.shadow; // The fork: with no palette write inside the row, which is nearly every line, the - // colour table is the same at every dot and no dot's time is needed. + // colour table is the same at every dot and no dot's time is needed; and the table is + // kept by pixel value (`shown`), colour 0 resolved, until a palette write. let split = if used == 0 { &row[..0] } else { row }; if used == 0 { - colours.extend(row.iter().map(|&pixel| { - // colour 0 of every palette shows the backdrop/overscan entry - let entry = if pixel & 0x0F == 0 { - pixel & 0x100 - } else { - pixel - }; - shadow[entry as usize] - })); + let shown = &mut self.shown; + if shown.len() != shadow.len() { + shown.clear(); + if shadow.len() > 0x100 { + shown.extend((0..shadow.len()).map(|pixel| { + // colour 0 of every palette shows the backdrop/overscan entry + shadow[if pixel & 0x0F == 0 { + pixel & 0x100 + } else { + pixel + }] + })); + } + } + if shown.is_empty() { + // (a colour table too short for the overscan entry: as the base board) + colours.extend(row.iter().map(|&pixel| { + let entry = if pixel & 0x0F == 0 { + pixel & 0x100 + } else { + pixel + }; + shadow[entry as usize] + })); + } else { + colours.extend(row.iter().map(|&pixel| shown[pixel as usize])); + } + } else { + self.shown.clear(); } for (x, &pixel) in split.iter().enumerate() { let when = first + x as i64 * div;