mappings: implement some debug traits for viewing pixbufs
This commit is contained in:
parent
291affc992
commit
3517428d54
@ -4,6 +4,8 @@ use crate::lib8::scale8;
|
|||||||
|
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::fmt::{Formatter, Debug};
|
use std::fmt::{Formatter, Debug};
|
||||||
|
use ansi_term::Color;
|
||||||
|
use rgb::Rgb;
|
||||||
|
|
||||||
pub trait CoordinateView: Debug {
|
pub trait CoordinateView: Debug {
|
||||||
fn next(&mut self) -> Option<(VirtualCoordinates, PhysicalCoordinates)>;
|
fn next(&mut self) -> Option<(VirtualCoordinates, PhysicalCoordinates)>;
|
||||||
@ -13,6 +15,43 @@ pub trait PixelMapping<CoordData: CoordLimits<Data = CoordData>> {
|
|||||||
fn select(&self, rect: &Rectangle<CoordData, Virtual>) -> impl CoordinateView;
|
fn select(&self, rect: &Rectangle<CoordData, Virtual>) -> impl CoordinateView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait DisplayDump<T: PixelMapping<CoordData>, CoordData: CoordLimits<Data = CoordData>> {
|
||||||
|
fn dump(&self, map: &T);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const PIXEL_NUM: usize> DisplayDump<LinearPixelMapping, u8> for [Rgb<u8>; PIXEL_NUM] {
|
||||||
|
fn dump(&self, _map: &LinearPixelMapping) {
|
||||||
|
for ref pixel in self {
|
||||||
|
print!("{}", Color::RGB(pixel.r, pixel.g, pixel.b).paint("█"));
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const PIXEL_NUM: usize> DisplayDump<StrideMapping, u8> for [Rgb<u8>; 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)]
|
#[derive(Debug)]
|
||||||
struct LinearCoordView {
|
struct LinearCoordView {
|
||||||
rect: Rectangle<u8, Virtual>,
|
rect: Rectangle<u8, Virtual>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user