mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
more todo!() removal
This commit is contained in:
@@ -16,6 +16,16 @@ use crate::Exceptions;
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
impl Version {
|
impl Version {
|
||||||
|
pub fn FromDimension(dimension: u32) -> Result<VersionRef> {
|
||||||
|
todo!()
|
||||||
|
// bool isMicro = dimension < 21;
|
||||||
|
// if (dimension % DimensionStep(isMicro) != 1) {
|
||||||
|
// //throw std::invalid_argument("Unexpected dimension");
|
||||||
|
// return nullptr;
|
||||||
|
// }
|
||||||
|
// return FromNumber((dimension - DimensionOffset(isMicro)) / DimensionStep(isMicro), isMicro);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 {
|
pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 {
|
||||||
Self::DimensionOffset(is_micro) + Self::DimensionStep(is_micro) * version
|
Self::DimensionOffset(is_micro) + Self::DimensionStep(is_micro) * version
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ use crate::{
|
|||||||
Exceptions,
|
Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::detector::AppendBit;
|
||||||
|
|
||||||
pub fn getBit(bitMatrix: &BitMatrix, x: u32, y: u32, mirrored: Option<bool>) -> bool {
|
pub fn getBit(bitMatrix: &BitMatrix, x: u32, y: u32, mirrored: Option<bool>) -> bool {
|
||||||
let mirrored = mirrored.unwrap_or(false);
|
let mirrored = mirrored.unwrap_or(false);
|
||||||
if mirrored {
|
if mirrored {
|
||||||
@@ -29,27 +31,33 @@ pub fn hasValidDimension(bitMatrix: &BitMatrix, isMicro: bool) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ReadVersion(bitMatrix: &BitMatrix) -> Result<VersionRef> {
|
pub fn ReadVersion(bitMatrix: &BitMatrix) -> Result<VersionRef> {
|
||||||
todo!()
|
let dimension = bitMatrix.height();
|
||||||
// int dimension = bitMatrix.height();
|
|
||||||
|
|
||||||
// const Version* version = Version::FromDimension(dimension);
|
let mut version = Version::FromDimension(dimension)?;
|
||||||
|
|
||||||
// if (!version || version->versionNumber() < 7)
|
if (version.getVersionNumber() < 7) {
|
||||||
// return version;
|
return Ok(version);
|
||||||
|
}
|
||||||
|
|
||||||
// for (bool mirror : {false, true}) {
|
for mirror in [false, true] {
|
||||||
// // Read top-right/bottom-left version info: 3 wide by 6 tall (depending on mirrored)
|
// for (bool mirror : {false, true}) {
|
||||||
// int versionBits = 0;
|
// Read top-right/bottom-left version info: 3 wide by 6 tall (depending on mirrored)
|
||||||
// for (int y = 5; y >= 0; --y)
|
let mut versionBits = 0;
|
||||||
// for (int x = dimension - 9; x >= dimension - 11; --x)
|
for y in (0..=5).rev() {
|
||||||
// AppendBit(versionBits, getBit(bitMatrix, x, y, mirror));
|
// for (int y = 5; y >= 0; --y) {
|
||||||
|
for x in ((dimension - 11)..=(dimension - 9)).rev() {
|
||||||
|
// for (int x = dimension - 9; x >= dimension - 11; --x) {
|
||||||
|
AppendBit(&mut versionBits, getBit(bitMatrix, x, y, Some(mirror)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// version = Version::DecodeVersionInformation(versionBits);
|
version = Version::DecodeVersionInformation(versionBits, 0)?; // THIS MIGHT BE WRONG todo!()
|
||||||
// if (version && version->dimension() == dimension)
|
if (version.getDimensionForVersion() == dimension) {
|
||||||
// return version;
|
return Ok(version);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return nullptr;
|
return Err(Exceptions::FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result<FormatInformation> {
|
pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result<FormatInformation> {
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ pub fn ReadVersion(
|
|||||||
Version::DecodeVersionInformation(bits[0], bits[1])
|
Version::DecodeVersionInformation(bits[0], bits[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn AppendBit(val: &mut i32, bit: bool) {
|
pub fn AppendBit(val: &mut i32, bit: bool) {
|
||||||
*val <<= 1;
|
*val <<= 1;
|
||||||
|
|
||||||
*val |= i32::from(bit)
|
*val |= i32::from(bit)
|
||||||
|
|||||||
@@ -167,7 +167,34 @@ impl Mode {
|
|||||||
* count of characters that will follow encoded in this Mode
|
* count of characters that will follow encoded in this Mode
|
||||||
*/
|
*/
|
||||||
pub fn CharacterCountBits(&self, version: &Version) -> u32 {
|
pub fn CharacterCountBits(&self, version: &Version) -> u32 {
|
||||||
todo!()
|
let number = version.getVersionNumber() as usize;
|
||||||
|
if (version.isMicroQRCode()) {
|
||||||
|
match (self) {
|
||||||
|
Mode::NUMERIC=> return [3, 4, 5, 6][number - 1],
|
||||||
|
Mode::ALPHANUMERIC=> return [3, 4, 5][number - 2],
|
||||||
|
Mode::BYTE=> return [4, 5][number - 3],
|
||||||
|
Mode::KANJI | //=> [[fallthrough]],
|
||||||
|
Mode::HANZI=> return [3, 4][number - 3],
|
||||||
|
_=> return 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = if (number <= 9) {
|
||||||
|
0
|
||||||
|
} else if (number <= 26) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
2
|
||||||
|
};
|
||||||
|
|
||||||
|
match (self) {
|
||||||
|
Mode::NUMERIC=> return [10, 12, 14][i],
|
||||||
|
Mode::ALPHANUMERIC=> return [9, 11, 13][i],
|
||||||
|
Mode::BYTE=> return [8, 16, 16][i],
|
||||||
|
Mode::KANJI| // [[fallthrough]];
|
||||||
|
Mode::HANZI=> return [8, 10, 12][i],
|
||||||
|
_=> return 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user