qr_code partially working

This commit is contained in:
Henry Schimke
2022-10-09 22:01:36 -05:00
parent 50a675c693
commit 79aafa200d
26 changed files with 839 additions and 604 deletions

View File

@@ -16,6 +16,8 @@
use std::fmt;
use crate::common::BitMatrix;
/**
* JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
* -1, 0, and 1, I'm going to use less memory and go with bytes.
@@ -110,3 +112,17 @@ impl fmt::Display for ByteMatrix {
write!(f, "{}", result)
}
}
impl From<ByteMatrix> for BitMatrix {
fn from(bm: ByteMatrix) -> Self {
let mut bit_matrix = BitMatrix::new(bm.getWidth(), bm.getHeight()).unwrap();
for y in 0..bm.getHeight() {
for x in 0..bm.getWidth() {
if bm.get(x, y) > 0 {
bit_matrix.set(x as u32, y as u32);
}
}
}
bit_matrix
}
}