mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
continue removing todo!()s
This commit is contained in:
@@ -306,7 +306,7 @@ pub fn DecodeBitStream(
|
||||
mode = Mode::CodecModeForBits(
|
||||
bits.readBits(modeBitLength as usize)?,
|
||||
Some(version.isMicroQRCode()),
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
match (mode) {
|
||||
|
||||
@@ -123,10 +123,18 @@ impl Mode {
|
||||
}
|
||||
|
||||
pub const fn get_terminator_bit_length(version: &Version) -> u8 {
|
||||
todo!()
|
||||
(if version.isMicroQRCode() {
|
||||
version.getVersionNumber() * 2 + 1
|
||||
} else {
|
||||
4
|
||||
}) as u8
|
||||
}
|
||||
pub const fn get_codec_mode_bits_length(version: &Version) -> u8 {
|
||||
todo!()
|
||||
(if version.isMicroQRCode() {
|
||||
version.getVersionNumber() - 1
|
||||
} else {
|
||||
4
|
||||
}) as u8
|
||||
}
|
||||
/**
|
||||
* @param bits variable number of bits encoding a QR Code data mode
|
||||
@@ -134,9 +142,23 @@ impl Mode {
|
||||
* @return Mode encoded by these bits
|
||||
* @throws FormatError if bits do not correspond to a known mode
|
||||
*/
|
||||
pub fn CodecModeForBits(bits: u32, isMicro: Option<bool>) -> Self {
|
||||
pub fn CodecModeForBits(bits: u32, isMicro: Option<bool>) -> Result<Self> {
|
||||
let isMicro = isMicro.unwrap_or(false);
|
||||
todo!()
|
||||
const BITS_2_MODE_LEN: usize = 4;
|
||||
|
||||
if (!isMicro) {
|
||||
if ((bits >= 0x00 && bits <= 0x05) || (bits >= 0x07 && bits <= 0x09) || bits == 0x0d) {
|
||||
return Mode::try_from(bits);
|
||||
}
|
||||
} else {
|
||||
const Bits2Mode: [Mode; BITS_2_MODE_LEN] =
|
||||
[Mode::NUMERIC, Mode::ALPHANUMERIC, Mode::BYTE, Mode::KANJI];
|
||||
if ((bits as usize) < BITS_2_MODE_LEN) {
|
||||
return Ok(Bits2Mode[bits as usize]);
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::format_with("Invalid codec mode"))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,3 +184,11 @@ impl TryFrom<u8> for Mode {
|
||||
Self::forBits(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for Mode {
|
||||
type Error = Exceptions;
|
||||
|
||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||
Self::forBits(value as u8)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub struct Version {
|
||||
pub(crate) is_micro: bool,
|
||||
}
|
||||
impl Version {
|
||||
fn new(versionNumber: u32, alignmentPatternCenters: Vec<u32>, ecBlocks: [ECBlocks;4]) -> Self {
|
||||
fn new(versionNumber: u32, alignmentPatternCenters: Vec<u32>, ecBlocks: [ECBlocks; 4]) -> Self {
|
||||
let mut total = 0;
|
||||
let ecCodewords = ecBlocks[0].getECCodewordsPerBlock();
|
||||
let ecbArray = ecBlocks[0].getECBlocks();
|
||||
@@ -72,7 +72,7 @@ impl Version {
|
||||
alignmentPatternCenters,
|
||||
ecBlocks: ecBlocks.to_vec(),
|
||||
totalCodewords: total,
|
||||
is_micro: false
|
||||
is_micro: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ impl Version {
|
||||
alignmentPatternCenters: Vec::default(),
|
||||
ecBlocks,
|
||||
totalCodewords: total,
|
||||
is_micro: true
|
||||
is_micro: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getVersionNumber(&self) -> u32 {
|
||||
pub const fn getVersionNumber(&self) -> u32 {
|
||||
self.versionNumber
|
||||
}
|
||||
|
||||
@@ -203,19 +203,38 @@ impl Version {
|
||||
Ok(bitMatrix)
|
||||
}
|
||||
|
||||
pub fn build_micro_versions() -> Vec<Version> {
|
||||
vec![
|
||||
Version::new_micro(1, vec![ECBlocks::new(2, vec![ECB::new(1,3)])]),
|
||||
Version::new_micro(2, vec![ECBlocks::new(5, vec![ECB::new(1,5)]), ECBlocks::new(6, vec![ECB::new(1,4)])]),
|
||||
Version::new_micro(3, vec![ECBlocks::new(6, vec![ECB::new(1,11)]), ECBlocks::new(8, vec![ECB::new(1,9)])]),
|
||||
Version::new_micro(4, vec![ECBlocks::new(8, vec![ECB::new(1,16)]), ECBlocks::new(10, vec![ECB::new(1,14)]), ECBlocks::new(14, vec![ECB::new(1,10)])]),
|
||||
]
|
||||
// static const Version allVersions[] = {
|
||||
// {1, {2, 1, 3, 0, 0}},
|
||||
// {2, {5, 1, 5, 0, 0, 6, 1, 4, 0, 0}},
|
||||
// {3, {6, 1, 11, 0, 0, 8, 1, 9, 0, 0}},
|
||||
// {4, {8, 1, 16, 0, 0, 10, 1, 14, 0, 0, 14, 1, 10, 0, 0}}};
|
||||
}
|
||||
pub fn build_micro_versions() -> Vec<Version> {
|
||||
vec![
|
||||
Version::new_micro(1, vec![ECBlocks::new(2, vec![ECB::new(1, 3)])]),
|
||||
Version::new_micro(
|
||||
2,
|
||||
vec![
|
||||
ECBlocks::new(5, vec![ECB::new(1, 5)]),
|
||||
ECBlocks::new(6, vec![ECB::new(1, 4)]),
|
||||
],
|
||||
),
|
||||
Version::new_micro(
|
||||
3,
|
||||
vec![
|
||||
ECBlocks::new(6, vec![ECB::new(1, 11)]),
|
||||
ECBlocks::new(8, vec![ECB::new(1, 9)]),
|
||||
],
|
||||
),
|
||||
Version::new_micro(
|
||||
4,
|
||||
vec![
|
||||
ECBlocks::new(8, vec![ECB::new(1, 16)]),
|
||||
ECBlocks::new(10, vec![ECB::new(1, 14)]),
|
||||
ECBlocks::new(14, vec![ECB::new(1, 10)]),
|
||||
],
|
||||
),
|
||||
]
|
||||
// static const Version allVersions[] = {
|
||||
// {1, {2, 1, 3, 0, 0}},
|
||||
// {2, {5, 1, 5, 0, 0, 6, 1, 4, 0, 0}},
|
||||
// {3, {6, 1, 11, 0, 0, 8, 1, 9, 0, 0}},
|
||||
// {4, {8, 1, 16, 0, 0, 10, 1, 14, 0, 0, 14, 1, 10, 0, 0}}};
|
||||
}
|
||||
|
||||
/**
|
||||
* See ISO 18004:2006 6.5.1 Table 9
|
||||
|
||||
Reference in New Issue
Block a user