Skip to content

Commit

Permalink
enhancement: cleanup building of QR Versions using a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed Jan 31, 2024
1 parent 2248fb2 commit 20c61c9
Show file tree
Hide file tree
Showing 2 changed files with 603 additions and 1,550 deletions.
36 changes: 12 additions & 24 deletions src/qrcode/decoder/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,29 @@ impl Version {
}
}

pub(super) fn new_micro(versionNumber: u32, ecBlocks: Vec<ECBlocks>) -> Self {
pub(super) fn without_alignment_patterns(versionNumber: u32, ecBlocks: Vec<ECBlocks>) -> Self {
let mut total = 0;
let ecCodewords = ecBlocks[0].getECCodewordsPerBlock();
let ecbArray = ecBlocks[0].getECBlocks();
let mut i = 0;
while i < ecbArray.len() {
total += ecbArray[i].getCount() * (ecbArray[i].getDataCodewords() + ecCodewords);
i += 1;
for ecb_array_element in ecbArray {
total +=
ecb_array_element.getCount() * (ecb_array_element.getDataCodewords() + ecCodewords);
}

Self {
versionNumber,
alignmentPatternCenters: Vec::default(),
ecBlocks,
totalCodewords: total,
qr_type: Type::Micro,
}
}

pub(super) fn new_model1(versionNumber: u32, ecBlocks: Vec<ECBlocks>) -> Self {
let mut total = 0;
let ecCodewords = ecBlocks[0].getECCodewordsPerBlock();
let ecbArray = ecBlocks[0].getECBlocks();
let mut i = 0;
while i < ecbArray.len() {
total += ecbArray[i].getCount() * (ecbArray[i].getDataCodewords() + ecCodewords);
i += 1;
}
let symbol_type = if ecBlocks[0].getECCodewordsPerBlock() < 7
|| ecBlocks[0].getECCodewordsPerBlock() == 8
{
Type::Micro
} else {
Type::Model1
};

Self {
versionNumber,
alignmentPatternCenters: Vec::default(),
ecBlocks,
totalCodewords: total,
qr_type: Type::Model1,
qr_type: symbol_type,
}
}

Expand Down
Loading

0 comments on commit 20c61c9

Please sign in to comment.