mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
Merge branch 'main' into thiserror
# Conflicts: # src/aztec/decoder.rs # src/datamatrix/decoder/decoded_bit_stream_parser.rs
This commit is contained in:
@@ -162,7 +162,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
||||
result.push_str(
|
||||
&encdr
|
||||
.decode(&decoded_bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(|a| Exceptions::illegal_state_with(a))?,
|
||||
.map_err(Exceptions::illegal_state_with)?,
|
||||
);
|
||||
|
||||
decoded_bytes.clear();
|
||||
@@ -342,7 +342,7 @@ fn correct_bits(
|
||||
}
|
||||
let mut offset = rawbits.len() % codeword_size;
|
||||
|
||||
let mut data_words = vec![0i32; num_codewords];
|
||||
let mut data_words = vec![0; num_codewords];
|
||||
for word in data_words.iter_mut().take(num_codewords) {
|
||||
// for i in 0..num_codewords {
|
||||
// for (int i = 0; i < numCodewords; i++, offset += codewordSize) {
|
||||
|
||||
@@ -142,7 +142,7 @@ impl<'a> Detector<'_> {
|
||||
self.shift = Self::get_rotation(&sides, length)?;
|
||||
|
||||
// Flatten the parameter bits into a single 28- or 40-bit long
|
||||
let mut parameter_data = 0u64;
|
||||
let mut parameter_data: u64 = 0;
|
||||
for i in 0..4 {
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
let side = sides[(self.shift + i) as usize % 4];
|
||||
@@ -230,7 +230,7 @@ impl<'a> Detector<'_> {
|
||||
}
|
||||
|
||||
let num_eccodewords = num_codewords - num_data_codewords;
|
||||
let mut parameterWords = vec![0i32; num_codewords as usize];
|
||||
let mut parameterWords = vec![0; num_codewords as usize];
|
||||
for i in (0..num_codewords).rev() {
|
||||
// for (int i = numCodewords - 1; i >= 0; --i) {
|
||||
parameterWords[i as usize] = (parameter_data & 0xF) as i32;
|
||||
@@ -245,7 +245,7 @@ impl<'a> Detector<'_> {
|
||||
//throw NotFoundException.getNotFoundInstance();
|
||||
//}
|
||||
// Toss the error correction. Just return the data as an integer
|
||||
let mut result = 0u32;
|
||||
let mut result: u32 = 0;
|
||||
for i in 0..num_data_codewords {
|
||||
// for (int i = 0; i < numDataCodewords; i++) {
|
||||
result = (result << 4) + parameterWords[i as usize] as u32;
|
||||
@@ -321,10 +321,10 @@ impl<'a> Detector<'_> {
|
||||
|
||||
// Expand the square by .5 pixel in each direction so that we're on the border
|
||||
// between the white square and the black square
|
||||
let pinax = point(pina.get_x() as f32 + 0.5f32, pina.get_y() as f32 - 0.5f32);
|
||||
let pinbx = point(pinb.get_x() as f32 + 0.5f32, pinb.get_y() as f32 + 0.5f32);
|
||||
let pincx = point(pinc.get_x() as f32 - 0.5f32, pinc.get_y() as f32 + 0.5f32);
|
||||
let pindx = point(pind.get_x() as f32 - 0.5f32, pind.get_y() as f32 - 0.5f32);
|
||||
let pinax = point(pina.get_x() as f32 + 0.5, pina.get_y() as f32 - 0.5);
|
||||
let pinbx = point(pinb.get_x() as f32 + 0.5, pinb.get_y() as f32 + 0.5);
|
||||
let pincx = point(pinc.get_x() as f32 - 0.5, pinc.get_y() as f32 + 0.5);
|
||||
let pindx = point(pind.get_x() as f32 - 0.5, pind.get_y() as f32 - 0.5);
|
||||
|
||||
// Expand the square so that its corners are the centers of the points
|
||||
// just outside the bull's eye.
|
||||
@@ -483,8 +483,8 @@ impl<'a> Detector<'_> {
|
||||
let sampler = DefaultGridSampler::default();
|
||||
let dimension = self.get_dimension();
|
||||
|
||||
let low = dimension as f32 / 2.0f32 - self.nb_center_layers as f32;
|
||||
let high = dimension as f32 / 2.0f32 + self.nb_center_layers as f32;
|
||||
let low = dimension as f32 / 2.0 - self.nb_center_layers as f32;
|
||||
let high = dimension as f32 / 2.0 + self.nb_center_layers as f32;
|
||||
|
||||
sampler.sample_grid_detailed(
|
||||
image,
|
||||
@@ -601,7 +601,7 @@ impl<'a> Detector<'_> {
|
||||
*/
|
||||
fn get_color(&self, p1: AztecPoint, p2: AztecPoint) -> i32 {
|
||||
let d = Self::distance_points(p1, p2);
|
||||
if d == 0.0f32 {
|
||||
if d == 0.0 {
|
||||
return 0;
|
||||
}
|
||||
let dx = (p2.get_x() - p1.get_x()) as f32 / d;
|
||||
@@ -626,11 +626,11 @@ impl<'a> Detector<'_> {
|
||||
|
||||
let err_ratio = error as f32 / d;
|
||||
|
||||
if err_ratio > 0.1f32 && err_ratio < 0.9f32 {
|
||||
if err_ratio > 0.1 && err_ratio < 0.9 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (err_ratio <= 0.1f32) == color_model {
|
||||
if (err_ratio <= 0.1) == color_model {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
@@ -674,7 +674,7 @@ impl<'a> Detector<'_> {
|
||||
* @return the corners of the expanded square
|
||||
*/
|
||||
fn expand_square(corner_points: &[Point], old_side: u32, new_side: u32) -> [Point; 4] {
|
||||
let ratio = new_side as f32 / (2.0f32 * old_side as f32);
|
||||
let ratio = new_side as f32 / (2.0 * old_side as f32);
|
||||
|
||||
let d = corner_points[0] - corner_points[2];
|
||||
let middle = corner_points[0].middle(corner_points[2]);
|
||||
|
||||
@@ -446,7 +446,7 @@ fn generateCheckWords(bitArray: &BitArray, totalBits: usize, wordSize: usize) ->
|
||||
}
|
||||
|
||||
fn bitsToWords(stuffedBits: &BitArray, wordSize: usize, totalWords: usize) -> Vec<i32> {
|
||||
let mut message = vec![0i32; totalWords];
|
||||
let mut message = vec![0; totalWords];
|
||||
let mut i = 0;
|
||||
let n = stuffedBits.getSize() / wordSize;
|
||||
while i < n {
|
||||
|
||||
@@ -196,7 +196,7 @@ impl HighLevelEncoder {
|
||||
// shown
|
||||
pub const SHIFT_TABLE: [[i32; 6]; 6] = {
|
||||
// mode shift codes, per table
|
||||
let mut shift_table = [[-1i32; 6]; 6];
|
||||
let mut shift_table = [[-1; 6]; 6];
|
||||
|
||||
shift_table[Self::MODE_UPPER][Self::MODE_PUNCT] = 0;
|
||||
|
||||
|
||||
@@ -40,11 +40,11 @@ use super::{maybe_append_multiple, maybe_append_string, ParsedRXingResult, Parse
|
||||
// const RFC2445_DURATION: &'static str =
|
||||
// "P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?";
|
||||
const RFC2445_DURATION_FIELD_UNITS: [i64; 5] = [
|
||||
7 * 24 * 60 * 60 * 1000i64, // 1 week
|
||||
24 * 60 * 60 * 1000i64, // 1 day
|
||||
60 * 60 * 1000i64, // 1 hour
|
||||
60 * 1000i64, // 1 minute
|
||||
1000i64, // 1 second
|
||||
7 * 24 * 60 * 60 * 1000, // 1 week
|
||||
24 * 60 * 60 * 1000, // 1 day
|
||||
60 * 60 * 1000, // 1 hour
|
||||
60 * 1000, // 1 minute
|
||||
1000, // 1 second
|
||||
];
|
||||
|
||||
static DATE_TIME: Lazy<Regex> = Lazy::new(|| Regex::new("[0-9]{8}(T[0-9]{6}Z?)?").unwrap());
|
||||
@@ -114,8 +114,8 @@ impl CalendarParsedRXingResult {
|
||||
let start = Self::parseDate(startString.clone())?;
|
||||
let end = if endString.is_empty() {
|
||||
let durationMS = Self::parseDurationMS(&durationString)?;
|
||||
if durationMS < 0i64 {
|
||||
-1i64
|
||||
if durationMS < 0 {
|
||||
-1
|
||||
} else {
|
||||
start + (durationMS / 1000)
|
||||
}
|
||||
@@ -240,7 +240,7 @@ impl CalendarParsedRXingResult {
|
||||
}
|
||||
// let regex = Regex::new(RFC2445_DURATION).unwrap();
|
||||
if let Some(m) = RFC2445_DURATION.captures(durationString) {
|
||||
let mut durationMS = 0i64;
|
||||
let mut durationMS: i64 = 0;
|
||||
for (i, unit) in RFC2445_DURATION_FIELD_UNITS.iter().enumerate() {
|
||||
// for i in 0..RFC2445_DURATION_FIELD_UNITS.len() {
|
||||
// for (int i = 0; i < RFC2445_DURATION_FIELD_UNITS.length; i++) {
|
||||
|
||||
@@ -224,7 +224,7 @@ fn doTest(
|
||||
);
|
||||
assert_eq!(
|
||||
endString,
|
||||
if calRXingResult.getEndTimestamp() < 0i64 {
|
||||
if calRXingResult.getEndTimestamp() < 0 {
|
||||
String::default()
|
||||
} else {
|
||||
format_date_string(calRXingResult.getEndTimestamp(), dateFormat)
|
||||
|
||||
@@ -29,9 +29,7 @@ static EPSILON: f32 = 1.0E-4f32;
|
||||
|
||||
#[test]
|
||||
fn test_square_to_quadrilateral() {
|
||||
let pt = PerspectiveTransform::squareToQuadrilateral(
|
||||
2.0f32, 3.0f32, 10.0, 4.0, 16.0, 15.0, 4.0, 9.0,
|
||||
);
|
||||
let pt = PerspectiveTransform::squareToQuadrilateral(2.0, 3.0, 10.0, 4.0, 16.0, 15.0, 4.0, 9.0);
|
||||
assert_point_equals(2.0, 3.0, 0.0, 0.0, &pt);
|
||||
assert_point_equals(10.0, 4.0, 1.0, 0.0, &pt);
|
||||
assert_point_equals(4.0, 9.0, 0.0, 1.0, &pt);
|
||||
|
||||
@@ -23,7 +23,7 @@ use std::{cmp, fmt};
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
static LOAD_FACTOR: f32 = 0.75f32;
|
||||
static LOAD_FACTOR: f32 = 0.75;
|
||||
|
||||
/**
|
||||
* <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>
|
||||
|
||||
@@ -335,7 +335,7 @@ impl<'a> WhiteRectangleDetector<'_> {
|
||||
let ti = t.x;
|
||||
let tj = t.y;
|
||||
|
||||
if yi < self.width as f32 / 2.0f32 {
|
||||
if yi < self.width as f32 / 2.0 {
|
||||
[
|
||||
point(ti - CORR as f32, tj + CORR as f32),
|
||||
point(zi + CORR as f32, zj + CORR as f32),
|
||||
|
||||
@@ -241,7 +241,7 @@ impl GlobalHistogramBinarizer {
|
||||
|
||||
// Find a valley between them that is low and closer to the white peak.
|
||||
let mut bestValley = secondPeak - 1;
|
||||
let mut bestValleyScore = -1i32;
|
||||
let mut bestValleyScore = -1;
|
||||
let mut x = secondPeak;
|
||||
while x > firstPeak {
|
||||
// for (int x = secondPeak - 1; x > firstPeak; x--) {
|
||||
|
||||
@@ -179,7 +179,7 @@ impl HybridBinarizer {
|
||||
}
|
||||
let left = Self::cap(x, sub_width - 3);
|
||||
let mut sum = 0;
|
||||
for z in -2i32..=2 {
|
||||
for z in -2..=2 {
|
||||
// for (int z = -2; z <= 2; z++) {
|
||||
let blackRow = &black_points[(top as i32 + z) as usize];
|
||||
sum += blackRow[(left - 2) as usize]
|
||||
@@ -255,7 +255,7 @@ impl HybridBinarizer {
|
||||
if xoffset > maxXOffset as u32 {
|
||||
xoffset = maxXOffset as u32;
|
||||
}
|
||||
let mut sum = 0u32;
|
||||
let mut sum: u32 = 0;
|
||||
let mut min = 0xff;
|
||||
let mut max = 0;
|
||||
|
||||
|
||||
@@ -133,19 +133,9 @@ impl PerspectiveTransform {
|
||||
) -> Self {
|
||||
let dx3 = x0 - x1 + x2 - x3;
|
||||
let dy3 = y0 - y1 + y2 - y3;
|
||||
if dx3 == 0.0f32 && dy3 == 0.0f32 {
|
||||
if dx3 == 0.0 && dy3 == 0.0 {
|
||||
// Affine
|
||||
PerspectiveTransform::new(
|
||||
x1 - x0,
|
||||
x2 - x1,
|
||||
x0,
|
||||
y1 - y0,
|
||||
y2 - y1,
|
||||
y0,
|
||||
0.0f32,
|
||||
0.0f32,
|
||||
1.0f32,
|
||||
)
|
||||
PerspectiveTransform::new(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0)
|
||||
} else {
|
||||
let dx1 = x1 - x2;
|
||||
let dx2 = x3 - x2;
|
||||
@@ -163,7 +153,7 @@ impl PerspectiveTransform {
|
||||
y0,
|
||||
a13,
|
||||
a23,
|
||||
1.0f32,
|
||||
1.0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ pub(crate) fn corrupt(
|
||||
) {
|
||||
let mut corrupted = vec![false; received.len()];
|
||||
//BitSet corrupted = new BitSet(received.length);
|
||||
let mut j = 0isize;
|
||||
let mut j: isize = 0;
|
||||
while j < howMany as isize {
|
||||
// for (int j = 0; j < howMany; j++) {
|
||||
let location: usize = random.gen_range(0..received.len());
|
||||
@@ -477,7 +477,7 @@ fn test_decoder(field: GenericGFRef, dataWords: &Vec<i32>, ecWords: &Vec<i32>) {
|
||||
};
|
||||
for _j in 0..iterations {
|
||||
//for (int j = 0; j < iterations; j++) {
|
||||
let mut i = 0isize;
|
||||
let mut i: isize = 0;
|
||||
while i < ecWords.len() as isize {
|
||||
//for (int i = 0; i < ecWords.length; i++) {
|
||||
if i > 10 && i < ecWords.len() as isize / 2 - 10 {
|
||||
|
||||
@@ -153,7 +153,7 @@ impl Decoder {
|
||||
fn correctErrors(&self, codewordBytes: &mut [u8], numDataCodewords: u32) -> Result<()> {
|
||||
let _numCodewords = codewordBytes.len();
|
||||
// First read into an array of ints
|
||||
// let codewordsInts = vec![0i32;numCodewords];
|
||||
// let codewordsInts = vec![0;numCodewords];
|
||||
// for i in 0..numCodewords {
|
||||
// // for (int i = 0; i < numCodewords; i++) {
|
||||
// codewordsInts[i] = codewordBytes[i];
|
||||
|
||||
@@ -732,7 +732,7 @@ fn decodeBase256Segment(
|
||||
result.append_string(
|
||||
&encoding::all::ISO_8859_1
|
||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(|e| Exceptions::parse_with(e))?,
|
||||
.map_err(Exceptions::parse_with)?,
|
||||
);
|
||||
byteSegments.push(bytes);
|
||||
|
||||
|
||||
@@ -375,7 +375,7 @@ fn addEdges(
|
||||
|
||||
//We create 4 EDF edges, with 1, 2 3 or 4 characters length. The fourth normally doesn't have a latch to ASCII
|
||||
//unless it is 2 characters away from the end of the input.
|
||||
let mut i = 0u32;
|
||||
let mut i: u32 = 0;
|
||||
while i < 3 {
|
||||
// for (i = 0; i < 3; i++) {
|
||||
let pos = from + i;
|
||||
|
||||
@@ -136,7 +136,7 @@ fn getBit(bit: u8, bytes: &[u8]) -> u8 {
|
||||
}
|
||||
|
||||
fn getInt(bytes: &[u8], x: &[u8]) -> u32 {
|
||||
let mut val = 0u32;
|
||||
let mut val: u32 = 0;
|
||||
for i in 0..x.len() {
|
||||
// for (int i = 0; i < x.length; i++) {
|
||||
val += (getBit(x[i], bytes) as u32) << ((x.len() - i - 1) as u32);
|
||||
|
||||
@@ -95,7 +95,7 @@ fn correctErrors(
|
||||
let divisor = if mode == ALL { 1 } else { 2 };
|
||||
|
||||
// First read into an array of ints
|
||||
let mut codewordsInts = vec![0i32; (codewords / divisor) as usize];
|
||||
let mut codewordsInts = vec![0; (codewords / divisor) as usize];
|
||||
for i in 0..codewords {
|
||||
if (mode == ALL) || (i % 2 == (mode - 1)) {
|
||||
codewordsInts[(i / divisor) as usize] = codewordBytes[(i + start) as usize] as i32;
|
||||
|
||||
@@ -134,8 +134,8 @@ impl Circle<'_> {
|
||||
let point_3 = self.find_width_at_degree(97.0).1[0];
|
||||
let guessed_center_point = Self::find_center(point_1, point_2, point_3);
|
||||
self.center = (
|
||||
guessed_center_point.0.round() as u32,
|
||||
guessed_center_point.1.round() as u32,
|
||||
guessed_center_point.x.round() as u32,
|
||||
guessed_center_point.y.round() as u32,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ impl Circle<'_> {
|
||||
/// returns (ellipse, center, semi_major, semi_minor, linear_eccentricity)
|
||||
pub fn detect_ellipse(&self) -> (bool, (u32, u32), u32, u32, u32) {
|
||||
// find semi-major and semi-minor axi
|
||||
let mut lengths = [(0, 0.0, [(0.0_f32, 0.0); 2]); 72];
|
||||
let mut lengths = [(0, 0.0, [Point::default(); 2]); 72];
|
||||
let mut circle_points = Vec::new();
|
||||
// for i_rotation in 0..72 {
|
||||
for (i_rotation, length_set) in lengths.iter_mut().enumerate() {
|
||||
@@ -193,7 +193,7 @@ impl Circle<'_> {
|
||||
let guessed_center_point = Self::find_center(point_1, point_2, point_3);
|
||||
(
|
||||
false,
|
||||
(guessed_center_point.0 as u32, guessed_center_point.1 as u32),
|
||||
(guessed_center_point.x as u32, guessed_center_point.y as u32),
|
||||
self.radius,
|
||||
self.radius,
|
||||
0,
|
||||
@@ -213,7 +213,7 @@ impl Circle<'_> {
|
||||
);
|
||||
(
|
||||
true,
|
||||
(ellipse_center.0 as u32, ellipse_center.1 as u32),
|
||||
(ellipse_center.x as u32, ellipse_center.y as u32),
|
||||
major_axis.0 / 2,
|
||||
minor_axis.0 / 2,
|
||||
linear_eccentricity,
|
||||
@@ -222,10 +222,10 @@ impl Circle<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_center(p1: (f32, f32), p2: (f32, f32), p3: (f32, f32)) -> (f32, f32) {
|
||||
let (x1, y1) = p1;
|
||||
let (x2, y2) = p2;
|
||||
let (x3, y3) = p3;
|
||||
fn find_center(p1: Point, p2: Point, p3: Point) -> Point {
|
||||
let Point { x: x1, y: y1 } = p1;
|
||||
let Point { x: x2, y: y2 } = p2;
|
||||
let Point { x: x3, y: y3 } = p3;
|
||||
|
||||
let a = x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2);
|
||||
let bx = (x1 * x1 + y1 * y1) * (y3 - y2)
|
||||
@@ -238,22 +238,16 @@ impl Circle<'_> {
|
||||
let x = bx / (2.0 * a);
|
||||
let y = by / (2.0 * a);
|
||||
|
||||
(x.abs(), y.abs())
|
||||
(x.abs(), y.abs()).into()
|
||||
}
|
||||
|
||||
fn calculate_ellipse_center(
|
||||
a: f32,
|
||||
_b: f32,
|
||||
p1: (f32, f32),
|
||||
p2: (f32, f32),
|
||||
p3: (f32, f32),
|
||||
) -> (f32, f32) {
|
||||
let x1 = p1.0;
|
||||
let y1 = p1.1;
|
||||
let x2 = p2.0;
|
||||
let y2 = p2.1;
|
||||
let x3 = p3.0;
|
||||
let y3 = p3.1;
|
||||
fn calculate_ellipse_center(a: f32, _b: f32, p1: Point, p2: Point, p3: Point) -> Point {
|
||||
let x1 = p1.x;
|
||||
let y1 = p1.y;
|
||||
let x2 = p2.x;
|
||||
let y2 = p2.y;
|
||||
let x3 = p3.x;
|
||||
let y3 = p3.y;
|
||||
|
||||
let ma = (x1 * x1 + y1 * y1 - a * a) / 2.0;
|
||||
let mb = (x2 * x2 + y2 * y2 - a * a) / 2.0;
|
||||
@@ -264,20 +258,20 @@ impl Circle<'_> {
|
||||
let x = (ma * y2 + mb * y3 + mc * y1) / determinant;
|
||||
let y = (x1 * mb + x2 * mc + x3 * ma) / determinant;
|
||||
|
||||
(x, y)
|
||||
(x, y).into()
|
||||
}
|
||||
|
||||
fn check_ellipse_point(
|
||||
center: (u32, u32),
|
||||
point: &(f32, f32),
|
||||
point: &Point,
|
||||
semi_major_axis: u32,
|
||||
semi_minor_axis: u32,
|
||||
) -> f64 {
|
||||
((point.0 as f64 - center.0 as f64).powf(2.0) / (semi_major_axis as f64).powf(2.0))
|
||||
+ ((point.1 as f64 - center.1 as f64).powf(2.0) / (semi_minor_axis as f64).powf(2.0))
|
||||
((point.x as f64 - center.0 as f64).powf(2.0) / (semi_major_axis as f64).powf(2.0))
|
||||
+ ((point.y as f64 - center.1 as f64).powf(2.0) / (semi_minor_axis as f64).powf(2.0))
|
||||
}
|
||||
|
||||
fn find_width_at_degree(&self, rotation: f32) -> (u32, [(f32, f32); 2]) {
|
||||
fn find_width_at_degree(&self, rotation: f32) -> (u32, [Point; 2]) {
|
||||
let mut x = self.center.0;
|
||||
let y = self.center.1;
|
||||
let mut length = 0;
|
||||
@@ -285,7 +279,7 @@ impl Circle<'_> {
|
||||
// count left
|
||||
while {
|
||||
let point = get_point(self.center, (x, y), rotation);
|
||||
!self.image.get(point.0 as u32, point.1 as u32) && x > 0
|
||||
!self.image.get(point.x as u32, point.y as u32) && x > 0
|
||||
} {
|
||||
x -= 1;
|
||||
length += 1;
|
||||
@@ -297,7 +291,7 @@ impl Circle<'_> {
|
||||
// count right
|
||||
while {
|
||||
let point = get_point(self.center, (x, y), rotation);
|
||||
!self.image.get(point.0 as u32, point.1 as u32)
|
||||
!self.image.get(point.x as u32, point.y as u32)
|
||||
} {
|
||||
x += 1;
|
||||
length += 1;
|
||||
@@ -344,10 +338,10 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
||||
};
|
||||
let grid_sampler = DefaultGridSampler::default();
|
||||
|
||||
let [tl, bl, tr, br] = &symbol_box.0;
|
||||
let [tl, bl, tr, br] = symbol_box.0;
|
||||
|
||||
let target_width = Point::distance(tl.into(), tr.into());
|
||||
let target_height = Point::distance(br.into(), tr.into());
|
||||
let target_width = Point::distance(tl, tr);
|
||||
let target_height = Point::distance(br, tr);
|
||||
|
||||
// let target_width = (tr.0 - tl.0).round().abs() as u32;
|
||||
// let target_height = (br.1 - tr.1).round().abs() as u32;
|
||||
@@ -364,14 +358,14 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
||||
target_height,
|
||||
0.0,
|
||||
target_height,
|
||||
tl.0,
|
||||
tl.1,
|
||||
tr.0,
|
||||
tr.1,
|
||||
br.0,
|
||||
br.1,
|
||||
bl.0,
|
||||
bl.1,
|
||||
tl.x,
|
||||
tl.y,
|
||||
tr.x,
|
||||
tr.y,
|
||||
br.x,
|
||||
br.y,
|
||||
bl.x,
|
||||
bl.y,
|
||||
) else {
|
||||
if try_harder {
|
||||
continue;
|
||||
@@ -382,10 +376,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
||||
return Ok(MaxicodeDetectionResult {
|
||||
bits,
|
||||
points: symbol_box
|
||||
.0
|
||||
.iter()
|
||||
.map(|p| Point { x: p.0, y: p.1 })
|
||||
.collect(),
|
||||
.0.to_vec(),
|
||||
rotation: symbol_box.1,
|
||||
});
|
||||
}
|
||||
@@ -709,7 +700,7 @@ const LEFT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
|
||||
const RIGHT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
|
||||
const ACCEPTED_SCALES: [f64; 5] = [0.065, 0.069, 0.07, 0.075, 0.08];
|
||||
|
||||
fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4], f32)> {
|
||||
fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([Point; 4], f32)> {
|
||||
let (left_boundary, right_boundary, top_boundary, bottom_boundary) =
|
||||
calculate_simple_boundary(circle, Some(image), None, false);
|
||||
|
||||
@@ -743,10 +734,10 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4]
|
||||
|
||||
Ok((
|
||||
[
|
||||
(result_box[0].x, result_box[0].y),
|
||||
(result_box[1].x, result_box[1].y),
|
||||
(result_box[2].x, result_box[2].y),
|
||||
(result_box[3].x, result_box[3].y),
|
||||
(result_box[0].x, result_box[0].y).into(),
|
||||
(result_box[1].x, result_box[1].y).into(),
|
||||
(result_box[2].x, result_box[2].y).into(),
|
||||
(result_box[3].x, result_box[3].y).into(),
|
||||
],
|
||||
final_rotation,
|
||||
))
|
||||
@@ -845,9 +836,9 @@ fn attempt_rotation_box(
|
||||
let p1_rot = get_point(circle.center, topl_p1, rotation);
|
||||
let p2_rot = get_point(circle.center, topl_p2, rotation);
|
||||
let p3_rot = get_point(circle.center, topl_p3, rotation);
|
||||
let found_tl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
||||
&& image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
||||
let found_tl = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||
&& image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||
if !found_tl {
|
||||
continue;
|
||||
}
|
||||
@@ -858,9 +849,9 @@ fn attempt_rotation_box(
|
||||
let p1_rot = get_point(circle.center, topr_p1, rotation);
|
||||
let p2_rot = get_point(circle.center, topr_p2, rotation);
|
||||
let p3_rot = get_point(circle.center, topr_p3, rotation);
|
||||
let found_tr = !image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
||||
&& !image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
||||
let found_tr = !image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||
&& !image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||
if !found_tr {
|
||||
continue;
|
||||
}
|
||||
@@ -871,9 +862,9 @@ fn attempt_rotation_box(
|
||||
let p1_rot = get_point(circle.center, l_p1, rotation);
|
||||
let p2_rot = get_point(circle.center, l_p2, rotation);
|
||||
let p3_rot = get_point(circle.center, l_p3, rotation);
|
||||
let found_l = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
||||
let found_l = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||
if !found_l {
|
||||
continue;
|
||||
}
|
||||
@@ -884,9 +875,9 @@ fn attempt_rotation_box(
|
||||
let p1_rot = get_point(circle.center, r_p1, rotation);
|
||||
let p2_rot = get_point(circle.center, r_p2, rotation);
|
||||
let p3_rot = get_point(circle.center, r_p3, rotation);
|
||||
let found_r = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
||||
let found_r = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||
if !found_r {
|
||||
continue;
|
||||
}
|
||||
@@ -897,9 +888,9 @@ fn attempt_rotation_box(
|
||||
let p1_rot = get_point(circle.center, bottoml_p1, rotation);
|
||||
let p2_rot = get_point(circle.center, bottoml_p2, rotation);
|
||||
let p3_rot = get_point(circle.center, bottoml_p3, rotation);
|
||||
let found_bl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
||||
let found_bl = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||
if !found_bl {
|
||||
continue;
|
||||
}
|
||||
@@ -910,9 +901,9 @@ fn attempt_rotation_box(
|
||||
let p1_rot = get_point(circle.center, bottomr_p1, rotation);
|
||||
let p2_rot = get_point(circle.center, bottomr_p2, rotation);
|
||||
let p3_rot = get_point(circle.center, bottomr_p3, rotation);
|
||||
let found_br = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
||||
let found_br = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||
if !found_br {
|
||||
continue;
|
||||
}
|
||||
@@ -952,10 +943,10 @@ fn attempt_rotation_box(
|
||||
|
||||
Some((
|
||||
[
|
||||
point(new_1.0, new_1.1),
|
||||
point(new_2.0, new_2.1),
|
||||
point(new_3.0, new_3.1),
|
||||
point(new_4.0, new_4.1),
|
||||
point(new_1.x, new_1.y),
|
||||
point(new_2.x, new_2.y),
|
||||
point(new_3.x, new_3.y),
|
||||
point(new_4.x, new_4.y),
|
||||
],
|
||||
final_rotation,
|
||||
))
|
||||
@@ -977,7 +968,7 @@ fn get_adjusted_points(
|
||||
)
|
||||
}
|
||||
|
||||
fn get_point(center: (u32, u32), original: (u32, u32), angle: f32) -> (f32, f32) {
|
||||
fn get_point(center: (u32, u32), original: (u32, u32), angle: f32) -> Point {
|
||||
let radians = angle.to_radians();
|
||||
let x = radians.cos() * (original.0 as f32 - center.0 as f32)
|
||||
- radians.sin() * (original.1 as f32 - center.1 as f32)
|
||||
@@ -986,7 +977,7 @@ fn get_point(center: (u32, u32), original: (u32, u32), angle: f32) -> (f32, f32)
|
||||
+ radians.cos() * (original.1 as f32 - center.1 as f32)
|
||||
+ center.1 as f32;
|
||||
|
||||
(x.abs(), y.abs())
|
||||
Point::new(x.abs(), y.abs())
|
||||
}
|
||||
|
||||
fn adjust_point_alternate(point: (u32, u32), circle: &Circle, center_scale: f64) -> (u32, u32) {
|
||||
|
||||
@@ -91,7 +91,7 @@ impl OneDReader for CodaBarReader {
|
||||
// Look for whitespace after pattern:
|
||||
let trailingWhitespace = self.counters[nextStart - 1];
|
||||
let mut lastPatternSize = 0;
|
||||
for i in -8isize..-1 {
|
||||
for i in -8..-1 {
|
||||
lastPatternSize += self.counters[(nextStart as isize + i) as usize];
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ impl CodaBarReader {
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
|
||||
as usize];
|
||||
for j in (0usize..=6).rev() {
|
||||
for j in (0..=6).rev() {
|
||||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
||||
// long stripes, while 0 and 1 are for short stripes.
|
||||
let category = (j & 1) + ((pattern as usize) & 1) * 2;
|
||||
|
||||
@@ -28,7 +28,7 @@ fn testBitsDiffering() {
|
||||
assert_eq!(0, FormatInformation::numBitsDiffering(1, 1));
|
||||
assert_eq!(1, FormatInformation::numBitsDiffering(0, 2));
|
||||
assert_eq!(2, FormatInformation::numBitsDiffering(1, 2));
|
||||
assert_eq!(32, FormatInformation::numBitsDiffering(-1i32 as u32, 0));
|
||||
assert_eq!(32, FormatInformation::numBitsDiffering(u32::MAX, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -48,8 +48,8 @@ pub fn decode(
|
||||
let mut bits = BitSource::new(bytes.to_owned());
|
||||
let mut result = String::with_capacity(50);
|
||||
let mut byteSegments = vec![vec![0u8; 0]; 0];
|
||||
let mut symbolSequence = -1i32;
|
||||
let mut parityData = -1i32;
|
||||
let mut symbolSequence = -1;
|
||||
let mut parityData = -1;
|
||||
|
||||
let mut currentCharacterSetECI = None;
|
||||
let mut fc1InEffect = false;
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::common::BitArray;
|
||||
*/
|
||||
|
||||
fn getUnsignedInt(v: &BitArray) -> u64 {
|
||||
let mut result = 0u64;
|
||||
let mut result: u64 = 0;
|
||||
const OFFSET: usize = 0;
|
||||
for i in 0..32 {
|
||||
// for (int i = 0, offset = 0; i < 32; i++) {
|
||||
|
||||
@@ -132,7 +132,7 @@ impl RXingResult {
|
||||
|
||||
/** Currently necessary because the external OneDReader proc macro uses it. */
|
||||
pub fn getRXingResultPoints(&self) -> &Vec<Point> {
|
||||
&&self.resultPoints
|
||||
&self.resultPoints
|
||||
}
|
||||
|
||||
/** Currently necessary because the external OneDReader proc macro uses it. */
|
||||
|
||||
Reference in New Issue
Block a user