mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-25 20:02:34 +00:00
data_mask.rs added
This commit is contained in:
@@ -149,7 +149,7 @@ pub fn ReadQRCodewords(
|
|||||||
// Read a bit
|
// Read a bit
|
||||||
AppendBit(
|
AppendBit(
|
||||||
&mut currentByte,
|
&mut currentByte,
|
||||||
GetDataMaskBit(formatInfo.data_mask as u32, xx, y, None)
|
GetDataMaskBit(formatInfo.data_mask as u32, xx, y, None)?
|
||||||
!= getBit(bitMatrix, xx, y, Some(formatInfo.isMirrored)),
|
!= getBit(bitMatrix, xx, y, Some(formatInfo.isMirrored)),
|
||||||
);
|
);
|
||||||
// If we've made a whole byte, save it off
|
// If we've made a whole byte, save it off
|
||||||
@@ -214,7 +214,7 @@ pub fn ReadMQRCodewords(
|
|||||||
// Read a bit
|
// Read a bit
|
||||||
AppendBit(
|
AppendBit(
|
||||||
&mut currentByte,
|
&mut currentByte,
|
||||||
GetDataMaskBit(formatInfo.data_mask as u32, xx, y, Some(true))
|
GetDataMaskBit(formatInfo.data_mask as u32, xx, y, Some(true))?
|
||||||
!= getBit(bitMatrix, xx, y, Some(formatInfo.isMirrored)),
|
!= getBit(bitMatrix, xx, y, Some(formatInfo.isMirrored)),
|
||||||
);
|
);
|
||||||
bitsRead += 1;
|
bitsRead += 1;
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::common::BitMatrix;
|
use crate::common::BitMatrix;
|
||||||
|
use crate::common::Result;
|
||||||
|
use crate::Exceptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Encapsulates data masks for the data bits in a QR and micro QR code, per ISO 18004:2006 6.8.</p>
|
* <p>Encapsulates data masks for the data bits in a QR and micro QR code, per ISO 18004:2006 6.8.</p>
|
||||||
@@ -13,27 +15,33 @@ use crate::common::BitMatrix;
|
|||||||
* and j is row position. In fact, as the text says, i is row position and j is column position.</p>
|
* and j is row position. In fact, as the text says, i is row position and j is column position.</p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn GetDataMaskBit(maskIndex: u32, x: u32, y: u32, isMicro: Option<bool>) -> bool {
|
pub fn GetDataMaskBit(maskIndex: u32, x: u32, y: u32, isMicro: Option<bool>) -> Result<bool> {
|
||||||
let isMicro = isMicro.unwrap_or(false);
|
let isMicro = isMicro.unwrap_or(false);
|
||||||
todo!()
|
let mut maskIndex = maskIndex;
|
||||||
// if (isMicro) {
|
if (isMicro) {
|
||||||
// if (maskIndex < 0 || maskIndex >= 4)
|
if (maskIndex < 0 || maskIndex >= 4) {
|
||||||
// throw std::invalid_argument("QRCode maskIndex out of range");
|
return Err(Exceptions::illegal_argument_with(
|
||||||
// maskIndex = std::array{1, 4, 6, 7}[maskIndex]; // map from MQR to QR indices
|
"QRCode maskIndex out of range",
|
||||||
// }
|
));
|
||||||
|
}
|
||||||
|
maskIndex = [1, 4, 6, 7][maskIndex as usize]; // map from MQR to QR indices
|
||||||
|
}
|
||||||
|
|
||||||
// switch (maskIndex) {
|
match (maskIndex) {
|
||||||
// case 0: return (y + x) % 2 == 0;
|
0 => return Ok((y + x) % 2 == 0),
|
||||||
// case 1: return y % 2 == 0;
|
1 => return Ok(y % 2 == 0),
|
||||||
// case 2: return x % 3 == 0;
|
2 => return Ok(x % 3 == 0),
|
||||||
// case 3: return (y + x) % 3 == 0;
|
3 => return Ok((y + x) % 3 == 0),
|
||||||
// case 4: return ((y / 2) + (x / 3)) % 2 == 0;
|
4 => return Ok(((y / 2) + (x / 3)) % 2 == 0),
|
||||||
// case 5: return (y * x) % 6 == 0;
|
5 => return Ok((y * x) % 6 == 0),
|
||||||
// case 6: return ((y * x) % 6) < 3;
|
6 => return Ok(((y * x) % 6) < 3),
|
||||||
// case 7: return (y + x + ((y * x) % 3)) % 2 == 0;
|
7 => return Ok((y + x + ((y * x) % 3)) % 2 == 0),
|
||||||
// }
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
// throw std::invalid_argument("QRCode maskIndex out of range");
|
Err(Exceptions::illegal_argument_with(
|
||||||
|
"QRCode maskIndex out of range",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetMaskedBit(
|
pub fn GetMaskedBit(
|
||||||
@@ -42,6 +50,6 @@ pub fn GetMaskedBit(
|
|||||||
y: u32,
|
y: u32,
|
||||||
maskIndex: u32,
|
maskIndex: u32,
|
||||||
isMicro: Option<bool>,
|
isMicro: Option<bool>,
|
||||||
) -> bool {
|
) -> Result<bool> {
|
||||||
return GetDataMaskBit(maskIndex, x, y, isMicro) != bits.get(x, y);
|
Ok(GetDataMaskBit(maskIndex, x, y, isMicro)? != bits.get(x, y))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user