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

@@ -82,7 +82,7 @@ impl BitMatrixParser {
let dimension = self.bitMatrix.getHeight();
let mut formatInfoBits2 = 0;
let jMin = dimension - 7;
for j in (jMin..=dimension).rev() {
for j in (jMin..=dimension-1).rev() {
// for (int j = dimension - 1; j >= jMin; j--) {
formatInfoBits2 = self.copyBit(8, j, formatInfoBits2);
}
@@ -194,7 +194,7 @@ impl BitMatrixParser {
let mut currentByte = 0;
let mut bitsRead = 0;
// Read columns in pairs, from right to left
let mut j = dimension - 1;
let mut j = dimension as i32 - 1;
while j > 0 {
// for (int j = dimension - 1; j > 0; j -= 2) {
if j == 6 {
@@ -213,11 +213,11 @@ impl BitMatrixParser {
for col in 0..2 {
// for (int col = 0; col < 2; col++) {
// Ignore bits covered by the function pattern
if !functionPattern.get(j - col, i) {
if !functionPattern.get(j as u32 - col, i) {
// Read a bit
bitsRead += 1;
currentByte <<= 1;
if self.bitMatrix.get(j - col, i) {
if self.bitMatrix.get(j as u32 - col, i) {
currentByte |= 1;
}
// If we've made a whole byte, save it off

View File

@@ -80,7 +80,8 @@ impl DataBlock {
// for (int i = 0; i < ecBlock.getCount(); i++) {
let numDataCodewords = ecBlock.getDataCodewords();
let numBlockCodewords = ecBlocks.getECCodewordsPerBlock() + numDataCodewords;
result[numRXingResultBlocks] = DataBlock::new(numDataCodewords, vec![0u8;numBlockCodewords as usize]);
// result[numRXingResultBlocks] = DataBlock::new(numDataCodewords, vec![0u8;numBlockCodewords as usize]);
result.push( DataBlock::new(numDataCodewords, vec![0u8;numBlockCodewords as usize]));
numRXingResultBlocks += 1;
}
}

View File

@@ -14,6 +14,8 @@
* limitations under the License.
*/
use std::str::FromStr;
use crate::Exceptions;
/**
@@ -85,6 +87,33 @@ impl From<ErrorCorrectionLevel> for u8 {
}
}
impl FromStr for ErrorCorrectionLevel {
type Err=Exceptions;
fn from_str(s: &str) -> Result<Self, Self::Err> {
// First try to see if the string is just the name of the value
let as_str = match s.to_uppercase().as_str() {
"L" => Some(ErrorCorrectionLevel::L),
"M" => Some(ErrorCorrectionLevel::M),
"Q" =>Some(ErrorCorrectionLevel::Q),
"H" =>Some(ErrorCorrectionLevel::H),
_ => None,
};
// If we find something, cool, return it, otherwise keep trying as numbers
if as_str.is_some() {
return Ok(as_str.unwrap());
}
let number_possible = s.parse::<u8>();
if number_possible.is_ok() {
return number_possible.unwrap().try_into();
}
return Err(Exceptions::IllegalArgumentException(format!("could not parse {} into an ec level", s)))
}
}
//private static final ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
//private final int bits;

View File

@@ -45,6 +45,7 @@ const VERSION_DECODE_INFO: [u32; 34] = [
*
* @author Sean Owen
*/
#[derive(Debug)]
pub struct Version {
// private static final Version[] VERSIONS = buildVersions();
versionNumber: u32,
@@ -930,7 +931,8 @@ impl fmt::Display for Version {
* each set of blocks. It also holds the number of error-correction codewords per block since it
* will be the same across all blocks within one version.</p>
*/
pub struct ECBlocks {
#[derive(Debug)]
pub struct ECBlocks {
ecCodewordsPerBlock: u32,
ecBlocks: Vec<ECB>,
}
@@ -970,6 +972,7 @@ impl ECBlocks {
* This includes the number of data codewords, and the number of times a block with these
* parameters is used consecutively in the QR code version's format.</p>
*/
#[derive(Debug)]
pub struct ECB {
count: u32,
dataCodewords: u32,