From 7996f42c648fd6a3c8c429ec0b630b2c9277ea32 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Fri, 6 Jan 2023 10:45:40 -0600 Subject: [PATCH] fix missing result point callback --- Cargo.toml | 2 +- README.md | 2 ++ src/oned/ean_manufacturer_org_support.rs | 10 ++++++---- src/oned/rss/rss_14_reader.rs | 25 +++++++++++------------- src/oned/upc_ean_reader.rs | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c39cfd..39116f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rxing" -version = "0.2.5" +version = "0.2.6" description="A rust port of the zxing barcode library." license="Apache-2.0" repository="https://github.com/hschimke/rxing" diff --git a/README.md b/README.md index 7e49c22..177ccca 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ fn main() { ``` ## Latest Release Notes +v0.2.6 -> Fix missing result point callback for rss14 + v0.2.4 -> Add helper functions for common cases (read a file, use raw luma8 data). v0.2.3 -> Implement most suggestions from clippy, as well as some simple changes, no surface changes. diff --git a/src/oned/ean_manufacturer_org_support.rs b/src/oned/ean_manufacturer_org_support.rs index 33cfde7..9099fd1 100644 --- a/src/oned/ean_manufacturer_org_support.rs +++ b/src/oned/ean_manufacturer_org_support.rs @@ -23,6 +23,7 @@ * * @author Sean Owen */ + pub struct EANManufacturerOrgSupport { ranges: Vec>, //= new ArrayList<>(); countryIdentifiers: Vec, // = new ArrayList<>(); @@ -40,13 +41,14 @@ impl Default for EANManufacturerOrgSupport { } impl EANManufacturerOrgSupport { - pub fn lookupCountryIdentifier(&self, productCode: &str) -> Option { + pub fn lookupCountryIdentifier(&self, productCode: &str) -> Option<&str> { let prefix = productCode[0..3].parse::().expect("must parse prefix"); // let prefix = Integer.parseInt(productCode.substring(0, 3)); let max = self.ranges.len(); - for i in 0..max { + for (i, range) in self.ranges.iter().enumerate().take(max) { + // for i in 0..max { // for (int i = 0; i < max; i++) { - let range = self.ranges.get(i).expect("must have index i or fail"); + // let range = self.ranges.get(i).expect("must have index i or fail"); let start = range[0]; if prefix < start { return None; @@ -57,7 +59,7 @@ impl EANManufacturerOrgSupport { self.countryIdentifiers .get(i) .expect("must have index i or fail") - .clone(), + // .clone(), ); } } diff --git a/src/oned/rss/rss_14_reader.rs b/src/oned/rss/rss_14_reader.rs index b55a492..5ba8563 100644 --- a/src/oned/rss/rss_14_reader.rs +++ b/src/oned/rss/rss_14_reader.rs @@ -20,7 +20,7 @@ use crate::{ common::BitArray, oned::{one_d_reader, OneDReader}, BarcodeFormat, DecodeHintType, DecodingHintDictionary, Exceptions, RXingResult, - RXingResultMetadataType, RXingResultMetadataValue, Reader, + RXingResultMetadataType, RXingResultMetadataValue, Reader, DecodeHintValue, RXingResultPoint, }; use super::{ @@ -257,24 +257,21 @@ impl RSS14Reader { row: &BitArray, right: bool, rowNumber: u32, - _hints: &DecodingHintDictionary, + hints: &DecodingHintDictionary, ) -> Option { let pos_pair = || -> Result { let startEnd = self.findFinderPattern(row, right)?; let pattern = self.parseFoundFinderPattern(row, rowNumber, right, &startEnd)?; - // RXingResultPointCallback resultPointCallback = hints == null ? null : - // (RXingResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); - - // if (resultPointCallback != null) { - // startEnd = pattern.getStartEnd(); - // float center = (startEnd[0] + startEnd[1] - 1) / 2.0f; - // if (right) { - // // row is actually reversed - // center = row.getSize() - 1 - center; - // } - // resultPointCallback.foundPossibleRXingResultPoint(new RXingResultPoint(center, rowNumber)); - // } + if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK) { + let startEnd = pattern.getStartEnd(); + let mut center :f32 = (startEnd[0] + startEnd[1] - 1) as f32 / 2.0; + if right { + // row is actually reversed + center = row.getSize() as f32 - 1.0 - center; + } + cb( &RXingResultPoint::new(center, rowNumber as f32)); + } let outside = self.decodeDataCharacter(row, &pattern, true)?; let inside = self.decodeDataCharacter(row, &pattern, false)?; diff --git a/src/oned/upc_ean_reader.rs b/src/oned/upc_ean_reader.rs index 8298cc6..52ca523 100644 --- a/src/oned/upc_ean_reader.rs +++ b/src/oned/upc_ean_reader.rs @@ -294,7 +294,7 @@ pub trait UPCEANReader: OneDReader { if let Some(cid) = countryID { decodeRXingResult.putMetadata( RXingResultMetadataType::POSSIBLE_COUNTRY, - RXingResultMetadataValue::PossibleCountry(cid), + RXingResultMetadataValue::PossibleCountry(cid.to_owned()), ); } }