more From for Cp437Grid and BitVec

This commit is contained in:
Vinzenz Schroeter 2024-11-12 21:38:49 +01:00
parent eb7496b27d
commit ab16f57292
5 changed files with 23 additions and 9 deletions

View file

@ -14,4 +14,4 @@ version = "0.10.0"
missing-docs = "warn" missing-docs = "warn"
[workspace.dependencies] [workspace.dependencies]
thiserror = "1.0.69" thiserror = "1.0.69"

View file

@ -42,10 +42,10 @@ fn main() {
} }
let text = cli.text.join("\n"); let text = cli.text.join("\n");
let grid = CharGrid::from(&*text); let grid = CharGrid::from(text);
let cp437_grid = Cp437Grid::from(&grid); let grid = Cp437Grid::from(grid);
connection connection
.send(Command::Cp437Data(Origin::ZERO, cp437_grid)) .send(Command::Cp437Data(Origin::ZERO, grid))
.expect("sending text failed"); .expect("sending text failed");
} }

View file

@ -33,12 +33,8 @@ fn main() {
enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false); enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false);
} }
// this works because the pixel grid has max size
let pixel_data: Vec<u8> = enabled_pixels.clone().into();
let bit_vec = BitVec::from_vec(pixel_data);
connection connection
.send(Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma)) .send(Command::BitmapLinearWin(Origin::ZERO, enabled_pixels.clone(), CompressionCode::Lzma))
.expect("could not send command to display"); .expect("could not send command to display");
thread::sleep(sleep_duration); thread::sleep(sleep_duration);
} }

View file

@ -175,6 +175,12 @@ impl From<Bitmap> for Vec<u8> {
} }
} }
impl From<Bitmap> for BitVec {
fn from(value: Bitmap) -> Self {
value.bit_vec
}
}
pub struct IterRows<'t> { pub struct IterRows<'t> {
bitmap: &'t Bitmap, bitmap: &'t Bitmap,
row: usize, row: usize,

View file

@ -141,6 +141,12 @@ mod feature_cp437 {
} }
} }
impl From<CharGrid> for Cp437Grid {
fn from(value: CharGrid) -> Self {
Cp437Grid::from(&value)
}
}
impl From<&str> for CharGrid { impl From<&str> for CharGrid {
fn from(value: &str) -> Self { fn from(value: &str) -> Self {
let value = value.replace("\r\n", "\n"); let value = value.replace("\r\n", "\n");
@ -166,6 +172,12 @@ mod feature_cp437 {
} }
} }
impl From<String> for CharGrid {
fn from(value: String) -> Self {
CharGrid::from(&value)
}
}
impl From<&CharGrid> for String { impl From<&CharGrid> for String {
fn from(value: &CharGrid) -> Self { fn from(value: &CharGrid) -> Self {
value value