porting formatinformation and eclevel

This commit is contained in:
Henry Schimke
2023-03-30 15:01:31 -05:00
parent 7f675137f2
commit 98e30a1d80
4 changed files with 114 additions and 25 deletions

View File

@@ -0,0 +1,27 @@
use crate::common::Result;
use crate::qrcode::decoder::ErrorCorrectionLevel;
impl ErrorCorrectionLevel {
pub fn ECLevelFromBits(bits: u8, isMicro: bool) -> Self {
if (isMicro) {
let LEVEL_FOR_BITS: [ErrorCorrectionLevel; 8] = [
ErrorCorrectionLevel::L,
ErrorCorrectionLevel::L,
ErrorCorrectionLevel::M,
ErrorCorrectionLevel::L,
ErrorCorrectionLevel::M,
ErrorCorrectionLevel::L,
ErrorCorrectionLevel::M,
ErrorCorrectionLevel::Q,
];
return LEVEL_FOR_BITS[bits as usize & 0x07];
}
let LEVEL_FOR_BITS: [ErrorCorrectionLevel; 4] = [
ErrorCorrectionLevel::M,
ErrorCorrectionLevel::L,
ErrorCorrectionLevel::H,
ErrorCorrectionLevel::Q,
];
return LEVEL_FOR_BITS[bits as usize & 0x3];
}
}