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
}
}

View File

@@ -16,7 +16,7 @@
use std::fmt;
use crate::qrcode::decoder::{Mode, ErrorCorrectionLevel, Version};
use crate::qrcode::decoder::{Mode, ErrorCorrectionLevel, Version, VersionRef};
use super::ByteMatrix;
@@ -25,13 +25,14 @@ use super::ByteMatrix;
* @author satorux@google.com (Satoru Takabayashi) - creator
* @author dswitkin@google.com (Daniel Switkin) - ported from C++
*/
#[derive(Debug, Clone)]
pub struct QRCode {
// public static final int NUM_MASK_PATTERNS = 8;
mode:Option<Mode>,
ecLevel:Option<ErrorCorrectionLevel>,
version:Option<&'static Version>,
version:Option<VersionRef>,
maskPattern:i32,
matrix:Option<ByteMatrix>,