diff --git a/src/aztec.rs b/src/aztec.rs index 41c0034..af92d38 100644 --- a/src/aztec.rs +++ b/src/aztec.rs @@ -19,13 +19,13 @@ use crate::aztec::encoder::{AztecCode,Encoder}; * @author Sean Owen */ pub struct AztecDetectorResult { - super: DetectorResult; + //super: DetectorResult; - let compact: bool; + compact: bool, - let nb_datablocks: i32; + nb_datablocks: i32, - let nb_layers: i32; + nb_layers: i32 } impl DetectorResult for AztecDetectorResult { diff --git a/src/common.rs b/src/common.rs index eb626f0..e4cfede 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,3 +1,6 @@ +pub mod detector; +pub mod readsolomon; + use std::collections::HashMap; use crate::{Binarizer,LuminanceSource,NotFoundException,FormatException,NotFoundException,Binarizer,ResultPoint}; @@ -172,7 +175,7 @@ impl GridSampler { */ pub fn sample_grid(&self, image: &BitMatrix, dimension_x: i32, dimension_y: i32, p1_to_x: f32, p1_to_y: f32, p2_to_x: f32, p2_to_y: f32, p3_to_x: f32, p3_to_y: f32, p4_to_x: f32, p4_to_y: f32, p1_from_x: f32, p1_from_y: f32, p2_from_x: f32, p2_from_y: f32, p3_from_x: f32, p3_from_y: f32, p4_from_x: f32, p4_from_y: f32) -> Result ; - pub fn sample_grid(&self, image: &BitMatrix, dimension_x: i32, dimension_y: i32, transform: &PerspectiveTransform) -> /* throws NotFoundException */Result> ; + pub fn sample_grid(&self, image: &BitMatrix, dimension_x: i32, dimension_y: i32, transform: &PerspectiveTransform) -> Result ; /** *

Checks a set of points that have been transformed to sample points on an image against @@ -207,14 +210,14 @@ impl GridSampler { } nudged = false; if x == -1 { - points[offset] = 0.0f; + points[offset] = 0.0f32; nudged = true; } else if x == width { points[offset] = width - 1.0; nudged = true; } if y == -1 { - points[offset + 1] = 0.0f; + points[offset + 1] = 0.0f32; nudged = true; } else if y == height { points[offset + 1] = height - 1.0; @@ -238,14 +241,14 @@ impl GridSampler { } nudged = false; if x == -1 { - points[offset] = 0.0f; + points[offset] = 0.0f32; nudged = true; } else if x == width { points[offset] = width - 1.0; nudged = true; } if y == -1 { - points[offset + 1] = 0.0f; + points[offset + 1] = 0.0f32; nudged = true; } else if y == height { points[offset + 1] = height - 1.0; @@ -524,7 +527,7 @@ impl GlobalHistogramBinarizer { */ const EMPTY_BITS : Vec = Vec!([]); -const LOAD_FACTOR: f32 = 0.75f; +const LOAD_FACTOR: f32 = 0.75f32; #[derive(Cloneable, Eq, Hash)] pub struct BitArray { @@ -1362,7 +1365,7 @@ Ok(()) * * @return {@code left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white */ - pub fn get_enclosing_rectangle(&self) -> Vec { + pub fn get_enclosing_rectangle(&self) -> Option> { let mut left: i32 = self.width; let mut top: i32 = self.height; let mut right: i32 = -1; @@ -1415,7 +1418,7 @@ Ok(()) if right < left || bottom < top { return null; } - return vec![left, top, right - left + 1, bottom - top + 1, ] + return Some(vec![left, top, right - left + 1, bottom - top + 1, ]) ; } @@ -1424,7 +1427,7 @@ Ok(()) * * @return {@code x,y} coordinate of top-left-most 1 bit, or null if it is all white */ - pub fn get_top_left_on_bit(&self) -> Vec { + pub fn get_top_left_on_bit(&self) -> Option> { let bits_offset: i32 = 0; while bits_offset < self.bits.len() && self.bits[bits_offset] == 0 { bits_offset += 1; @@ -1440,7 +1443,7 @@ Ok(()) bit += 1; } x += bit; - return vec![x, y, ] + return Some(vec![x, y, ]) ; } @@ -1735,7 +1738,7 @@ impl CharacterSetECI { * @return CharacterSetECI representing ECI for character encoding, or null if it is legal * but unsupported */ - pub fn get_character_set_e_c_i( charset: &str) -> Result { + pub fn get_character_set_e_c_i( charset: &str) -> Result,&'static str> { //return NAME_TO_ECI::get(&charset.name()); let eci = match charset { "Cp437" => Self::Cp437, @@ -1762,7 +1765,7 @@ impl CharacterSetECI { "EUC-KR" => Self::EUC_KR, _ => return Err("Invalid charset") }; - Ok(eci) + Ok(Some(eci)) } /** @@ -1771,7 +1774,7 @@ _ => return Err("Invalid charset") * unsupported * @throws FormatException if ECI value is invalid */ - pub fn get_character_set_e_c_i_by_value( value: i32) -> Result { + pub fn get_character_set_e_c_i_by_value( value: i32) -> Result, FormatException> { if value < 0 || value >= 900 { return Err( FormatException::get_format_instance()); } @@ -1801,7 +1804,7 @@ _ => return Err("Invalid charset") _ => return Err( FormatException::get_format_instance()) }; - return Ok(eci); + return Ok(Some(eci)); } pub fn get_value(v: Self) -> i32 { @@ -1831,7 +1834,7 @@ _ => return Err( FormatException::get_format_instance()) } } - /** + /* * @param name character set ECI encoding name * @return CharacterSetECI representing ECI for character encoding, or null if it is legal * but unsupported @@ -1899,8 +1902,8 @@ impl DecoderResult { /** * @return raw bytes representing the result, or {@code null} if not applicable */ - pub fn get_raw_bytes(&self) -> Vec { - return self.raw_bytes; + pub fn get_raw_bytes(&self) -> Option> { + return Some(self.raw_bytes); } /** @@ -1929,21 +1932,21 @@ impl DecoderResult { /** * @return list of byte segments in the result, or {@code null} if not applicable */ - pub fn get_byte_segments(&self) -> List> { + pub fn get_byte_segments(&self) -> Option>> { return self.byte_segments; } /** * @return name of error correction level used, or {@code null} if not applicable */ - pub fn get_e_c_level(&self) -> String { - return self.ec_level; + pub fn get_e_c_level(&self) -> Option { + return Some(self.ec_level); } /** * @return number of errors corrected, or {@code null} if not applicable */ - pub fn get_errors_corrected(&self) -> Integer { + pub fn get_errors_corrected(&self) -> Option { return self.errors_corrected; } @@ -1954,7 +1957,7 @@ impl DecoderResult { /** * @return number of erasures corrected, or {@code null} if not applicable */ - pub fn get_erasures(&self) -> Integer { + pub fn get_erasures(&self) -> Option { return self.erasures; } @@ -2017,12 +2020,12 @@ impl GridSampler for DefaultGridSampler { while y < dimension_y { { let max: i32 = points.len(); - let i_value: f32 = y + 0.5f; + let i_value: f32 = y + 0.5f32; { let mut x: i32 = 0; while x < max { { - points[x] = (x / 2.0) as f32 + 0.5f; + points[x] = (x / 2.0) as f32 + 0.5f32; points[x + 1] = i_value; } x += 2; @@ -3086,43 +3089,43 @@ impl MinimalECIInput { return ints; } - struct InputEdge { +} - c: char, +struct InputEdge { - //the encoding of this edge - encoder_index: i32, + c: char, - previous: InputEdge, + //the encoding of this edge + encoder_index: i32, - cached_total_size: i32 - } - - impl InputEdge { + previous: InputEdge, - fn new( c: char, encoder_set: &ECIEncoderSet, encoder_index: i32, previous: &InputEdge, fnc1: i32) -> Self { - let mut new_ie : Self; - new_ie .c = if c == fnc1 { 1000 } else { c }; - new_ie .encoderIndex = encoder_index; - new_ie .previous = previous; - let mut size: i32 = if new_ie .c == 1000 { 1 } else { encoder_set.encode(c, encoder_index).len() }; - let previous_encoder_index: i32 = if previous == null { 0 } else { previous.encoderIndex }; - if previous_encoder_index != encoder_index { - size += COST_PER_ECI; - } - if previous != null { - size += previous.cachedTotalSize; - } - new_ie .cachedTotalSize = size; + cached_total_size: i32 +} - new_ie - } +impl InputEdge { - fn is_f_n_c1(&self) -> bool { - return self.c == 1000; - } - } + fn new( c: char, encoder_set: &ECIEncoderSet, encoder_index: i32, previous: &InputEdge, fnc1: i32) -> Self { + let mut new_ie : Self; + new_ie .c = if c == fnc1 { 1000 } else { c }; + new_ie .encoderIndex = encoder_index; + new_ie .previous = previous; + let mut size: i32 = if new_ie .c == 1000 { 1 } else { encoder_set.encode(c, encoder_index).len() }; + let previous_encoder_index: i32 = if previous == null { 0 } else { previous.encoderIndex }; + if previous_encoder_index != encoder_index { + size += COST_PER_ECI; + } + if previous != null { + size += previous.cachedTotalSize; + } + new_ie .cachedTotalSize = size; + new_ie + } + + fn is_f_n_c1(&self) -> bool { + return self.c == 1000; + } } // PerspectiveTransform.java @@ -3215,9 +3218,9 @@ impl PerspectiveTransform { pub fn square_to_quadrilateral( x0: f32, y0: f32, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32) -> PerspectiveTransform { let dx3: f32 = x0 - x1 + x2 - x3; let dy3: f32 = y0 - y1 + y2 - y3; - if dx3 == 0.0f && dy3 == 0.0f { + if dx3 == 0.0f32 && dy3 == 0.0f32 { // Affine - return PerspectiveTransform::new(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f, 0.0f, 1.0f); + return PerspectiveTransform::new(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f32, 0.0f32, 1.0f32); } else { let dx1: f32 = x1 - x2; let dx2: f32 = x3 - x2; @@ -3226,7 +3229,7 @@ impl PerspectiveTransform { let denominator: f32 = dx1 * dy2 - dx2 * dy1; let a13: f32 = (dx3 * dy2 - dx2 * dy3) / denominator; let a23: f32 = (dx1 * dy3 - dx3 * dy1) / denominator; - return PerspectiveTransform::new(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0f); + return PerspectiveTransform::new(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0f32); } } diff --git a/src/common/detector.rs b/src/common/detector.rs index 7f46428..2a0dd07 100644 --- a/src/common/detector.rs +++ b/src/common/detector.rs @@ -24,7 +24,7 @@ impl MathUtils { * @return nearest {@code int} */ pub fn round( d: f32) -> i32 { - return (d + ( if d < 0.0f { -0.5f } else { 0.5f })) as i32; + return (d + ( if d < 0.0f32 { -0.5f32 } else { 0.5f32 })) as i32; } /** @@ -86,7 +86,7 @@ pub struct MonochromeRectangleDetector { impl MonochromeRectangleDetector { pub fn new( image: &BitMatrix) -> Self { - Self{ image }; + Self{ image } } /** @@ -208,7 +208,7 @@ impl MonochromeRectangleDetector { * @return int[] with start and end of found range, or null if no such range is found * (e.g. only white was found) */ - fn black_white_range(&self, fixed_dimension: i32, max_white_run: i32, min_dim: i32, max_dim: i32, horizontal: bool) -> Vec { + fn black_white_range(&self, fixed_dimension: i32, max_white_run: i32, min_dim: i32, max_dim: i32, horizontal: bool) -> Option> { let center: i32 = (min_dim + max_dim) / 2; // Scan left/up first let mut start: i32 = center; @@ -248,7 +248,7 @@ impl MonochromeRectangleDetector { } } end -= 1; - return if end > start { vec![start, end, ] + return if end > start { Some(vec![start, end, ]) } else { null }; } } @@ -288,7 +288,7 @@ pub struct WhiteRectangleDetector { impl WhiteRectangleDetector { pub fn new( image: &BitMatrix) -> Result { - this(image, INIT_SIZE, image.get_width() / 2, image.get_height() / 2); + this(image, INIT_SIZE, image.get_width() / 2, image.get_height() / 2) } /** @@ -475,13 +475,13 @@ impl WhiteRectangleDetector { if y == null { return Err( NotFoundException::get_not_found_instance()); } - return Ok(self.center_edges(y, z, x, t)); + return Ok(self.center_edges(&y, &z, &x, &t)); } else { return Err( NotFoundException::get_not_found_instance()); } } - fn get_black_point_on_segment(&self, a_x: f32, a_y: f32, b_x: f32, b_y: f32) -> ResultPoint { + fn get_black_point_on_segment(&self, a_x: f32, a_y: f32, b_x: f32, b_y: f32) -> Option { let dist: i32 = MathUtils::round(&MathUtils::distance(a_x, a_y, b_x, b_y)); let x_step: f32 = (b_x - a_x) / dist; let y_step: f32 = (b_y - a_y) / dist; @@ -492,7 +492,7 @@ impl WhiteRectangleDetector { let x: i32 = MathUtils::round(a_x + i * x_step); let y: i32 = MathUtils::round(a_y + i * y_step); if self.image.get(x, y) { - return ResultPoint::new(x, y); + return Some(ResultPoint::new(x, y)); } } i += 1; @@ -530,7 +530,7 @@ impl WhiteRectangleDetector { let xj: f32 = x.get_y(); let ti: f32 = t.get_x(); let tj: f32 = t.get_y(); - if yi < self.width / 2.0f { + if yi < self.width / 2.0f32 { return vec![ResultPoint::new(ti - CORR, tj + CORR), ResultPoint::new(zi + CORR, zj + CORR), ResultPoint::new(xi - CORR, xj - CORR), ResultPoint::new(yi + CORR, yj - CORR), ] ; } else { diff --git a/src/common/readsolomon.rs b/src/common/readsolomon.rs index 6053e8c..ba458a0 100644 --- a/src/common/readsolomon.rs +++ b/src/common/readsolomon.rs @@ -138,7 +138,7 @@ impl GenericGFPoly { } } - return GenericGFPoly::new(self.field, &sum_diff); + return GenericGFPoly::new(&self.field, &sum_diff); } fn multiply(&self, other: &GenericGFPoly) -> Result { @@ -146,7 +146,7 @@ impl GenericGFPoly { return Err(IllegalArgumentException::new("GenericGFPolys do not have same GenericGF field")); } if self.is_zero() || other.is_zero() { - return self.field.get_zero(); + return Ok(self.field.get_zero()); } let a_coefficients: Vec = self.coefficients; let a_length: i32 = a_coefficients.len(); @@ -173,7 +173,7 @@ impl GenericGFPoly { } } - return GenericGFPoly::new(self.field, &product); + return GenericGFPoly::new(&self.field, &product); } fn multiply(&self, scalar: i32) -> GenericGFPoly { @@ -195,7 +195,7 @@ impl GenericGFPoly { } } - return GenericGFPoly::new(self.field, &product); + return GenericGFPoly::new(&self.field, &product); } fn multiply_by_monomial(&self, degree: i32, coefficient: i32) -> Result { @@ -203,7 +203,7 @@ impl GenericGFPoly { return Err( IllegalArgumentException::new()); } if coefficient == 0 { - return self.field.get_zero(); + return Ok(self.field.get_zero()); } let size: i32 = self.coefficients.len(); let mut product: [i32; size + degree] = [0; size + degree]; @@ -217,7 +217,7 @@ impl GenericGFPoly { } } - return GenericGFPoly::new(self.field, &product); + return GenericGFPoly::new(&self.field, &product); } fn divide(&self, other: &GenericGFPoly) -> Result,IllegalArgumentException> { @@ -236,16 +236,15 @@ impl GenericGFPoly { let scale: i32 = self.field.multiply(&remainder.get_coefficient(&remainder.get_degree()), inverse_denominator_leading_term); let term: GenericGFPoly = other.multiply_by_monomial(degree_difference, scale); let iteration_quotient: GenericGFPoly = self.field.build_monomial(degree_difference, scale); - quotient = quotient.add_or_subtract(iteration_quotient); - remainder = remainder.add_or_subtract(term); + quotient = quotient.add_or_subtract(&iteration_quotient); + remainder = remainder.add_or_subtract(&term); } - return vec![quotient, remainder, ] - ; + return Ok(vec![quotient, remainder, ]); } pub fn to_string(&self) -> String { if self.is_zero() { - return "0"; + return "0".to_owned(); } let result: StringBuilder = StringBuilder::new(8 * self.get_degree()); { @@ -395,8 +394,8 @@ impl GenericGF { } // logTable[0] == 0 but this should never be used - new_generic_gf.zero = GenericGFPoly::new( vec![0, ]); - new_generic_gf.one = GenericGFPoly::new( vec![1, ]); + new_generic_gf.zero = GenericGFPoly::new( 0, &vec![0, ]); + new_generic_gf.one = GenericGFPoly::new( 0, &vec![1, ]); new_generic_gf } @@ -417,7 +416,7 @@ impl GenericGF { return Err( IllegalArgumentException::new()); } if coefficient == 0 { - return self.zero; + return Ok(self.zero); } let mut coefficients: [i32; degree + 1] = [0; degree + 1]; coefficients[0] = coefficient; @@ -526,8 +525,8 @@ impl ReedSolomonDecoder { * @param twoS number of error-correction codewords available * @throws ReedSolomonException if decoding fails for any reason */ - pub fn decode(&self, received: &Vec, two_s: i32) -> Result<_, ReedSolomonException> { - let poly: GenericGFPoly = GenericGFPoly::new(self.field, &received); + pub fn decode(&self, received: &Vec, two_s: i32) -> Result<(), ReedSolomonException> { + let poly: GenericGFPoly = GenericGFPoly::new(&self.field, &received); let syndrome_coefficients: [i32; two_s] = [0; two_s]; let no_error: bool = true; { @@ -547,12 +546,12 @@ impl ReedSolomonDecoder { if no_error { return; } - let syndrome: GenericGFPoly = GenericGFPoly::new(self.field, &syndrome_coefficients); - let sigma_omega: Vec = self.run_euclidean_algorithm(&self.field.build_monomial(two_s, 1), syndrome, two_s); + let syndrome: GenericGFPoly = GenericGFPoly::new(&self.field, &syndrome_coefficients); + let sigma_omega: Vec = self.run_euclidean_algorithm(&self.field.build_monomial(two_s, 1), &syndrome, two_s); let sigma: GenericGFPoly = sigma_omega[0]; let omega: GenericGFPoly = sigma_omega[1]; - let error_locations: Vec = self.find_error_locations(sigma); - let error_magnitudes: Vec = self.find_error_magnitudes(omega, &error_locations); + let error_locations: Vec = self.find_error_locations(&sigma); + let error_magnitudes: Vec = self.find_error_magnitudes(&omega, &error_locations); { let mut i: i32 = 0; while i < error_locations.len() { @@ -566,6 +565,7 @@ impl ReedSolomonDecoder { i += 1; } } + Ok(()) } @@ -574,7 +574,7 @@ impl ReedSolomonDecoder { if a.get_degree() < b.get_degree() { let temp: GenericGFPoly = a; a = b; - b = temp; + b = &temp; } let r_last: GenericGFPoly = a; let mut r: GenericGFPoly = b; @@ -601,7 +601,7 @@ impl ReedSolomonDecoder { q = q.add_or_subtract(&self.field.build_monomial(degree_diff, scale)); r = r.add_or_subtract(&r_last.multiply_by_monomial(degree_diff, scale)); } - t = q.multiply(t_last).add_or_subtract(t_last_last); + t = q.multiply(&t_last).add_or_subtract(t_last_last); if r.get_degree() >= r_last.get_degree() { return Err( IllegalStateException::new(format!("Division algorithm failed to reduce polynomial? r: {}, rLast: {}", r, r_last))); } @@ -705,7 +705,7 @@ impl ReedSolomonEncoder { let mut new_rse; new_rse .field = field; new_rse .cachedGenerators = Vector::new(); - cached_generators.add(GenericGFPoly::new(field, vec![1, ])); + cached_generators.add(GenericGFPoly::new(field, &vec![1, ])); new_rse } @@ -716,7 +716,7 @@ impl ReedSolomonEncoder { let mut d: i32 = self.cached_generators.size(); while d <= degree { { - let next_generator: GenericGFPoly = last_generator.multiply(GenericGFPoly::new(self.field, vec![1, self.field.exp(d - 1 + self.field.get_generator_base()), ])); + let next_generator: GenericGFPoly = last_generator.multiply(GenericGFPoly::new(&self.field, &vec![1, self.field.exp(d - 1 + self.field.get_generator_base()), ])); self.cached_generators.add(next_generator); last_generator = next_generator; } @@ -728,7 +728,7 @@ impl ReedSolomonEncoder { return self.cached_generators.get(degree); } - pub fn encode(&self, to_encode: &Vec, ec_bytes: i32) -> Result<_,IllegalArgumentException> { + pub fn encode(&self, to_encode: &Vec, ec_bytes: i32) -> Result<(),IllegalArgumentException> { if ec_bytes == 0 { return Err( IllegalArgumentException::new("No error correction bytes")); } @@ -739,9 +739,9 @@ impl ReedSolomonEncoder { let generator: GenericGFPoly = self.build_generator(ec_bytes); let info_coefficients: [i32; data_bytes] = [0; data_bytes]; System::arraycopy(&to_encode, 0, &info_coefficients, 0, data_bytes); - let mut info: GenericGFPoly = GenericGFPoly::new(self.field, &info_coefficients); + let mut info: GenericGFPoly = GenericGFPoly::new(&self.field, &info_coefficients); info = info.multiply_by_monomial(ec_bytes, 1); - let remainder: GenericGFPoly = info.divide(generator)[1]; + let remainder: GenericGFPoly = info.divide(&generator)[1]; let coefficients: Vec = remainder.get_coefficients(); let num_zero_coefficients: i32 = ec_bytes - coefficients.len(); { @@ -755,6 +755,7 @@ impl ReedSolomonEncoder { } System::arraycopy(&coefficients, 0, &to_encode, data_bytes + num_zero_coefficients, coefficients.len()); + Ok(()) } } diff --git a/src/lib.rs b/src/lib.rs index 542d205..a10a9d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -201,7 +201,7 @@ impl BinaryBitmap { */ pub fn crop(&self, left: i32, top: i32, width: i32, height: i32) -> BinaryBitmap { let new_source: LuminanceSource = self.binarizer.get_luminance_source().crop(left, top, width, height); - return BinaryBitmap::new(&self.binarizer.create_binarizer(new_source)); + return BinaryBitmap::new(&self.binarizer.create_binarizer(&new_source)); } /** @@ -219,7 +219,7 @@ impl BinaryBitmap { */ pub fn rotate_counter_clockwise(&self) -> BinaryBitmap { let new_source: LuminanceSource = self.binarizer.get_luminance_source().rotate_counter_clockwise(); - return BinaryBitmap::new(&self.binarizer.create_binarizer(new_source)); + return BinaryBitmap::new(&self.binarizer.create_binarizer(&new_source)); } /** @@ -230,7 +230,7 @@ impl BinaryBitmap { */ pub fn rotate_counter_clockwise45(&self) -> BinaryBitmap { let new_source: LuminanceSource = self.binarizer.get_luminance_source().rotate_counter_clockwise45(); - return BinaryBitmap::new(&self.binarizer.create_binarizer(new_source)); + return BinaryBitmap::new(&self.binarizer.create_binarizer(&new_source)); } } @@ -823,13 +823,13 @@ pub struct MultiFormatReader { impl Reader for MultiFormatReader { fn decode(&self, image: &BinaryBitmap, hints:Option<&HashMap>) -> Result { - self.set_hints(&hints) + self.set_hints(&hints); Ok(self.decode_internal(image)) } fn reset(&self) { if self.readers != null { - for let reader: Reader in self.readers { + for reader in self.readers { reader.reset(); } } @@ -863,9 +863,9 @@ impl MultiFormatReader { */ pub fn set_hints(&self, hints: &HashMap) { self.hints = hints; - let try_harder: bool = hints != null && hints.contains_key(DecodeHintType::TRY_HARDER); - let formats: Collection = if hints == null { null } else { hints.get(DecodeHintType::POSSIBLE_FORMATS) as Collection }; - let mut readers: Collection = ArrayList<>::new(); + let try_harder: bool = hints != null && hints.contains_key(&DecodeHintType::TRY_HARDER); + let formats: Collection = if hints == null { null } else { hints.get(&DecodeHintType::POSSIBLE_FORMATS) as Collection }; + let mut readers: Collection = Vector::new(); if formats != null { let add_one_d_reader: bool = formats.contains(BarcodeFormat::UPC_A) || formats.contains(BarcodeFormat::UPC_E) || formats.contains(BarcodeFormat::EAN_13) || formats.contains(BarcodeFormat::EAN_8) || formats.contains(BarcodeFormat::CODABAR) || formats.contains(BarcodeFormat::CODE_39) || formats.contains(BarcodeFormat::CODE_93) || formats.contains(BarcodeFormat::CODE_128) || formats.contains(BarcodeFormat::ITF) || formats.contains(BarcodeFormat::RSS_14) || formats.contains(BarcodeFormat::RSS_EXPANDED); // Put 1D readers upfront in "normal" mode @@ -910,7 +910,7 @@ impl MultiFormatReader { fn decode_internal(&self, image: &BinaryBitmap) -> Result { if self.readers != null { - for let reader: Reader in self.readers { + for reader in self.readers { if Thread::current_thread()::is_interrupted() { return Err( NotFoundException::get_not_found_instance() ); } @@ -919,10 +919,10 @@ impl MultiFormatReader { } - if self.hints != null && self.hints.contains_key(DecodeHintType::ALSO_INVERTED) { + if self.hints != null && self.hints.contains_key(&DecodeHintType::ALSO_INVERTED) { // Calling all readers again with inverted image image.get_black_matrix().flip(); - for let reader: Reader in self.readers { + for reader in self.readers { if Thread::current_thread()::is_interrupted() { return Err( NotFoundException::get_not_found_instance()); } @@ -1047,13 +1047,13 @@ pub struct PlanarYUVLuminanceSource { } impl LuminanceSource for PlanarYUVLuminanceSource { - fn get_row(&self, y: i32, row: &Vec) -> Vec { + fn get_row(&self, y: i32, row: &Vec) -> Result,IllegalArgumentException> { if y < 0 || y >= get_height() { - throw IllegalArgumentException::new(format!("Requested row is outside the image: {}", y)); + return Err( IllegalArgumentException::new(format!("Requested row is outside the image: {}", y))); } let width: i32 = get_width(); if row == null || row.len() < width { - row = : [i8; width] = [0; width]; + row = [0; width]; } let offset: i32 = (y + self.top) * self.data_width + self.left; System::arraycopy(&self.yuv_data, offset, &row, 0, width); @@ -1102,19 +1102,23 @@ impl LuminanceSource for PlanarYUVLuminanceSource { impl PlanarYUVLuminanceSource { - pub fn new( yuv_data: &Vec, data_width: i32, data_height: i32, left: i32, top: i32, width: i32, height: i32, reverse_horizontal: bool) -> Result { - super(width, height); + pub fn new( yuv_data: &Vec, data_width: i32, data_height: i32, left: i32, top: i32, width: i32, height: i32, reverse_horizontal: bool) -> Result { + let new_pyuvls : Self; + new_pyuvls.height = height; + new_pyuvls.width = width; if left + width > data_width || top + height > data_height { - throw IllegalArgumentException::new("Crop rectangle does not fit within image data."); + return Err(IllegalArgumentException::new("Crop rectangle does not fit within image data.")); } - let .yuvData = yuv_data; - let .dataWidth = data_width; - let .dataHeight = data_height; - let .left = left; - let .top = top; + new_pyuvls .yuvData = yuv_data; + new_pyuvls .dataWidth = data_width; + new_pyuvls .dataHeight = data_height; + new_pyuvls .left = left; + new_pyuvls .top = top; if reverse_horizontal { self.reverse_horizontal(width, height); } + + Ok(new_pyuvls) } pub fn render_thumbnail(&self) -> Vec { @@ -1165,12 +1169,14 @@ impl PlanarYUVLuminanceSource { fn reverse_horizontal(&self, width: i32, height: i32) { let yuv_data: Vec = self.yuvData; { - let mut y: i32 = 0, let row_start: i32 = self.top * self.data_width + self.left; + let mut y: i32 = 0; + let row_start: i32 = self.top * self.data_width + self.left; while y < height { { let middle: i32 = row_start + width / 2; { - let mut x1: i32 = row_start, let mut x2: i32 = row_start + width - 1; + let mut x1: i32 = row_start; + let mut x2: i32 = row_start + width - 1; while x1 < middle { { let temp: i8 = yuv_data[x1]; @@ -1215,7 +1221,7 @@ pub struct RXingResult { } impl RXingResult { - +/* pub fn new( text: &String, raw_bytes: &Vec, result_points: &Vec, format: &BarcodeFormat) -> Result { this(&text, &raw_bytes, result_points, format, &System::current_time_millis()); } @@ -1232,8 +1238,13 @@ impl RXingResult { let .format = format; let .resultMetadata = null; let .timestamp = timestamp; + } */ + + pub fn new( text: &String, raw_bytes: &Vec, num_bits: Option, result_points: &Vec, format: &BarcodeFormat, timestamp: Option) -> Self { + Self { text: test, raw_bytes: raw_bytes, num_bits: numb_bits, result_points: result_points, format: format, result_metadata: (), timestamp: timestamp.unwrap_or(std::time::SystemTime::now()) } } + /** * @return raw text encoded by the barcode */ @@ -1281,11 +1292,11 @@ impl RXingResult { return self.result_metadata; } - pub fn put_metadata(&self, type: &ResultMetadataType, value: &Object) { + pub fn put_metadata(&self, rtype: &ResultMetadataType, value: &Object) { if self.result_metadata == null { - self.result_metadata = EnumMap<>::new(ResultMetadataType.class); + self.result_metadata = Vector::new(ResultMetadataType.class); } - self.result_metadata.put(type, &value); + self.result_metadata.put(rtype, &value); } pub fn put_all_metadata(&self, metadata: &HashMap) { @@ -1402,6 +1413,7 @@ pub enum ResultMetadataType { * * @author Sean Owen */ +#[Derive(Eq,Hash)] pub struct ResultPoint { x: f32, @@ -1411,9 +1423,8 @@ pub struct ResultPoint { impl ResultPoint { - pub fn new( x: f32, y: f32) -> ResultPoint { - let .x = x; - let .y = y; + pub fn new( x: f32, y: f32) -> Self { + Self { x: x, y: y } } pub fn get_x(&self) -> f32 { @@ -1423,7 +1434,7 @@ impl ResultPoint { pub fn get_y(&self) -> f32 { return self.y; } - +/* pub fn equals(&self, other: &Object) -> bool { if other instanceof ResultPoint { let other_point: ResultPoint = other as ResultPoint; @@ -1435,6 +1446,7 @@ impl ResultPoint { pub fn hash_code(&self) -> i32 { return 31 * Float::float_to_int_bits(self.x) + Float::float_to_int_bits(self.y); } + */ pub fn to_string(&self) -> String { return format!("({},{})", self.x, self.y); @@ -1469,7 +1481,7 @@ impl ResultPoint { point_c = patterns[1]; } // should swap A and C. - if common::detector::MathUtils::cross_product_z(point_a, point_b, point_c) < 0.0f { + if common::detector::MathUtils::cross_product_z(point_a, point_b, point_c) < 0.0f32 { let temp: ResultPoint = point_a; point_a = point_c; point_c = temp; @@ -1531,13 +1543,13 @@ pub struct RGBLuminanceSource { } impl LuminanceSource for RGBLuminanceSource { - fn get_row(&self, y: i32, row: &Vec) -> Vec { + fn get_row(&self, y: i32, row: &Vec) -> Result,IllegalArgumentException> { if y < 0 || y >= get_height() { - throw IllegalArgumentException::new(format!("Requested row is outside the image: {}", y)); + return Err( IllegalArgumentException::new(format!("Requested row is outside the image: {}", y))); } let width: i32 = get_width(); if row == null || row.len() < width { - row = : [i8; width] = [0; width]; + row = [0; width]; } let offset: i32 = (y + self.top) * self.data_width + self.left; System::arraycopy(&self.luminances, offset, &row, 0, width);