enhancement: cleanup building of QR Versions using a macro

This commit is contained in:
Henry Schimke
2024-01-31 11:23:13 -06:00
parent 2248fb28f6
commit 20c61c9c13
2 changed files with 604 additions and 1551 deletions

View File

@@ -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 mut total = 0;
let ecCodewords = ecBlocks[0].getECCodewordsPerBlock(); let ecCodewords = ecBlocks[0].getECCodewordsPerBlock();
let ecbArray = ecBlocks[0].getECBlocks(); let ecbArray = ecBlocks[0].getECBlocks();
let mut i = 0; for ecb_array_element in ecbArray {
while i < ecbArray.len() { total +=
total += ecbArray[i].getCount() * (ecbArray[i].getDataCodewords() + ecCodewords); ecb_array_element.getCount() * (ecb_array_element.getDataCodewords() + ecCodewords);
i += 1;
} }
let symbol_type = if ecBlocks[0].getECCodewordsPerBlock() < 7
|| ecBlocks[0].getECCodewordsPerBlock() == 8
{
Type::Micro
} else {
Type::Model1
};
Self { Self {
versionNumber, versionNumber,
alignmentPatternCenters: Vec::default(), alignmentPatternCenters: Vec::default(),
ecBlocks, ecBlocks,
totalCodewords: total, totalCodewords: total,
qr_type: Type::Micro, qr_type: symbol_type,
}
}
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;
}
Self {
versionNumber,
alignmentPatternCenters: Vec::default(),
ecBlocks,
totalCodewords: total,
qr_type: Type::Model1,
} }
} }

File diff suppressed because it is too large Load Diff