mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
cargo fmt
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
* @author Guenther Grau
|
* @author Guenther Grau
|
||||||
*/
|
*/
|
||||||
pub struct BarcodeMetadata {
|
pub struct BarcodeMetadata {
|
||||||
|
|
||||||
columnCount: u32,
|
columnCount: u32,
|
||||||
errorCorrectionLevel: u32,
|
errorCorrectionLevel: u32,
|
||||||
rowCountUpperPart: u32,
|
rowCountUpperPart: u32,
|
||||||
@@ -26,8 +25,12 @@ pub struct BarcodeMetadata {
|
|||||||
rowCount: u32,
|
rowCount: u32,
|
||||||
}
|
}
|
||||||
impl BarcodeMetadata {
|
impl BarcodeMetadata {
|
||||||
|
pub fn new(
|
||||||
pub fn new( columnCount:u32, rowCountUpperPart:u32, rowCountLowerPart:u32, errorCorrectionLevel:u32) -> Self{
|
columnCount: u32,
|
||||||
|
rowCountUpperPart: u32,
|
||||||
|
rowCountLowerPart: u32,
|
||||||
|
errorCorrectionLevel: u32,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
columnCount,
|
columnCount,
|
||||||
errorCorrectionLevel,
|
errorCorrectionLevel,
|
||||||
@@ -56,5 +59,4 @@ impl BarcodeMetadata {
|
|||||||
pub fn getRowCountLowerPart(&self) -> u32 {
|
pub fn getRowCountLowerPart(&self) -> u32 {
|
||||||
self.rowCountLowerPart
|
self.rowCountLowerPart
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ pub fn new() -> Self {
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BarcodeValue {
|
impl Default for BarcodeValue {
|
||||||
|
|||||||
@@ -14,14 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::{common::BitMatrix, RXingResultPoint, Exceptions, ResultPoint};
|
use crate::{common::BitMatrix, Exceptions, RXingResultPoint, ResultPoint};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Guenther Grau
|
* @author Guenther Grau
|
||||||
*/
|
*/
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BoundingBox<'a> {
|
pub struct BoundingBox<'a> {
|
||||||
|
|
||||||
image: &'a BitMatrix,
|
image: &'a BitMatrix,
|
||||||
topLeft: RXingResultPoint,
|
topLeft: RXingResultPoint,
|
||||||
bottomLeft: RXingResultPoint,
|
bottomLeft: RXingResultPoint,
|
||||||
@@ -33,16 +32,17 @@ pub struct BoundingBox<'a> {
|
|||||||
maxY: u32,
|
maxY: u32,
|
||||||
}
|
}
|
||||||
impl<'a> BoundingBox<'_> {
|
impl<'a> BoundingBox<'_> {
|
||||||
|
pub fn new(
|
||||||
pub fn new( image:&'a BitMatrix,
|
image: &'a BitMatrix,
|
||||||
topLeft: Option<RXingResultPoint>,
|
topLeft: Option<RXingResultPoint>,
|
||||||
bottomLeft: Option<RXingResultPoint>,
|
bottomLeft: Option<RXingResultPoint>,
|
||||||
topRight: Option<RXingResultPoint>,
|
topRight: Option<RXingResultPoint>,
|
||||||
bottomRight:Option<RXingResultPoint>) -> Result<BoundingBox<'a>,Exceptions> {
|
bottomRight: Option<RXingResultPoint>,
|
||||||
|
) -> Result<BoundingBox<'a>, Exceptions> {
|
||||||
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
|
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
|
||||||
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
|
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
|
||||||
if leftUnspecified && rightUnspecified {
|
if leftUnspecified && rightUnspecified {
|
||||||
return Err(Exceptions::NotFoundException("".to_owned()))
|
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let newTopLeft;
|
let newTopLeft;
|
||||||
@@ -59,7 +59,8 @@ impl<'a> BoundingBox<'_> {
|
|||||||
newTopLeft = topLeft.unwrap();
|
newTopLeft = topLeft.unwrap();
|
||||||
newBottomLeft = bottomLeft.unwrap();
|
newBottomLeft = bottomLeft.unwrap();
|
||||||
newTopRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
|
newTopRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
|
||||||
newBottomRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
|
newBottomRight =
|
||||||
|
RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
|
||||||
} else {
|
} else {
|
||||||
newTopLeft = topLeft.unwrap();
|
newTopLeft = topLeft.unwrap();
|
||||||
newTopRight = topRight.unwrap();
|
newTopRight = topRight.unwrap();
|
||||||
@@ -94,20 +95,34 @@ impl<'a> BoundingBox<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge( leftBox:Option<&'a BoundingBox>, rightBox:Option<&'a BoundingBox>) -> Result<BoundingBox<'a>,Exceptions> {
|
pub fn merge(
|
||||||
|
leftBox: Option<&'a BoundingBox>,
|
||||||
|
rightBox: Option<&'a BoundingBox>,
|
||||||
|
) -> Result<BoundingBox<'a>, Exceptions> {
|
||||||
if leftBox.is_none() {
|
if leftBox.is_none() {
|
||||||
return Ok(rightBox.unwrap().clone())
|
return Ok(rightBox.unwrap().clone());
|
||||||
}
|
}
|
||||||
if rightBox.is_none() {
|
if rightBox.is_none() {
|
||||||
return Ok(leftBox.unwrap().clone())
|
return Ok(leftBox.unwrap().clone());
|
||||||
}
|
}
|
||||||
let leftBox = leftBox.unwrap();
|
let leftBox = leftBox.unwrap();
|
||||||
let rightBox = rightBox.unwrap();
|
let rightBox = rightBox.unwrap();
|
||||||
|
|
||||||
BoundingBox::new(leftBox.image, Some(leftBox.topLeft), Some(leftBox.bottomLeft), Some(rightBox.topRight), Some(rightBox.bottomRight))
|
BoundingBox::new(
|
||||||
|
leftBox.image,
|
||||||
|
Some(leftBox.topLeft),
|
||||||
|
Some(leftBox.bottomLeft),
|
||||||
|
Some(rightBox.topRight),
|
||||||
|
Some(rightBox.bottomRight),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addMissingRows(&self, missingStartRows:u32, missingEndRows:u32, isLeft:bool) -> Result<BoundingBox,Exceptions> {
|
pub fn addMissingRows(
|
||||||
|
&self,
|
||||||
|
missingStartRows: u32,
|
||||||
|
missingEndRows: u32,
|
||||||
|
isLeft: bool,
|
||||||
|
) -> Result<BoundingBox, Exceptions> {
|
||||||
let mut newTopLeft = self.topLeft;
|
let mut newTopLeft = self.topLeft;
|
||||||
let mut newBottomLeft = self.bottomLeft;
|
let mut newBottomLeft = self.bottomLeft;
|
||||||
let mut newTopRight = self.topRight;
|
let mut newTopRight = self.topRight;
|
||||||
@@ -128,7 +143,11 @@ impl<'a> BoundingBox<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if missingEndRows > 0 {
|
if missingEndRows > 0 {
|
||||||
let bottom = if isLeft { self.bottomLeft} else {self.bottomRight};
|
let bottom = if isLeft {
|
||||||
|
self.bottomLeft
|
||||||
|
} else {
|
||||||
|
self.bottomRight
|
||||||
|
};
|
||||||
let mut newMaxY = bottom.getY() as u32 + missingEndRows;
|
let mut newMaxY = bottom.getY() as u32 + missingEndRows;
|
||||||
if newMaxY >= self.image.getHeight() {
|
if newMaxY >= self.image.getHeight() {
|
||||||
newMaxY = self.image.getHeight() - 1;
|
newMaxY = self.image.getHeight() - 1;
|
||||||
@@ -141,7 +160,13 @@ impl<'a> BoundingBox<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox::new(self.image, Some(newTopLeft), Some(newBottomLeft), Some(newTopRight), Some(newBottomRight))
|
BoundingBox::new(
|
||||||
|
self.image,
|
||||||
|
Some(newTopLeft),
|
||||||
|
Some(newBottomLeft),
|
||||||
|
Some(newTopRight),
|
||||||
|
Some(newBottomRight),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getMinX(&self) -> u32 {
|
pub fn getMinX(&self) -> u32 {
|
||||||
@@ -175,5 +200,4 @@ impl<'a> BoundingBox<'_> {
|
|||||||
pub fn getBottomRight(&self) -> &RXingResultPoint {
|
pub fn getBottomRight(&self) -> &RXingResultPoint {
|
||||||
&self.bottomRight
|
&self.bottomRight
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ use std::fmt::Display;
|
|||||||
*/
|
*/
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Codeword {
|
pub struct Codeword {
|
||||||
|
|
||||||
startX: u32,
|
startX: u32,
|
||||||
endX: u32,
|
endX: u32,
|
||||||
bucket: u32,
|
bucket: u32,
|
||||||
@@ -32,7 +31,6 @@ pub struct Codeword {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Codeword {
|
impl Codeword {
|
||||||
|
|
||||||
pub fn new(startX: u32, endX: u32, bucket: u32, value: u32) -> Self {
|
pub fn new(startX: u32, endX: u32, bucket: u32, value: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
startX,
|
startX,
|
||||||
@@ -82,7 +80,6 @@ impl Codeword {
|
|||||||
pub fn setRowNumber(&mut self, rowNumber: i32) {
|
pub fn setRowNumber(&mut self, rowNumber: i32) {
|
||||||
self.rowNumber = rowNumber;
|
self.rowNumber = rowNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Codeword {
|
impl Display for Codeword {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ pub struct DetectionRXingResultColumn<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DetectionRXingResultColumn<'_> {
|
impl<'a> DetectionRXingResultColumn<'_> {
|
||||||
|
|
||||||
pub fn new(boundingBox: &'a BoundingBox) -> DetectionRXingResultColumn<'a> {
|
pub fn new(boundingBox: &'a BoundingBox) -> DetectionRXingResultColumn<'a> {
|
||||||
DetectionRXingResultColumn {
|
DetectionRXingResultColumn {
|
||||||
boundingBox: BoundingBox::from_other(boundingBox),
|
boundingBox: BoundingBox::from_other(boundingBox),
|
||||||
@@ -84,9 +83,6 @@ impl<'a> DetectionRXingResultColumn<'_> {
|
|||||||
pub fn getCodewords(&self) -> &[Option<Codeword>] {
|
pub fn getCodewords(&self) -> &[Option<Codeword>] {
|
||||||
&self.codewords
|
&self.codewords
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for DetectionRXingResultColumn<'_> {
|
impl Display for DetectionRXingResultColumn<'_> {
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ use crate::pdf417::pdf_417_common;
|
|||||||
// [[0.0;pdf_417_common::SYMBOL_TABLE.len()];pdf_417_common::BARS_IN_MODULE];
|
// [[0.0;pdf_417_common::SYMBOL_TABLE.len()];pdf_417_common::BARS_IN_MODULE];
|
||||||
|
|
||||||
const RATIOS_TABLE: [[f64; pdf_417_common::BARS_IN_MODULE as usize]; 2787] = {
|
const RATIOS_TABLE: [[f64; pdf_417_common::BARS_IN_MODULE as usize]; 2787] = {
|
||||||
let mut table = [[0.0;pdf_417_common::BARS_IN_MODULE as usize];pdf_417_common::SYMBOL_TABLE.len()];
|
let mut table =
|
||||||
|
[[0.0; pdf_417_common::BARS_IN_MODULE as usize]; pdf_417_common::SYMBOL_TABLE.len()];
|
||||||
// Pre-computes the symbol ratio table.
|
// Pre-computes the symbol ratio table.
|
||||||
let mut i = 0_usize;
|
let mut i = 0_usize;
|
||||||
while i < pdf_417_common::SYMBOL_TABLE.len() {
|
while i < pdf_417_common::SYMBOL_TABLE.len() {
|
||||||
@@ -41,7 +42,8 @@ use crate::pdf417::pdf_417_common;
|
|||||||
currentSymbol >>= 1;
|
currentSymbol >>= 1;
|
||||||
}
|
}
|
||||||
currentBit = currentSymbol & 0x1;
|
currentBit = currentSymbol & 0x1;
|
||||||
table[i][pdf_417_common::BARS_IN_MODULE as usize - j - 1] = size / pdf_417_common::MODULES_IN_CODEWORD as f64;
|
table[i][pdf_417_common::BARS_IN_MODULE as usize - j - 1] =
|
||||||
|
size / pdf_417_common::MODULES_IN_CODEWORD as f64;
|
||||||
|
|
||||||
j += 1;
|
j += 1;
|
||||||
}
|
}
|
||||||
@@ -67,9 +69,9 @@ use crate::pdf417::pdf_417_common;
|
|||||||
let mut sumPreviousBits = 0;
|
let mut sumPreviousBits = 0;
|
||||||
for i in 0..pdf_417_common::MODULES_IN_CODEWORD {
|
for i in 0..pdf_417_common::MODULES_IN_CODEWORD {
|
||||||
// for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
|
// for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
|
||||||
let sampleIndex:f32 =
|
let sampleIndex: f32 = bitCountSum as f32
|
||||||
bitCountSum as f32/ (2 * pdf_417_common::MODULES_IN_CODEWORD) as f32 +
|
/ (2 * pdf_417_common::MODULES_IN_CODEWORD) as f32
|
||||||
(i * bitCountSum) as f32 / pdf_417_common::MODULES_IN_CODEWORD as f32;
|
+ (i * bitCountSum) as f32 / pdf_417_common::MODULES_IN_CODEWORD as f32;
|
||||||
if sumPreviousBits as f32 + moduleBitCount[bitCountIndex] as f32 <= sampleIndex {
|
if sumPreviousBits as f32 + moduleBitCount[bitCountIndex] as f32 <= sampleIndex {
|
||||||
sumPreviousBits += moduleBitCount[bitCountIndex];
|
sumPreviousBits += moduleBitCount[bitCountIndex];
|
||||||
bitCountIndex += 1;
|
bitCountIndex += 1;
|
||||||
@@ -81,7 +83,11 @@ use crate::pdf417::pdf_417_common;
|
|||||||
|
|
||||||
fn getDecodedCodewordValue(moduleBitCount: &[u32]) -> i32 {
|
fn getDecodedCodewordValue(moduleBitCount: &[u32]) -> i32 {
|
||||||
let decodedValue = getBitValue(moduleBitCount);
|
let decodedValue = getBitValue(moduleBitCount);
|
||||||
if pdf_417_common::getCodeword(decodedValue as u32) == -1 {-1} else {decodedValue}
|
if pdf_417_common::getCodeword(decodedValue as u32) == -1 {
|
||||||
|
-1
|
||||||
|
} else {
|
||||||
|
decodedValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getBitValue(moduleBitCount: &[u32]) -> i32 {
|
fn getBitValue(moduleBitCount: &[u32]) -> i32 {
|
||||||
|
|||||||
Reference in New Issue
Block a user