diff --git a/src/mappings.rs b/src/mappings.rs index 6386126..654adb3 100644 --- a/src/mappings.rs +++ b/src/mappings.rs @@ -4,6 +4,8 @@ use crate::lib8::scale8; use std::cmp::max; use std::fmt::{Formatter, Debug}; +use ansi_term::Color; +use rgb::Rgb; pub trait CoordinateView: Debug { fn next(&mut self) -> Option<(VirtualCoordinates, PhysicalCoordinates)>; @@ -13,6 +15,43 @@ pub trait PixelMapping> { fn select(&self, rect: &Rectangle) -> impl CoordinateView; } +pub trait DisplayDump, CoordData: CoordLimits> { + fn dump(&self, map: &T); +} + +impl DisplayDump for [Rgb; PIXEL_NUM] { + fn dump(&self, _map: &LinearPixelMapping) { + for ref pixel in self { + print!("{}", Color::RGB(pixel.r, pixel.g, pixel.b).paint("█")); + } + println!(); + } +} + +impl DisplayDump for [Rgb; PIXEL_NUM] { + fn dump(&self, map: &StrideMapping) { + for y in 0..map.stride_count { + let stride = &map.strides[y]; + for x in 0..stride.length { + let idx = if stride.reverse { + stride.physical_idx + stride.length as usize - x as usize + } else { + stride.physical_idx + x as usize + }; + if idx >= self.len() { + println!(); + println!("frame!!!"); + return; + } + let pixel = &self[idx]; + print!("{}", Color::RGB(pixel.r, pixel.g, pixel.b).paint("█")); + } + println!(); + } + println!("frame!!!"); + } +} + #[derive(Debug)] struct LinearCoordView { rect: Rectangle,