mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
reorganize some impl blocks
This commit is contained in:
61
src/common/cpp_essentials/base_extentions/bitmatrix.rs
Normal file
61
src/common/cpp_essentials/base_extentions/bitmatrix.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use crate::common::BitMatrix;
|
||||
use crate::common::Result;
|
||||
use crate::point;
|
||||
|
||||
impl BitMatrix {
|
||||
pub fn Deflate(
|
||||
&self,
|
||||
width: u32,
|
||||
height: u32,
|
||||
top: f32,
|
||||
left: f32,
|
||||
subSampling: f32,
|
||||
) -> Result<Self> {
|
||||
let mut result = BitMatrix::new(width, height)?;
|
||||
|
||||
for y in 0..result.height() {
|
||||
// for (int y = 0; y < result.height(); y++) {
|
||||
let yOffset = top + y as f32 * subSampling;
|
||||
for x in 0..result.width() {
|
||||
// for (int x = 0; x < result.width(); x++) {
|
||||
if (self.get_point(point(left + x as f32 * subSampling, yOffset))) {
|
||||
result.set(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn findBoundingBox(
|
||||
&self,
|
||||
left: u32,
|
||||
top: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
minSize: u32,
|
||||
) -> (bool, u32, u32, u32, u32) {
|
||||
todo!()
|
||||
// let right;
|
||||
// let bottom;
|
||||
// if (!self.getTopLeftOnBitWithPosition(left, top) || !self.getBottomRightOnBitWithPosition(right, bottom) || bottom - top + 1 < minSize)
|
||||
// {return false;}
|
||||
|
||||
// for (int y = top; y <= bottom; y++ ) {
|
||||
// for (int x = 0; x < left; ++x)
|
||||
// if (get(x, y)) {
|
||||
// left = x;
|
||||
// break;
|
||||
// }
|
||||
// for (int x = _width-1; x > right; x--)
|
||||
// if (get(x, y)) {
|
||||
// right = x;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// width = right - left + 1;
|
||||
// height = bottom - top + 1;
|
||||
// return width >= minSize && height >= minSize;
|
||||
}
|
||||
}
|
||||
3
src/common/cpp_essentials/base_extentions/mod.rs
Normal file
3
src/common/cpp_essentials/base_extentions/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod bitmatrix;
|
||||
mod qr_formatinformation;
|
||||
mod qrcode_version;
|
||||
@@ -0,0 +1,22 @@
|
||||
use crate::qrcode::decoder::FormatInformation;
|
||||
|
||||
impl FormatInformation {
|
||||
pub fn DecodeMQR(formatInfoBits: u32) -> Self {
|
||||
unimplemented!()
|
||||
// // We don't use the additional masking (with 0x4445) to work around potentially non complying MicroQRCode encoders
|
||||
// auto fi = FindBestFormatInfo(0, FORMAT_INFO_DECODE_LOOKUP_MICRO, {formatInfoBits, MirrorBits(formatInfoBits)});
|
||||
|
||||
// constexpr uint8_t BITS_TO_VERSION[] = {1, 2, 2, 3, 3, 4, 4, 4};
|
||||
|
||||
// // Bits 2/3/4 contain both error correction level and version, 0/1 contain mask.
|
||||
// fi.ecLevel = ECLevelFromBits((fi.index >> 2) & 0x07, true);
|
||||
// fi.dataMask = static_cast<uint8_t>(fi.index & 0x03);
|
||||
// fi.microVersion = BITS_TO_VERSION[(fi.index >> 2) & 0x07];
|
||||
// fi.isMirrored = fi.bitsIndex == 1;
|
||||
|
||||
// return fi;
|
||||
}
|
||||
pub fn isValid(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
47
src/common/cpp_essentials/base_extentions/qrcode_version.rs
Normal file
47
src/common/cpp_essentials/base_extentions/qrcode_version.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use crate::common::Result;
|
||||
use crate::qrcode::decoder::{Version, VersionRef, VERSION_DECODE_INFO};
|
||||
use crate::Exceptions;
|
||||
|
||||
impl Version {
|
||||
pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 {
|
||||
Self::DimensionOffset(is_micro) + Self::DimensionStep(is_micro) * version
|
||||
}
|
||||
|
||||
pub fn DimensionOffset(is_micro: bool) -> u32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn DimensionStep(is_micro: bool) -> u32 {
|
||||
unimplemented!()
|
||||
}
|
||||
pub fn DecodeVersionInformation(versionBitsA: i32, versionBitsB: i32) -> Result<VersionRef> {
|
||||
let mut bestDifference = u32::MAX;
|
||||
let mut bestVersion = 0;
|
||||
let mut i = 0;
|
||||
for targetVersion in VERSION_DECODE_INFO {
|
||||
// for (int targetVersion : VERSION_DECODE_INFO) {
|
||||
// Do the version info bits match exactly? done.
|
||||
if targetVersion == versionBitsA as u32 || targetVersion == versionBitsB as u32 {
|
||||
return Self::getVersionForNumber(i + 7);
|
||||
}
|
||||
// Otherwise see if this is the closest to a real version info bit string
|
||||
// we have seen so far
|
||||
for bits in [versionBitsA, versionBitsB] {
|
||||
// for (int bits : {versionBitsA, versionBitsB}) {
|
||||
let bitsDifference = ((bits as u32) ^ targetVersion).count_ones(); //BitHacks::CountBitsSet(bits ^ targetVersion);
|
||||
if bitsDifference < bestDifference {
|
||||
bestVersion = i + 7;
|
||||
bestDifference = bitsDifference;
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
// We can tolerate up to 3 bits of error since no two version info codewords will
|
||||
// differ in less than 8 bits.
|
||||
if bestDifference <= 3 {
|
||||
return Self::getVersionForNumber(bestVersion);
|
||||
}
|
||||
// If we didn't find a close enough match, fail
|
||||
return Err(Exceptions::ILLEGAL_STATE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user