mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
add ReadMQRCodewords
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitMatrix, Result},
|
common::{BitMatrix, Result},
|
||||||
qrcode::decoder::{FormatInformation, Version, VersionRef},
|
qrcode::decoder::{ErrorCorrectionLevel, FormatInformation, Version, VersionRef},
|
||||||
Exceptions,
|
Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -176,49 +176,67 @@ pub fn ReadMQRCodewords(
|
|||||||
version: VersionRef,
|
version: VersionRef,
|
||||||
formatInfo: &FormatInformation,
|
formatInfo: &FormatInformation,
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
todo!()
|
let functionPattern = version.buildFunctionPattern()?;
|
||||||
// BitMatrix functionPattern = version.buildFunctionPattern();
|
|
||||||
|
|
||||||
// // D3 in a Version M1 symbol, D11 in a Version M3-L symbol and D9
|
// D3 in a Version M1 symbol, D11 in a Version M3-L symbol and D9
|
||||||
// // in a Version M3-M symbol is a 2x2 square 4-module block.
|
// in a Version M3-M symbol is a 2x2 square 4-module block.
|
||||||
// // See ISO 18004:2006 6.7.3.
|
// See ISO 18004:2006 6.7.3.
|
||||||
// bool hasD4mBlock = version.versionNumber() % 2 == 1;
|
let hasD4mBlock = version.getVersionNumber() % 2 == 1;
|
||||||
// int d4mBlockIndex =
|
let d4mBlockIndex = if version.getVersionNumber() == 1 {
|
||||||
// version.versionNumber() == 1 ? 3 : (formatInfo.ecLevel == QRCode::ErrorCorrectionLevel::Low ? 11 : 9);
|
3
|
||||||
|
} else {
|
||||||
|
(if formatInfo.error_correction_level == ErrorCorrectionLevel::L {
|
||||||
|
11
|
||||||
|
} else {
|
||||||
|
9
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// ByteArray result;
|
let mut result = Vec::new();
|
||||||
// result.reserve(version.totalCodewords());
|
result.reserve(version.getTotalCodewords() as usize);
|
||||||
// uint8_t currentByte = 0;
|
let mut currentByte = 0;
|
||||||
// bool readingUp = true;
|
let mut readingUp = true;
|
||||||
// int bitsRead = 0;
|
let mut bitsRead = 0;
|
||||||
// int dimension = bitMatrix.height();
|
let dimension = bitMatrix.height();
|
||||||
// // Read columns in pairs, from right to left
|
// Read columns in pairs, from right to left
|
||||||
// for (int x = dimension - 1; x > 0; x -= 2) {
|
let mut x = dimension - 1;
|
||||||
// // Read alternatingly from bottom to top then top to bottom
|
while x > 0 {
|
||||||
// for (int row = 0; row < dimension; row++) {
|
// for (int x = dimension - 1; x > 0; x -= 2) {
|
||||||
// int y = readingUp ? dimension - 1 - row : row;
|
// Read alternatingly from bottom to top then top to bottom
|
||||||
// for (int col = 0; col < 2; col++) {
|
for row in 0..dimension {
|
||||||
// int xx = x - col;
|
// for (int row = 0; row < dimension; row++) {
|
||||||
// // Ignore bits covered by the function pattern
|
let y = if readingUp { dimension - 1 - row } else { row };
|
||||||
// if (!functionPattern.get(xx, y)) {
|
for col in 0..2 {
|
||||||
// // Read a bit
|
// for (int col = 0; col < 2; col++) {
|
||||||
// AppendBit(currentByte,
|
let xx = x - col;
|
||||||
// GetDataMaskBit(formatInfo.dataMask, xx, y, true) != getBit(bitMatrix, xx, y, formatInfo.isMirrored));
|
// Ignore bits covered by the function pattern
|
||||||
// ++bitsRead;
|
if (!functionPattern.get(xx, y)) {
|
||||||
// // If we've made a whole byte, save it off; save early if 2x2 data block.
|
// Read a bit
|
||||||
// if (bitsRead == 8 || (bitsRead == 4 && hasD4mBlock && Size(result) == d4mBlockIndex - 1)) {
|
AppendBit(
|
||||||
// result.push_back(std::exchange(currentByte, 0));
|
&mut currentByte,
|
||||||
// bitsRead = 0;
|
GetDataMaskBit(formatInfo.data_mask as u32, xx, y, Some(true))
|
||||||
// }
|
!= getBit(bitMatrix, xx, y, Some(formatInfo.isMirrored)),
|
||||||
// }
|
);
|
||||||
// }
|
bitsRead += 1;
|
||||||
// }
|
// If we've made a whole byte, save it off; save early if 2x2 data block.
|
||||||
// readingUp = !readingUp; // switch directions
|
if (bitsRead == 8
|
||||||
// }
|
|| (bitsRead == 4 && hasD4mBlock && (result.len()) == d4mBlockIndex - 1))
|
||||||
// if (Size(result) != version.totalCodewords())
|
{
|
||||||
// return {};
|
result.push(std::mem::take(&mut currentByte));
|
||||||
|
bitsRead = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
readingUp = !readingUp; // switch directions
|
||||||
|
|
||||||
// return result;
|
x -= 2;
|
||||||
|
}
|
||||||
|
if ((result.len()) != version.getTotalCodewords() as usize) {
|
||||||
|
return Err(Exceptions::FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result.iter().copied().map(|x| x as u8).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ReadCodewords(
|
pub fn ReadCodewords(
|
||||||
|
|||||||
Reference in New Issue
Block a user