change to using once_cell for lazy init

This commit is contained in:
Henry Schimke
2023-01-05 10:53:55 -06:00
parent d2a4b21808
commit 20764559ae
37 changed files with 556 additions and 608 deletions

View File

@@ -15,7 +15,7 @@ exclude = [
[dependencies] [dependencies]
regex = "1.7.0" regex = "1.7.0"
fancy-regex = "0.10" fancy-regex = "0.10"
lazy_static = "1.4.0" once_cell = "1.17.0"
encoding = "0.2" encoding = "0.2"
rand = "0.8.5" rand = "0.8.5"
urlencoding = "2.1.2" urlencoding = "2.1.2"

View File

@@ -2,12 +2,10 @@ use regex::Regex;
use crate::common::BitArray; use crate::common::BitArray;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static SPACES: Lazy<Regex> = Lazy::new(|| Regex::new("\\s+").unwrap());
static ref SPACES: Regex = Regex::new("\\s+").unwrap(); static DOTX: Lazy<Regex> = Lazy::new(|| Regex::new("[^.X]").unwrap());
static ref DOTX: Regex = Regex::new("[^.X]").unwrap();
}
#[allow(dead_code)] #[allow(dead_code)]
pub fn toBitArray(bits: &str) -> BitArray { pub fn toBitArray(bits: &str) -> BitArray {

View File

@@ -29,7 +29,7 @@
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc}; use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use chrono_tz::Tz; use chrono_tz::Tz;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use crate::exceptions::Exceptions; use crate::exceptions::Exceptions;
@@ -46,11 +46,11 @@ const RFC2445_DURATION_FIELD_UNITS: [i64; 5] = [
1000i64, // 1 second 1000i64, // 1 second
]; ];
lazy_static! { static DATE_TIME: Lazy<Regex> = Lazy::new(|| Regex::new("[0-9]{8}(T[0-9]{6}Z?)?").unwrap());
static ref DATE_TIME: Regex = Regex::new("[0-9]{8}(T[0-9]{6}Z?)?").unwrap(); static RFC2445_DURATION: Lazy<Regex> = Lazy::new(|| {
static ref RFC2445_DURATION: Regex = Regex::new("P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?").unwrap()
Regex::new("P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?").unwrap(); });
}
// const DATE_TIME: &'static str = "[0-9]{8}(T[0-9]{6}Z?)?"; // const DATE_TIME: &'static str = "[0-9]{8}(T[0-9]{6}Z?)?";
/** /**

View File

@@ -24,13 +24,11 @@
use regex::Regex; use regex::Regex;
use crate::RXingResult; use crate::RXingResult;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(",").unwrap());
static ref COMMA: Regex = Regex::new(",").unwrap(); static ATEXT_ALPHANUMERIC: Lazy<Regex> =
static ref ATEXT_ALPHANUMERIC: Regex = Lazy::new(|| Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap());
Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap();
}
use super::{ use super::{
EmailAddressParsedRXingResult, EmailDoCoMoResultParser, ParsedClientResult, ResultParser, EmailAddressParsedRXingResult, EmailDoCoMoResultParser, ParsedClientResult, ResultParser,

View File

@@ -26,12 +26,10 @@ use crate::RXingResult;
use super::{EmailAddressParsedRXingResult, ParsedClientResult, ResultParser}; use super::{EmailAddressParsedRXingResult, ParsedClientResult, ResultParser};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static ATEXT_ALPHANUMERIC: Lazy<Regex> =
static ref ATEXT_ALPHANUMERIC: Regex = Lazy::new(|| Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap());
Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap();
}
/** /**
* Implements the "MATMSG" email message entry format. * Implements the "MATMSG" email message entry format.

View File

@@ -23,11 +23,9 @@
use super::{GeoParsedRXingResult, ParsedClientResult, ResultParser}; use super::{GeoParsedRXingResult, ParsedClientResult, ResultParser};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static GEO_URL: Lazy<regex::Regex> = Lazy::new(|| regex::Regex::new(GEO_URL_PATTERN).unwrap());
static ref GEO_URL: regex::Regex = regex::Regex::new(GEO_URL_PATTERN).unwrap();
}
const GEO_URL_PATTERN: &str = "geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?"; const GEO_URL_PATTERN: &str = "geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?";

View File

@@ -31,7 +31,7 @@ use std::collections::HashMap;
use regex::Regex; use regex::Regex;
use urlencoding::decode; use urlencoding::decode;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::{exceptions::Exceptions, RXingResult}; use crate::{exceptions::Exceptions, RXingResult};
@@ -92,9 +92,7 @@ use super::{
pub type ParserFunction = dyn Fn(&RXingResult) -> Option<ParsedClientResult>; pub type ParserFunction = dyn Fn(&RXingResult) -> Option<ParsedClientResult>;
lazy_static! { static DIGITS: Lazy<Regex> = Lazy::new(|| Regex::new("\\d+").unwrap());
static ref DIGITS: Regex = Regex::new("\\d+").unwrap();
}
// const DIGITS: &'static str = "\\d+"; //= Pattern.compile("\\d+"); // const DIGITS: &'static str = "\\d+"; //= Pattern.compile("\\d+");
const AMPERSAND: &str = "&"; // private static final Pattern AMPERSAND = Pattern.compile("&"); const AMPERSAND: &str = "&"; // private static final Pattern AMPERSAND = Pattern.compile("&");

View File

@@ -21,7 +21,7 @@
// import java.util.regex.Matcher; // import java.util.regex.Matcher;
// import java.util.regex.Pattern; // import java.util.regex.Pattern;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
/** /**
* Tries to parse results that are a URI of some kind. * Tries to parse results that are a URI of some kind.
* *
@@ -34,15 +34,15 @@ use crate::RXingResult;
use super::{ParsedClientResult, ResultParser, URIParsedRXingResult}; use super::{ParsedClientResult, ResultParser, URIParsedRXingResult};
lazy_static! { static ALLOWED_URI_CHARS: Lazy<Regex> = Lazy::new(|| {
static ref ALLOWED_URI_CHARS: Regex = Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile")
Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile"); });
static ref USER_IN_HOST: Regex = static USER_IN_HOST: Lazy<Regex> =
Regex::new(":/*([^/@]+)@[^/]+").expect("Regex patterns should always copile"); Lazy::new(|| Regex::new(":/*([^/@]+)@[^/]+").expect("Regex patterns should always copile"));
static ref URL_WITH_PROTOCOL_PATTERN: Regex = Regex::new("[a-zA-Z][a-zA-Z0-9+-.]+:").unwrap(); static URL_WITH_PROTOCOL_PATTERN: Lazy<Regex> =
static ref URL_WITHOUT_PROTOCOL_PATTERN: Regex = Lazy::new(|| Regex::new("[a-zA-Z][a-zA-Z0-9+-.]+:").unwrap());
Regex::new("([a-zA-Z0-9\\-]+\\.){1,6}[a-zA-Z]{2,}(:\\d{1,5})?(/|\\?|$)").unwrap(); static URL_WITHOUT_PROTOCOL_PATTERN: Lazy<Regex> =
} Lazy::new(|| Regex::new("([a-zA-Z0-9\\-]+\\.){1,6}[a-zA-Z]{2,}(:\\d{1,5})?(/|\\?|$)").unwrap());
const ALLOWED_URI_CHARS_PATTERN: &str = "[-._~:/?#\\[\\]@!$&'()*+,;=%A-Za-z0-9]+"; const ALLOWED_URI_CHARS_PATTERN: &str = "[-._~:/?#\\[\\]@!$&'()*+,;=%A-Za-z0-9]+";
// const USER_IN_HOST: &'static str = ":/*([^/@]+)@[^/]+"; // const USER_IN_HOST: &'static str = ":/*([^/@]+)@[^/]+";

View File

@@ -32,7 +32,7 @@ use std::convert::TryFrom;
use regex::Regex; use regex::Regex;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::RXingResult; use crate::RXingResult;
@@ -40,17 +40,15 @@ use uriparse::URI;
use super::{AddressBookParsedRXingResult, ParsedClientResult, ResultParser}; use super::{AddressBookParsedRXingResult, ParsedClientResult, ResultParser};
lazy_static! { static BEGIN_VCARD: Lazy<Regex> = Lazy::new(|| Regex::new("(?i:BEGIN:VCARD)").unwrap());
static ref BEGIN_VCARD: Regex = Regex::new("(?i:BEGIN:VCARD)").unwrap(); static VCARD_LIKE_DATE: Lazy<Regex> = Lazy::new(|| Regex::new("\\d{4}-?\\d{2}-?\\d{2}").unwrap());
static ref VCARD_LIKE_DATE: Regex = Regex::new("\\d{4}-?\\d{2}-?\\d{2}").unwrap(); static CR_LF_SPACE_TAB: Lazy<Regex> = Lazy::new(|| Regex::new("\r\n[ \t]").unwrap());
static ref CR_LF_SPACE_TAB: Regex = Regex::new("\r\n[ \t]").unwrap(); static NEWLINE_ESCAPE: Lazy<Regex> = Lazy::new(|| Regex::new("\\\\[nN]").unwrap());
static ref NEWLINE_ESCAPE: Regex = Regex::new("\\\\[nN]").unwrap(); static VCARD_ESCAPE: Lazy<Regex> = Lazy::new(|| Regex::new("\\\\([,;\\\\])").unwrap());
static ref VCARD_ESCAPE: Regex = Regex::new("\\\\([,;\\\\])").unwrap(); static EQUALS: Lazy<Regex> = Lazy::new(|| Regex::new("=").unwrap());
static ref EQUALS: Regex = Regex::new("=").unwrap(); static UNESCAPED_SEMICOLONS: Lazy<fancy_regex::Regex> =
static ref UNESCAPED_SEMICOLONS: fancy_regex::Regex = Lazy::new(|| fancy_regex::Regex::new("(?<!\\\\);+").unwrap());
fancy_regex::Regex::new("(?<!\\\\);+").unwrap(); static SEMICOLON_OR_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new("[;,]").unwrap());
static ref SEMICOLON_OR_COMMA: Regex = Regex::new("[;,]").unwrap();
}
// const BEGIN_VCARD: &'static str = "(?i:BEGIN:VCARD)"; //, Pattern.CASE_INSENSITIVE); // const BEGIN_VCARD: &'static str = "(?i:BEGIN:VCARD)"; //, Pattern.CASE_INSENSITIVE);
// const VCARD_LIKE_DATE: &'static str = "\\d{4}-?\\d{2}-?\\d{2}"; // const VCARD_LIKE_DATE: &'static str = "\\d{4}-?\\d{2}-?\\d{2}";

View File

@@ -29,12 +29,10 @@ use crate::{
use super::ParsedClientResult; use super::ParsedClientResult;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static IOQ_MATCHER: Lazy<Regex> = Lazy::new(|| Regex::new(IOQ).unwrap());
static ref IOQ_MATCHER: Regex = Regex::new(IOQ).unwrap(); static AZ09_MATCHER: Lazy<Regex> = Lazy::new(|| Regex::new(AZ09).unwrap());
static ref AZ09_MATCHER: Regex = Regex::new(AZ09).unwrap();
}
/** /**
* Detects a result that is likely a vehicle identification number. * Detects a result that is likely a vehicle identification number.

View File

@@ -56,11 +56,7 @@ fn test_short_shift_jis1() {
#[test] #[test]
fn test_short_iso885911() { fn test_short_iso885911() {
// båd // båd
do_test( do_test(&[0x62, 0xe5, 0x64], encoding::all::ISO_8859_1, "ISO8859_1");
&[0x62, 0xe5, 0x64],
encoding::all::ISO_8859_1,
"ISO8859_1",
);
} }
#[test] #[test]

View File

@@ -28,23 +28,22 @@ use unicode_segmentation::UnicodeSegmentation;
use super::CharacterSetECI; use super::CharacterSetECI;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static ENCODERS: Lazy<Vec<EncodingRef>> = Lazy::new(|| {
static ref ENCODERS : Vec<EncodingRef> = { let mut enc_vec = Vec::new();
let mut enc_vec = Vec::new(); for name in NAMES {
for name in NAMES { if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) {
if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) { // try {
// try { enc_vec.push(CharacterSetECI::getCharset(&enc));
enc_vec.push(CharacterSetECI::getCharset(&enc)); // } catch (UnsupportedCharsetException e) {
// } catch (UnsupportedCharsetException e) { // continue
// continue // }
// }
}
} }
enc_vec }
}; enc_vec
} });
const NAMES: [&str; 20] = [ const NAMES: [&str; 20] = [
"IBM437", "IBM437",
"ISO-8859-2", "ISO-8859-2",

View File

@@ -22,18 +22,14 @@ pub(crate) mod ReedSolomonTestCase;
//package com.google.zxing.common.reedsolomon; //package com.google.zxing.common.reedsolomon;
pub type GenericGFRef = &'static GenericGF; pub type GenericGFRef = &'static GenericGF;
use once_cell::sync::Lazy;
use lazy_static::lazy_static; static AZTEC_DATA_12: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x1069, 4096, 1)); // x^12 + x^6 + x^5 + x^3 + 1
static AZTEC_DATA_10: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x409, 1024, 1)); // x^10 + x^3 + 1
lazy_static! { static AZTEC_DATA_6: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x43, 64, 1)); // x^6 + x + 1
static ref AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1 static AZTEC_PARAM: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x13, 16, 1)); // x^4 + x + 1
static ref AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1 static QR_CODE_FIELD_256: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x011D, 256, 0)); // x^8 + x^4 + x^3 + x^2 + 1
static ref AZTEC_DATA_6: GenericGF = GenericGF::new(0x43, 64, 1); // x^6 + x + 1 static DATA_MATRIX_FIELD_256: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x012D, 256, 1)); // x^8 + x^5 + x^3 + x^2 + 1
static ref AZTEC_PARAM: GenericGF = GenericGF::new(0x13, 16, 1); // x^4 + x + 1
static ref QR_CODE_FIELD_256: GenericGF = GenericGF::new(0x011D, 256, 0); // x^8 + x^4 + x^3 + x^2 + 1
static ref DATA_MATRIX_FIELD_256: GenericGF = GenericGF::new(0x012D, 256, 1); // x^8 + x^5 + x^3 + x^2 + 1
// static ref PDF_417_FIELD: GenericGF = GenericGF::new(3,crate::pdf417::pdf_417_common::NUMBER_OF_CODEWORDS as usize,1);
}
// pub const AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1 // pub const AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
// pub const AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1 // pub const AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1

View File

@@ -24,7 +24,7 @@ use encoding::{Encoding, EncodingRef};
use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary}; use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
/** /**
* Common string-related functions. * Common string-related functions.
@@ -55,10 +55,9 @@ pub struct StringUtils {
const ASSUME_SHIFT_JIS: bool = false; const ASSUME_SHIFT_JIS: bool = false;
// static SHIFT_JIS: &'static str = "SJIS"; // static SHIFT_JIS: &'static str = "SJIS";
// static GB2312: &'static str = "GB2312"; // static GB2312: &'static str = "GB2312";
lazy_static! {
pub static ref SHIFT_JIS_CHARSET: EncodingRef = pub static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
encoding::label::encoding_from_whatwg_label("SJIS").unwrap(); Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
}
// private static final boolean ASSUME_SHIFT_JIS = // private static final boolean ASSUME_SHIFT_JIS =
// SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) || // SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) ||

View File

@@ -24,11 +24,9 @@ use crate::{
use super::{decoder::Decoder, detector::Detector}; use super::{decoder::Decoder, detector::Detector};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static DECODER: Lazy<Decoder> = Lazy::new(|| Decoder::new());
static ref DECODER: Decoder = Decoder::new();
}
/** /**
* This implementation can detect and decode Data Matrix codes in an image. * This implementation can detect and decode Data Matrix codes in an image.

View File

@@ -15,13 +15,11 @@
*/ */
use core::fmt; use core::fmt;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::Exceptions; use crate::Exceptions;
lazy_static! { static VERSIONS: Lazy<Vec<Version>> = Lazy::new(|| Version::buildVersions());
static ref VERSIONS: Vec<Version> = Version::buildVersions();
}
pub type VersionRef = &'static Version; pub type VersionRef = &'static Version;

View File

@@ -18,7 +18,7 @@ use crate::Exceptions;
use super::SymbolInfo; use super::SymbolInfo;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
/** /**
* Error Correction Code for ECC200. * Error Correction Code for ECC200.
@@ -30,66 +30,68 @@ use lazy_static::lazy_static;
*/ */
const FACTOR_SETS: [u32; 16] = [5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68]; const FACTOR_SETS: [u32; 16] = [5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68];
lazy_static! {
/** /**
* Precomputed polynomial factors for ECC 200. * Precomputed polynomial factors for ECC 200.
*/ */
static ref FACTORS: [Vec<u32>; 16] = [ static FACTORS: Lazy<[Vec<u32>; 16]> = Lazy::new(|| {
Vec::from([228, 48, 15, 111, 62]), [
Vec::from([23, 68, 144, 134, 240, 92, 254]), Vec::from([228, 48, 15, 111, 62]),
Vec::from([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]), Vec::from([23, 68, 144, 134, 240, 92, 254]),
Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]), Vec::from([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]),
Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]), Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]),
Vec::from([ Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]),
156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185, Vec::from([
]), 156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185,
Vec::from([ ]),
83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188, Vec::from([
]), 83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188,
Vec::from([ ]),
15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172, Vec::from([
]), 15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186,
Vec::from([ 172,
52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 254, 124, 12, 181, ]),
184, 96, 50, 193, Vec::from([
]), 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 254, 124, 12,
Vec::from([ 181, 184, 96, 50, 193,
211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17, 138, 110, 213, ]),
141, 136, 120, 151, 233, 168, 93, 255, Vec::from([
]), 211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17, 138, 110,
Vec::from([ 213, 141, 136, 120, 151, 233, 168, 93, 255,
245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182, 229, 18, 2, ]),
4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25, 225, 98, 81, 112, Vec::from([
]), 245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182, 229, 18,
Vec::from([ 2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25, 225, 98, 81, 112,
77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175, 95, 100, 9, ]),
167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226, 5, Vec::from([
9, 5, 77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175, 95, 100, 9,
]), 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226,
Vec::from([ 5, 9, 5,
245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87, 191, 106, 16, ]),
147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, 176, 87, 187, Vec::from([
147, 160, 175, 69, 213, 92, 253, 225, 19, 245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87, 191, 106,
]), 16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, 176,
Vec::from([ 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19,
175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235, 150, 159, 36, ]),
223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232, 144, 238, 22, 150, 201, 117, Vec::from([
62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53, 143, 46, 175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235, 150, 159,
]), 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232, 144, 238, 22, 150,
Vec::from([ 201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53,
242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37, 185, 112, 134, 143, 46,
230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27, 218, 51, ]),
63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, Vec::from([
11, 204, 242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37, 185, 112,
]), 134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27,
Vec::from([ 218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224,
220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127, 213, 136, 248, 124, 86, 47, 11, 204,
180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 66, 139, 153, 185, 202, 167, ]),
179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25, 49, 232, 211, Vec::from([
189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186, 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127, 213, 136,
]), 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 66, 139, 153, 185,
]; 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25,
} 49, 232, 211, 189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186,
]),
]
});
const MODULO_VALUE: usize = 0x12D; const MODULO_VALUE: usize = 0x12D;

View File

@@ -16,27 +16,26 @@
use std::rc::Rc; use std::rc::Rc;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::datamatrix::encoder::{SymbolInfo, SymbolShapeHint}; use crate::datamatrix::encoder::{SymbolInfo, SymbolShapeHint};
use super::{high_level_encoder, minimal_encoder, symbol_info, SymbolInfoLookup}; use super::{high_level_encoder, minimal_encoder, symbol_info, SymbolInfoLookup};
lazy_static! { /**
/**
* Tests for {@link HighLevelEncoder} and {@link MinimalEncoder} * Tests for {@link HighLevelEncoder} and {@link MinimalEncoder}
*/ */
static ref TEST_SYMBOLS :Vec<SymbolInfo>= vec![ static TEST_SYMBOLS: Lazy<Vec<SymbolInfo>> = Lazy::new(|| {
SymbolInfo::new(false, 3, 5, 8, 8, 1), vec![
SymbolInfo::new(false, 5, 7, 10, 10, 1), SymbolInfo::new(false, 3, 5, 8, 8, 1),
/*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), SymbolInfo::new(false, 5, 7, 10, 10, 1),
SymbolInfo::new(false, 8, 10, 12, 12, 1), /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1),
/*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), SymbolInfo::new(false, 8, 10, 12, 12, 1),
SymbolInfo::new(false, 13, 0, 0, 0, 1), /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2),
SymbolInfo::new(false, 77, 0, 0, 0, 1) SymbolInfo::new(false, 13, 0, 0, 0, 1),
//The last entries are fake entries to test special conditions with C40 encoding SymbolInfo::new(false, 77, 0, 0, 0, 1), //The last entries are fake entries to test special conditions with C40 encoding
]; ]
} });
// const SIL: SymbolInfoLookup = SymbolInfoLookup::new(); // const SIL: SymbolInfoLookup = SymbolInfoLookup::new();

View File

@@ -19,42 +19,42 @@ use std::fmt;
use crate::{Dimension, Exceptions}; use crate::{Dimension, Exceptions};
use super::SymbolShapeHint; use super::SymbolShapeHint;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { pub(super) static PROD_SYMBOLS: Lazy<Vec<SymbolInfo>> = Lazy::new(|| {
pub(super) static ref PROD_SYMBOLS: Vec<SymbolInfo> = vec![ vec![
SymbolInfo::new(false, 3, 5, 8, 8, 1), SymbolInfo::new(false, 3, 5, 8, 8, 1),
SymbolInfo::new(false, 5, 7, 10, 10, 1), SymbolInfo::new(false, 5, 7, 10, 10, 1),
/*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1),
SymbolInfo::new(false, 8, 10, 12, 12, 1), SymbolInfo::new(false, 8, 10, 12, 12, 1),
/*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2),
SymbolInfo::new(false, 12, 12, 14, 14, 1), SymbolInfo::new(false, 12, 12, 14, 14, 1),
/*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1), /*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1),
SymbolInfo::new(false, 18, 14, 16, 16, 1), SymbolInfo::new(false, 18, 14, 16, 16, 1),
SymbolInfo::new(false, 22, 18, 18, 18, 1), SymbolInfo::new(false, 22, 18, 18, 18, 1),
/*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2), /*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2),
SymbolInfo::new(false, 30, 20, 20, 20, 1), SymbolInfo::new(false, 30, 20, 20, 20, 1),
/*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2), /*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2),
SymbolInfo::new(false, 36, 24, 22, 22, 1), SymbolInfo::new(false, 36, 24, 22, 22, 1),
SymbolInfo::new(false, 44, 28, 24, 24, 1), SymbolInfo::new(false, 44, 28, 24, 24, 1),
/*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2), /*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2),
SymbolInfo::new(false, 62, 36, 14, 14, 4), SymbolInfo::new(false, 62, 36, 14, 14, 4),
SymbolInfo::new(false, 86, 42, 16, 16, 4), SymbolInfo::new(false, 86, 42, 16, 16, 4),
SymbolInfo::new(false, 114, 48, 18, 18, 4), SymbolInfo::new(false, 114, 48, 18, 18, 4),
SymbolInfo::new(false, 144, 56, 20, 20, 4), SymbolInfo::new(false, 144, 56, 20, 20, 4),
SymbolInfo::new(false, 174, 68, 22, 22, 4), SymbolInfo::new(false, 174, 68, 22, 22, 4),
SymbolInfo::with_details(false, 204, 84, 24, 24, 4, 102, 42), SymbolInfo::with_details(false, 204, 84, 24, 24, 4, 102, 42),
SymbolInfo::with_details(false, 280, 112, 14, 14, 16, 140, 56), SymbolInfo::with_details(false, 280, 112, 14, 14, 16, 140, 56),
SymbolInfo::with_details(false, 368, 144, 16, 16, 16, 92, 36), SymbolInfo::with_details(false, 368, 144, 16, 16, 16, 92, 36),
SymbolInfo::with_details(false, 456, 192, 18, 18, 16, 114, 48), SymbolInfo::with_details(false, 456, 192, 18, 18, 16, 114, 48),
SymbolInfo::with_details(false, 576, 224, 20, 20, 16, 144, 56), SymbolInfo::with_details(false, 576, 224, 20, 20, 16, 144, 56),
SymbolInfo::with_details(false, 696, 272, 22, 22, 16, 174, 68), SymbolInfo::with_details(false, 696, 272, 22, 22, 16, 174, 68),
SymbolInfo::with_details(false, 816, 336, 24, 24, 16, 136, 56), SymbolInfo::with_details(false, 816, 336, 24, 24, 16, 136, 56),
SymbolInfo::with_details(false, 1050, 408, 18, 18, 36, 175, 68), SymbolInfo::with_details(false, 1050, 408, 18, 18, 36, 175, 68),
SymbolInfo::with_details(false, 1304, 496, 20, 20, 36, 163, 62), SymbolInfo::with_details(false, 1304, 496, 20, 20, 36, 163, 62),
SymbolInfo::new_symbol_info_144(), SymbolInfo::new_symbol_info_144(),
]; ]
} });
/** /**
* Symbol info table for DataMatrix. * Symbol info table for DataMatrix.

View File

@@ -36,7 +36,9 @@ pub fn detect_in_file_with_hints(
); );
} }
hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); hints
.entry(DecodeHintType::TRY_HARDER)
.or_insert(DecodeHintValue::TryHarder(true));
multi_format_reader.decode_with_hints( multi_format_reader.decode_with_hints(
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
@@ -60,7 +62,9 @@ pub fn detect_multiple_in_file_with_hints(
let multi_format_reader = MultiFormatReader::default(); let multi_format_reader = MultiFormatReader::default();
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader); let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); hints
.entry(DecodeHintType::TRY_HARDER)
.or_insert(DecodeHintValue::TryHarder(true));
scanner.decode_multiple_with_hints( scanner.decode_multiple_with_hints(
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
@@ -95,7 +99,9 @@ pub fn detect_in_luma_with_hints(
); );
} }
hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); hints
.entry(DecodeHintType::TRY_HARDER)
.or_insert(DecodeHintValue::TryHarder(true));
multi_format_reader.decode_with_hints( multi_format_reader.decode_with_hints(
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
@@ -122,7 +128,9 @@ pub fn detect_multiple_in_luma_with_hints(
let multi_format_reader = MultiFormatReader::default(); let multi_format_reader = MultiFormatReader::default();
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader); let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); hints
.entry(DecodeHintType::TRY_HARDER)
.or_insert(DecodeHintValue::TryHarder(true));
scanner.decode_multiple_with_hints( scanner.decode_multiple_with_hints(
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(

View File

@@ -98,4 +98,4 @@ pub use multi_format_reader::*;
pub mod helpers; pub mod helpers;
mod luma_luma_source; mod luma_luma_source;
pub use luma_luma_source::*; pub use luma_luma_source::*;

View File

@@ -17,7 +17,7 @@
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use crate::{common::DecoderRXingResult, Exceptions}; use crate::{common::DecoderRXingResult, Exceptions};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
/** /**
* <p>MaxiCodes can encode text or structured information as bits in one of several modes, * <p>MaxiCodes can encode text or structured information as bits in one of several modes,
@@ -59,8 +59,8 @@ const POSTCODE_3_BYTES: [[u8; 6]; 6] = [
[9, 10, 11, 12, 1, 2], [9, 10, 11, 12, 1, 2],
]; ];
lazy_static! { static SETS: Lazy<[String; 5]> = Lazy::new(|| {
static ref SETS : [String;5]= [ [
format!("\rABCDEFGHIJKLMNOPQRSTUVWXYZ{}{}{}{}{} {}\"#$%&'()*+,-./0123456789:{}{}{}{}{}" , ECI , FS , GS , RS , NS , PAD , format!("\rABCDEFGHIJKLMNOPQRSTUVWXYZ{}{}{}{}{} {}\"#$%&'()*+,-./0123456789:{}{}{}{}{}" , ECI , FS , GS , RS , NS , PAD ,
SHIFTB , SHIFTC , SHIFTD , SHIFTE , LATCHB), SHIFTB , SHIFTC , SHIFTD , SHIFTE , LATCHB),
format!("`abcdefghijklmnopqrstuvwxyz{}{}{}{}{}{{{}}}~\u{007F};<=>?[\\]^_ ,./:@!|{}{}{}{}{}{}{}{}{}" , ECI , FS , GS , RS , NS ,PAD , format!("`abcdefghijklmnopqrstuvwxyz{}{}{}{}{}{{{}}}~\u{007F};<=>?[\\]^_ ,./:@!|{}{}{}{}{}{}{}{}{}" , ECI , FS , GS , RS , NS ,PAD ,
@@ -78,8 +78,8 @@ static ref SETS : [String;5]= [
ECI , PAD , PAD , '\u{001B}' , NS , FS , GS , RS , ECI , PAD , PAD , '\u{001B}' , NS , FS , GS , RS ,
"\u{001F}\u{009F}\u{00A0}\u{00A2}\u{00A3}\u{00A4}\u{00A5}\u{00A6}\u{00A7}\u{00A9}\u{00AD}\u{00AE}\u{00B6}\u{0095}\u{0096}\u{0097}\u{0098}\u{0099}\u{009A}\u{009B}\u{009C}\u{009D}\u{009E}" , "\u{001F}\u{009F}\u{00A0}\u{00A2}\u{00A3}\u{00A4}\u{00A5}\u{00A6}\u{00A7}\u{00A9}\u{00AD}\u{00AE}\u{00B6}\u{0095}\u{0096}\u{0097}\u{0098}\u{0099}\u{009A}\u{009B}\u{009C}\u{009D}\u{009E}" ,
LATCHA , ' ' , SHIFTC , SHIFTD , LOCK , LATCHB), LATCHA , ' ' , SHIFTC , SHIFTD , LOCK , LATCHB),
]; ]
} });
pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions> { pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions> {
let mut result = String::with_capacity(144); let mut result = String::with_capacity(144);

View File

@@ -16,7 +16,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::{ use crate::{
common::{ common::{
@@ -39,11 +39,11 @@ const ALL: u32 = 0;
const EVEN: u32 = 1; const EVEN: u32 = 1;
const ODD: u32 = 2; const ODD: u32 = 2;
lazy_static! { static RS_DECODER: Lazy<ReedSolomonDecoder> = Lazy::new(|| {
static ref RS_DECODER: ReedSolomonDecoder = ReedSolomonDecoder::new(get_predefined_genericgf( ReedSolomonDecoder::new(get_predefined_genericgf(
PredefinedGenericGF::MaxicodeField64 PredefinedGenericGF::MaxicodeField64,
)); ))
} });
pub fn decode(bits: BitMatrix) -> Result<DecoderRXingResult, Exceptions> { pub fn decode(bits: BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
decode_with_hints(bits, &HashMap::new()) decode_with_hints(bits, &HashMap::new())

View File

@@ -450,120 +450,119 @@ impl Code128Reader {
} }
} }
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { pub static CODE_PATTERNS: Lazy<[Vec<u32>; 107]> = Lazy::new(|| {
[
pub static ref CODE_PATTERNS: [Vec<u32>; 107] = [ vec![2, 1, 2, 2, 2, 2], // 0
vec![2, 1, 2, 2, 2, 2], // 0 vec![2, 2, 2, 1, 2, 2],
vec![2, 2, 2, 1, 2, 2], vec![2, 2, 2, 2, 2, 1],
vec![2, 2, 2, 2, 2, 1], vec![1, 2, 1, 2, 2, 3],
vec![1, 2, 1, 2, 2, 3], vec![1, 2, 1, 3, 2, 2],
vec![1, 2, 1, 3, 2, 2], vec![1, 3, 1, 2, 2, 2], // 5
vec![1, 3, 1, 2, 2, 2], // 5 vec![1, 2, 2, 2, 1, 3],
vec![1, 2, 2, 2, 1, 3], vec![1, 2, 2, 3, 1, 2],
vec![1, 2, 2, 3, 1, 2], vec![1, 3, 2, 2, 1, 2],
vec![1, 3, 2, 2, 1, 2], vec![2, 2, 1, 2, 1, 3],
vec![2, 2, 1, 2, 1, 3], vec![2, 2, 1, 3, 1, 2], // 10
vec![2, 2, 1, 3, 1, 2], // 10 vec![2, 3, 1, 2, 1, 2],
vec![2, 3, 1, 2, 1, 2], vec![1, 1, 2, 2, 3, 2],
vec![1, 1, 2, 2, 3, 2], vec![1, 2, 2, 1, 3, 2],
vec![1, 2, 2, 1, 3, 2], vec![1, 2, 2, 2, 3, 1],
vec![1, 2, 2, 2, 3, 1], vec![1, 1, 3, 2, 2, 2], // 15
vec![1, 1, 3, 2, 2, 2], // 15 vec![1, 2, 3, 1, 2, 2],
vec![1, 2, 3, 1, 2, 2], vec![1, 2, 3, 2, 2, 1],
vec![1, 2, 3, 2, 2, 1], vec![2, 2, 3, 2, 1, 1],
vec![2, 2, 3, 2, 1, 1], vec![2, 2, 1, 1, 3, 2],
vec![2, 2, 1, 1, 3, 2], vec![2, 2, 1, 2, 3, 1], // 20
vec![2, 2, 1, 2, 3, 1], // 20 vec![2, 1, 3, 2, 1, 2],
vec![2, 1, 3, 2, 1, 2], vec![2, 2, 3, 1, 1, 2],
vec![2, 2, 3, 1, 1, 2], vec![3, 1, 2, 1, 3, 1],
vec![3, 1, 2, 1, 3, 1], vec![3, 1, 1, 2, 2, 2],
vec![3, 1, 1, 2, 2, 2], vec![3, 2, 1, 1, 2, 2], // 25
vec![3, 2, 1, 1, 2, 2], // 25 vec![3, 2, 1, 2, 2, 1],
vec![3, 2, 1, 2, 2, 1], vec![3, 1, 2, 2, 1, 2],
vec![3, 1, 2, 2, 1, 2], vec![3, 2, 2, 1, 1, 2],
vec![3, 2, 2, 1, 1, 2], vec![3, 2, 2, 2, 1, 1],
vec![3, 2, 2, 2, 1, 1], vec![2, 1, 2, 1, 2, 3], // 30
vec![2, 1, 2, 1, 2, 3], // 30 vec![2, 1, 2, 3, 2, 1],
vec![2, 1, 2, 3, 2, 1], vec![2, 3, 2, 1, 2, 1],
vec![2, 3, 2, 1, 2, 1], vec![1, 1, 1, 3, 2, 3],
vec![1, 1, 1, 3, 2, 3], vec![1, 3, 1, 1, 2, 3],
vec![1, 3, 1, 1, 2, 3], vec![1, 3, 1, 3, 2, 1], // 35
vec![1, 3, 1, 3, 2, 1], // 35 vec![1, 1, 2, 3, 1, 3],
vec![1, 1, 2, 3, 1, 3], vec![1, 3, 2, 1, 1, 3],
vec![1, 3, 2, 1, 1, 3], vec![1, 3, 2, 3, 1, 1],
vec![1, 3, 2, 3, 1, 1], vec![2, 1, 1, 3, 1, 3],
vec![2, 1, 1, 3, 1, 3], vec![2, 3, 1, 1, 1, 3], // 40
vec![2, 3, 1, 1, 1, 3], // 40 vec![2, 3, 1, 3, 1, 1],
vec![2, 3, 1, 3, 1, 1], vec![1, 1, 2, 1, 3, 3],
vec![1, 1, 2, 1, 3, 3], vec![1, 1, 2, 3, 3, 1],
vec![1, 1, 2, 3, 3, 1], vec![1, 3, 2, 1, 3, 1],
vec![1, 3, 2, 1, 3, 1], vec![1, 1, 3, 1, 2, 3], // 45
vec![1, 1, 3, 1, 2, 3], // 45 vec![1, 1, 3, 3, 2, 1],
vec![1, 1, 3, 3, 2, 1], vec![1, 3, 3, 1, 2, 1],
vec![1, 3, 3, 1, 2, 1], vec![3, 1, 3, 1, 2, 1],
vec![3, 1, 3, 1, 2, 1], vec![2, 1, 1, 3, 3, 1],
vec![2, 1, 1, 3, 3, 1], vec![2, 3, 1, 1, 3, 1], // 50
vec![2, 3, 1, 1, 3, 1], // 50 vec![2, 1, 3, 1, 1, 3],
vec![2, 1, 3, 1, 1, 3], vec![2, 1, 3, 3, 1, 1],
vec![2, 1, 3, 3, 1, 1], vec![2, 1, 3, 1, 3, 1],
vec![2, 1, 3, 1, 3, 1], vec![3, 1, 1, 1, 2, 3],
vec![3, 1, 1, 1, 2, 3], vec![3, 1, 1, 3, 2, 1], // 55
vec![3, 1, 1, 3, 2, 1], // 55 vec![3, 3, 1, 1, 2, 1],
vec![3, 3, 1, 1, 2, 1], vec![3, 1, 2, 1, 1, 3],
vec![3, 1, 2, 1, 1, 3], vec![3, 1, 2, 3, 1, 1],
vec![3, 1, 2, 3, 1, 1], vec![3, 3, 2, 1, 1, 1],
vec![3, 3, 2, 1, 1, 1], vec![3, 1, 4, 1, 1, 1], // 60
vec![3, 1, 4, 1, 1, 1], // 60 vec![2, 2, 1, 4, 1, 1],
vec![2, 2, 1, 4, 1, 1], vec![4, 3, 1, 1, 1, 1],
vec![4, 3, 1, 1, 1, 1], vec![1, 1, 1, 2, 2, 4],
vec![1, 1, 1, 2, 2, 4], vec![1, 1, 1, 4, 2, 2],
vec![1, 1, 1, 4, 2, 2], vec![1, 2, 1, 1, 2, 4], // 65
vec![1, 2, 1, 1, 2, 4], // 65 vec![1, 2, 1, 4, 2, 1],
vec![1, 2, 1, 4, 2, 1], vec![1, 4, 1, 1, 2, 2],
vec![1, 4, 1, 1, 2, 2], vec![1, 4, 1, 2, 2, 1],
vec![1, 4, 1, 2, 2, 1], vec![1, 1, 2, 2, 1, 4],
vec![1, 1, 2, 2, 1, 4], vec![1, 1, 2, 4, 1, 2], // 70
vec![1, 1, 2, 4, 1, 2], // 70 vec![1, 2, 2, 1, 1, 4],
vec![1, 2, 2, 1, 1, 4], vec![1, 2, 2, 4, 1, 1],
vec![1, 2, 2, 4, 1, 1], vec![1, 4, 2, 1, 1, 2],
vec![1, 4, 2, 1, 1, 2], vec![1, 4, 2, 2, 1, 1],
vec![1, 4, 2, 2, 1, 1], vec![2, 4, 1, 2, 1, 1], // 75
vec![2, 4, 1, 2, 1, 1], // 75 vec![2, 2, 1, 1, 1, 4],
vec![2, 2, 1, 1, 1, 4], vec![4, 1, 3, 1, 1, 1],
vec![4, 1, 3, 1, 1, 1], vec![2, 4, 1, 1, 1, 2],
vec![2, 4, 1, 1, 1, 2], vec![1, 3, 4, 1, 1, 1],
vec![1, 3, 4, 1, 1, 1], vec![1, 1, 1, 2, 4, 2], // 80
vec![1, 1, 1, 2, 4, 2], // 80 vec![1, 2, 1, 1, 4, 2],
vec![1, 2, 1, 1, 4, 2], vec![1, 2, 1, 2, 4, 1],
vec![1, 2, 1, 2, 4, 1], vec![1, 1, 4, 2, 1, 2],
vec![1, 1, 4, 2, 1, 2], vec![1, 2, 4, 1, 1, 2],
vec![1, 2, 4, 1, 1, 2], vec![1, 2, 4, 2, 1, 1], // 85
vec![1, 2, 4, 2, 1, 1], // 85 vec![4, 1, 1, 2, 1, 2],
vec![4, 1, 1, 2, 1, 2], vec![4, 2, 1, 1, 1, 2],
vec![4, 2, 1, 1, 1, 2], vec![4, 2, 1, 2, 1, 1],
vec![4, 2, 1, 2, 1, 1], vec![2, 1, 2, 1, 4, 1],
vec![2, 1, 2, 1, 4, 1], vec![2, 1, 4, 1, 2, 1], // 90
vec![2, 1, 4, 1, 2, 1], // 90 vec![4, 1, 2, 1, 2, 1],
vec![4, 1, 2, 1, 2, 1], vec![1, 1, 1, 1, 4, 3],
vec![1, 1, 1, 1, 4, 3], vec![1, 1, 1, 3, 4, 1],
vec![1, 1, 1, 3, 4, 1], vec![1, 3, 1, 1, 4, 1],
vec![1, 3, 1, 1, 4, 1], vec![1, 1, 4, 1, 1, 3], // 95
vec![1, 1, 4, 1, 1, 3], // 95 vec![1, 1, 4, 3, 1, 1],
vec![1, 1, 4, 3, 1, 1], vec![4, 1, 1, 1, 1, 3],
vec![4, 1, 1, 1, 1, 3], vec![4, 1, 1, 3, 1, 1],
vec![4, 1, 1, 3, 1, 1], vec![1, 1, 3, 1, 4, 1],
vec![1, 1, 3, 1, 4, 1], vec![1, 1, 4, 1, 3, 1], // 100
vec![1, 1, 4, 1, 3, 1], // 100 vec![3, 1, 1, 1, 4, 1],
vec![3, 1, 1, 1, 4, 1], vec![4, 1, 1, 1, 3, 1],
vec![4, 1, 1, 1, 3, 1], vec![2, 1, 1, 4, 1, 2],
vec![2, 1, 1, 4, 1, 2], vec![2, 1, 1, 2, 1, 4],
vec![2, 1, 1, 2, 1, 4], vec![2, 1, 1, 2, 3, 2], // 105
vec![2, 1, 1, 2, 3, 2], // 105 vec![2, 3, 3, 1, 1, 1, 2],
vec![2, 3, 3, 1, 1, 1, 2], ]
]; });
}
const MAX_AVG_VARIANCE: f32 = 0.25; const MAX_AVG_VARIANCE: f32 = 0.25;
const MAX_INDIVIDUAL_VARIANCE: f32 = 0.7; const MAX_INDIVIDUAL_VARIANCE: f32 = 0.7;

View File

@@ -34,7 +34,7 @@ const LF: &str = "10000110010";
use std::collections::HashMap; use std::collections::HashMap;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::{ use crate::{
common::{BitMatrix, BitMatrixTestCase}, common::{BitMatrix, BitMatrixTestCase},
@@ -43,9 +43,8 @@ use crate::{
}; };
use super::Code128Writer; use super::Code128Writer;
lazy_static! {
static ref WRITER: Code128Writer = Code128Writer::default(); static WRITER: Lazy<Code128Writer> = Lazy::new(|| Code128Writer::default());
}
#[test] #[test]
fn testEncodeWithFunc3() { fn testEncodeWithFunc3() {

View File

@@ -20,12 +20,10 @@ use crate::{
common::BitMatrix, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer, common::BitMatrix, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
}; };
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
lazy_static! { pub static NUMERIC: Lazy<Regex> = Lazy::new(|| Regex::new("[0-9]+").unwrap());
pub static ref NUMERIC: Regex = Regex::new("[0-9]+").unwrap();
}
/** /**
* <p>Encapsulates functionality and implementation that is common to one-dimensional barcodes.</p> * <p>Encapsulates functionality and implementation that is common to one-dimensional barcodes.</p>

View File

@@ -27,16 +27,14 @@
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/ */
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use crate::{common::BitArray, Exceptions}; use crate::{common::BitArray, Exceptions};
lazy_static! { static ONE: Lazy<Regex> = Lazy::new(|| Regex::new("1").unwrap());
static ref ONE: Regex = Regex::new("1").unwrap(); static ZERO: Lazy<Regex> = Lazy::new(|| Regex::new("0").unwrap());
static ref ZERO: Regex = Regex::new("0").unwrap(); static SPACE: Lazy<Regex> = Lazy::new(|| Regex::new(" ").unwrap());
static ref SPACE: Regex = Regex::new(" ").unwrap();
}
/* /*
* Constructs a BitArray from a String like the one returned from BitArray.toString() * Constructs a BitArray from a String like the one returned from BitArray.toString()

View File

@@ -31,115 +31,111 @@ use std::collections::HashMap;
use crate::Exceptions; use crate::Exceptions;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { static TWO_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
let mut hm = HashMap::new();
hm.insert("00".to_owned(), DataLength::fixed(18));
hm.insert("01".to_owned(), DataLength::fixed(14));
hm.insert("02".to_owned(), DataLength::fixed(14));
hm.insert("10".to_owned(), DataLength::variable(20));
hm.insert("11".to_owned(), DataLength::fixed(6));
hm.insert("12".to_owned(), DataLength::fixed(6));
hm.insert("13".to_owned(), DataLength::fixed(6));
hm.insert("15".to_owned(), DataLength::fixed(6));
hm.insert("17".to_owned(), DataLength::fixed(6));
hm.insert("20".to_owned(), DataLength::fixed(2));
hm.insert("21".to_owned(), DataLength::variable(20));
hm.insert("22".to_owned(), DataLength::variable(29));
hm.insert("30".to_owned(), DataLength::variable(8));
hm.insert("37".to_owned(), DataLength::variable(8));
//internal company codes
for i in 90..=99 {
// for (int i = 90; i <= 99; i++) {
hm.insert(i.to_string(), DataLength::variable(30));
}
hm
});
static ref TWO_DIGIT_DATA_LENGTH : HashMap<String,DataLength> = { static THREE_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
let mut hm = HashMap::new(); let mut hm = HashMap::new();
hm.insert("00".to_owned(), DataLength::fixed(18)); hm.insert("240".to_owned(), DataLength::variable(30));
hm.insert("01".to_owned(), DataLength::fixed(14)); hm.insert("241".to_owned(), DataLength::variable(30));
hm.insert("02".to_owned(), DataLength::fixed(14)); hm.insert("242".to_owned(), DataLength::variable(6));
hm.insert("10".to_owned(), DataLength::variable(20)); hm.insert("250".to_owned(), DataLength::variable(30));
hm.insert("11".to_owned(), DataLength::fixed(6)); hm.insert("251".to_owned(), DataLength::variable(30));
hm.insert("12".to_owned(), DataLength::fixed(6)); hm.insert("253".to_owned(), DataLength::variable(17));
hm.insert("13".to_owned(), DataLength::fixed(6)); hm.insert("254".to_owned(), DataLength::variable(20));
hm.insert("15".to_owned(), DataLength::fixed(6)); hm.insert("400".to_owned(), DataLength::variable(30));
hm.insert("17".to_owned(), DataLength::fixed(6)); hm.insert("401".to_owned(), DataLength::variable(30));
hm.insert("20".to_owned(), DataLength::fixed(2)); hm.insert("402".to_owned(), DataLength::fixed(17));
hm.insert("21".to_owned(), DataLength::variable(20)); hm.insert("403".to_owned(), DataLength::variable(30));
hm.insert("22".to_owned(), DataLength::variable(29)); hm.insert("410".to_owned(), DataLength::fixed(13));
hm.insert("30".to_owned(), DataLength::variable(8)); hm.insert("411".to_owned(), DataLength::fixed(13));
hm.insert("37".to_owned(), DataLength::variable(8)); hm.insert("412".to_owned(), DataLength::fixed(13));
//internal company codes hm.insert("413".to_owned(), DataLength::fixed(13));
for i in 90..=99 { hm.insert("414".to_owned(), DataLength::fixed(13));
// for (int i = 90; i <= 99; i++) { hm.insert("420".to_owned(), DataLength::variable(20));
hm.insert(i.to_string(), DataLength::variable(30)); hm.insert("421".to_owned(), DataLength::variable(15));
} hm.insert("422".to_owned(), DataLength::fixed(3));
hm hm.insert("423".to_owned(), DataLength::variable(15));
}; hm.insert("424".to_owned(), DataLength::fixed(3));
hm.insert("425".to_owned(), DataLength::fixed(3));
hm.insert("426".to_owned(), DataLength::fixed(3));
static ref THREE_DIGIT_DATA_LENGTH : HashMap<String,DataLength>= hm
{ });
let mut hm = HashMap::new();
hm.insert("240".to_owned(), DataLength::variable(30));
hm.insert("241".to_owned(), DataLength::variable(30));
hm.insert("242".to_owned(), DataLength::variable(6));
hm.insert("250".to_owned(), DataLength::variable(30));
hm.insert("251".to_owned(), DataLength::variable(30));
hm.insert("253".to_owned(), DataLength::variable(17));
hm.insert("254".to_owned(), DataLength::variable(20));
hm.insert("400".to_owned(), DataLength::variable(30));
hm.insert("401".to_owned(), DataLength::variable(30));
hm.insert("402".to_owned(), DataLength::fixed(17));
hm.insert("403".to_owned(), DataLength::variable(30));
hm.insert("410".to_owned(), DataLength::fixed(13));
hm.insert("411".to_owned(), DataLength::fixed(13));
hm.insert("412".to_owned(), DataLength::fixed(13));
hm.insert("413".to_owned(), DataLength::fixed(13));
hm.insert("414".to_owned(), DataLength::fixed(13));
hm.insert("420".to_owned(), DataLength::variable(20));
hm.insert("421".to_owned(), DataLength::variable(15));
hm.insert("422".to_owned(), DataLength::fixed(3));
hm.insert("423".to_owned(), DataLength::variable(15));
hm.insert("424".to_owned(), DataLength::fixed(3));
hm.insert("425".to_owned(), DataLength::fixed(3));
hm.insert("426".to_owned(), DataLength::fixed(3));
hm static THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
}; let mut hm = HashMap::new();
for i in 310..=316 {
// for (int i = 310; i <= 316; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 320..=336 {
// for (int i = 320; i <= 336; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 340..=357 {
// for (int i = 340; i <= 357; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 360..=369 {
// for (int i = 360; i <= 369; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
hm.insert("390".to_owned(), DataLength::variable(15));
hm.insert("391".to_owned(), DataLength::variable(18));
hm.insert("392".to_owned(), DataLength::variable(15));
hm.insert("393".to_owned(), DataLength::variable(18));
hm.insert("703".to_owned(), DataLength::variable(30));
static ref THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH:HashMap<String,DataLength> = { hm
let mut hm = HashMap::new(); });
for i in 310..=316 {
// for (int i = 310; i <= 316; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 320..=336 {
// for (int i = 320; i <= 336; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 340..=357 {
// for (int i = 340; i <= 357; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 360..=369 {
// for (int i = 360; i <= 369; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
hm.insert("390".to_owned(), DataLength::variable(15));
hm.insert("391".to_owned(), DataLength::variable(18));
hm.insert("392".to_owned(), DataLength::variable(15));
hm.insert("393".to_owned(), DataLength::variable(18));
hm.insert("703".to_owned(), DataLength::variable(30));
hm static FOUR_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
}; let mut hm = HashMap::new();
hm.insert("7001".to_owned(), DataLength::fixed(13));
hm.insert("7002".to_owned(), DataLength::variable(30));
hm.insert("7003".to_owned(), DataLength::fixed(10));
hm.insert("8001".to_owned(), DataLength::fixed(14));
hm.insert("8002".to_owned(), DataLength::variable(20));
hm.insert("8003".to_owned(), DataLength::variable(30));
hm.insert("8004".to_owned(), DataLength::variable(30));
hm.insert("8005".to_owned(), DataLength::fixed(6));
hm.insert("8006".to_owned(), DataLength::fixed(18));
hm.insert("8007".to_owned(), DataLength::variable(30));
hm.insert("8008".to_owned(), DataLength::variable(12));
hm.insert("8018".to_owned(), DataLength::fixed(18));
hm.insert("8020".to_owned(), DataLength::variable(25));
hm.insert("8100".to_owned(), DataLength::fixed(6));
hm.insert("8101".to_owned(), DataLength::fixed(10));
hm.insert("8102".to_owned(), DataLength::fixed(2));
hm.insert("8110".to_owned(), DataLength::variable(70));
hm.insert("8200".to_owned(), DataLength::variable(70));
static ref FOUR_DIGIT_DATA_LENGTH : HashMap<String,DataLength>={ hm
let mut hm = HashMap::new(); });
hm.insert("7001".to_owned(), DataLength::fixed(13));
hm.insert("7002".to_owned(), DataLength::variable(30));
hm.insert("7003".to_owned(), DataLength::fixed(10));
hm.insert("8001".to_owned(), DataLength::fixed(14));
hm.insert("8002".to_owned(), DataLength::variable(20));
hm.insert("8003".to_owned(), DataLength::variable(30));
hm.insert("8004".to_owned(), DataLength::variable(30));
hm.insert("8005".to_owned(), DataLength::fixed(6));
hm.insert("8006".to_owned(), DataLength::fixed(18));
hm.insert("8007".to_owned(), DataLength::variable(30));
hm.insert("8008".to_owned(), DataLength::variable(12));
hm.insert("8018".to_owned(), DataLength::fixed(18));
hm.insert("8020".to_owned(), DataLength::variable(25));
hm.insert("8100".to_owned(), DataLength::fixed(6));
hm.insert("8101".to_owned(), DataLength::fixed(10));
hm.insert("8102".to_owned(), DataLength::fixed(2));
hm.insert("8110".to_owned(), DataLength::variable(70));
hm.insert("8200".to_owned(), DataLength::variable(70));
hm
};
}
pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Exceptions> { pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Exceptions> {
if rawInformation.is_empty() { if rawInformation.is_empty() {

View File

@@ -40,6 +40,8 @@ use crate::{
RXingResultMetadataType, RXingResultMetadataValue, Reader, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
use once_cell::sync::Lazy;
use super::{bit_array_builder, decoders::abstract_expanded_decoder, ExpandedPair, ExpandedRow}; use super::{bit_array_builder, decoders::abstract_expanded_decoder, ExpandedPair, ExpandedRow};
const FINDER_PAT_A: u32 = 0; const FINDER_PAT_A: u32 = 0;
@@ -49,9 +51,8 @@ const FINDER_PAT_D: u32 = 3;
const FINDER_PAT_E: u32 = 4; const FINDER_PAT_E: u32 = 4;
const FINDER_PAT_F: u32 = 5; const FINDER_PAT_F: u32 = 5;
use lazy_static::lazy_static; static FINDER_PATTERN_SEQUENCES: Lazy<Vec<Vec<u32>>> = Lazy::new(|| {
lazy_static! { vec![
static ref FINDER_PATTERN_SEQUENCES: Vec<Vec<u32>> = vec![
vec![FINDER_PAT_A, FINDER_PAT_A], vec![FINDER_PAT_A, FINDER_PAT_A],
vec![FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B], vec![FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B],
vec![FINDER_PAT_A, FINDER_PAT_C, FINDER_PAT_B, FINDER_PAT_D], vec![FINDER_PAT_A, FINDER_PAT_C, FINDER_PAT_B, FINDER_PAT_D],
@@ -60,7 +61,7 @@ lazy_static! {
FINDER_PAT_E, FINDER_PAT_E,
FINDER_PAT_B, FINDER_PAT_B,
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_C FINDER_PAT_C,
], ],
vec![ vec![
FINDER_PAT_A, FINDER_PAT_A,
@@ -68,7 +69,7 @@ lazy_static! {
FINDER_PAT_B, FINDER_PAT_B,
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_F FINDER_PAT_F,
], ],
vec![ vec![
FINDER_PAT_A, FINDER_PAT_A,
@@ -77,7 +78,7 @@ lazy_static! {
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_E, FINDER_PAT_E,
FINDER_PAT_F, FINDER_PAT_F,
FINDER_PAT_F FINDER_PAT_F,
], ],
vec![ vec![
FINDER_PAT_A, FINDER_PAT_A,
@@ -87,7 +88,7 @@ lazy_static! {
FINDER_PAT_C, FINDER_PAT_C,
FINDER_PAT_C, FINDER_PAT_C,
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_D FINDER_PAT_D,
], ],
vec![ vec![
FINDER_PAT_A, FINDER_PAT_A,
@@ -98,7 +99,7 @@ lazy_static! {
FINDER_PAT_C, FINDER_PAT_C,
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_E, FINDER_PAT_E,
FINDER_PAT_E FINDER_PAT_E,
], ],
vec![ vec![
FINDER_PAT_A, FINDER_PAT_A,
@@ -110,7 +111,7 @@ lazy_static! {
FINDER_PAT_D, FINDER_PAT_D,
FINDER_PAT_E, FINDER_PAT_E,
FINDER_PAT_F, FINDER_PAT_F,
FINDER_PAT_F FINDER_PAT_F,
], ],
vec![ vec![
FINDER_PAT_A, FINDER_PAT_A,
@@ -123,10 +124,10 @@ lazy_static! {
FINDER_PAT_E, FINDER_PAT_E,
FINDER_PAT_E, FINDER_PAT_E,
FINDER_PAT_F, FINDER_PAT_F,
FINDER_PAT_F FINDER_PAT_F,
], ],
]; ]
} });
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)

View File

@@ -21,14 +21,12 @@ use crate::{
use super::{one_d_reader, EANManufacturerOrgSupport, OneDReader, UPCEANExtensionSupport}; use super::{one_d_reader, EANManufacturerOrgSupport, OneDReader, UPCEANExtensionSupport};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { pub static EAN_MANUFACTURER_SUPPORT: Lazy<EANManufacturerOrgSupport> =
pub static ref EAN_MANUFACTURER_SUPPORT: EANManufacturerOrgSupport = Lazy::new(|| EANManufacturerOrgSupport::default());
EANManufacturerOrgSupport::default(); pub static UPC_EAN_EXTENSION_SUPPORT: Lazy<UPCEANExtensionSupport> =
pub static ref UPC_EAN_EXTENSION_SUPPORT: UPCEANExtensionSupport = Lazy::new(|| UPCEANExtensionSupport::default());
UPCEANExtensionSupport::default();
}
// These two values are critical for determining how permissive the decoding will be. // These two values are critical for determining how permissive the decoding will be.
// We've arrived at these values through a lot of trial and error. Setting them any higher // We've arrived at these values through a lot of trial and error. Setting them any higher

View File

@@ -80,30 +80,28 @@ const MIXED_CHARS: [char; 25] = [
'$', '/', '+', '%', '*', '=', '^', '$', '/', '+', '%', '*', '=', '^',
]; ];
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { /**
/** * Table containing values for the exponent of 900.
* Table containing values for the exponent of 900. * This is used in the numeric compaction decode algorithm.
* This is used in the numeric compaction decode algorithm. */
*/ static EXP900: Lazy<Vec<BigUint>> = Lazy::new(|| {
static ref EXP900 : Vec<BigUint> = { const EXP_LEN: usize = 16;
const EXP_LEN :usize= 16;
let mut exp900 = Vec::with_capacity(EXP_LEN); //[0;16]; let mut exp900 = Vec::with_capacity(EXP_LEN); //[0;16];
exp900.push(ToBigUint::to_biguint(&1).unwrap()); exp900.push(ToBigUint::to_biguint(&1).unwrap());
let nineHundred = ToBigUint::to_biguint(&900).unwrap(); let nineHundred = ToBigUint::to_biguint(&900).unwrap();
exp900.push(nineHundred); exp900.push(nineHundred);
let mut i = 2; let mut i = 2;
while i < EXP_LEN { while i < EXP_LEN {
// for (int i = 2; i < EXP900.length; i++) { // for (int i = 2; i < EXP900.length; i++) {
exp900.push( &exp900[i - 1] * 900_u32); exp900.push(&exp900[i - 1] * 900_u32);
i+=1; i += 1;
} }
exp900 exp900
}; });
}
// /** // /**
// * Table containing values for the exponent of 900. // * Table containing values for the exponent of 900.

View File

@@ -23,12 +23,10 @@ use crate::{
use super::ModulusPoly; use super::ModulusPoly;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
lazy_static! { // static ref PDF417_GF : Rc<&ModulusGF> = Rc::new(&ModulusGF::new(NUMBER_OF_CODEWORDS, 3));
// static ref PDF417_GF : Rc<&ModulusGF> = Rc::new(&ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); static FLD_INTERIOR: Lazy<ModulusGF> = Lazy::new(|| ModulusGF::new(NUMBER_OF_CODEWORDS, 3));
static ref FLD_INTERIOR : ModulusGF = ModulusGF::new(NUMBER_OF_CODEWORDS, 3);
}
/** /**
* <p>PDF417 error correction implementation.</p> * <p>PDF417 error correction implementation.</p>

View File

@@ -22,107 +22,93 @@
* PDF417 error correction code following the algorithm described in ISO/IEC 15438:2001(E) in * PDF417 error correction code following the algorithm described in ISO/IEC 15438:2001(E) in
* chapter 4.10. * chapter 4.10.
*/ */
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::Exceptions; use crate::Exceptions;
lazy_static! { /**
/** * Tables of coefficients for calculating error correction words
* Tables of coefficients for calculating error correction words * (see annex F, ISO/IEC 15438:2001(E))
* (see annex F, ISO/IEC 15438:2001(E)) */
*/ static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
static ref EC_COEFFICIENTS : [Vec<u32>;9] = [ [
vec![27, 917], vec![27, 917],
vec![522, 568, 723, 809], vec![522, 568, 723, 809],
vec![237, 308, 436, 284, 646, 653, 428, 379], vec![237, 308, 436, 284, 646, 653, 428, 379],
vec![274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, vec![
42, 176, 65], 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65,
vec![361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, ],
284, 193, 517, 273, 494, 263, 147, 593, 800, 571, 320, 803, vec![
133, 231, 390, 685, 330, 63, 410], 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, 273,
vec![539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410,
877, 381, 612, 723, 476, 462, 172, 430, 609, 858, 822, 543, ],
376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31, 460, vec![
594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612, 723, 476,
733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, 462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31,
623, 264, 543], 460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, 733, 717, 83, 404, 97,
vec![521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 280, 771, 840, 629, 4, 381, 843, 623, 264, 543,
925, 749, 415, 822, 93, 217, 208, 928, 244, 583, 620, 246, ],
148, 447, 631, 292, 908, 490, 704, 516, 258, 457, 907, 594, vec![
723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, 193, 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415, 822, 93,
219, 129, 186, 236, 287, 192, 775, 278, 173, 40, 379, 712, 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704, 516, 258, 457,
463, 646, 776, 171, 491, 297, 763, 156, 732, 95, 270, 447, 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, 193, 219, 129, 186,
90, 507, 48, 228, 821, 808, 898, 784, 663, 627, 378, 382, 236, 287, 192, 775, 278, 173, 40, 379, 712, 463, 646, 776, 171, 491, 297, 763, 156,
262, 380, 602, 754, 336, 89, 614, 87, 432, 670, 616, 157, 732, 95, 270, 447, 90, 507, 48, 228, 821, 808, 898, 784, 663, 627, 378, 382, 262, 380,
374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, 602, 754, 336, 89, 614, 87, 432, 670, 616, 157, 374, 242, 726, 600, 269, 375, 898, 845,
587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, 454, 354, 130, 814, 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550,
315, 550, 86, 801, 4, 108, 539], 86, 801, 4, 108, 539,
vec![524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, ],
786, 138, 720, 858, 194, 311, 913, 275, 190, 375, 850, 438, vec![
733, 194, 280, 201, 280, 828, 757, 710, 814, 919, 89, 68, 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720, 858, 194,
569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, 439, 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757, 710, 814, 919,
418, 592, 668, 353, 859, 370, 694, 325, 240, 216, 257, 284, 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, 439, 418, 592, 668, 353,
549, 209, 884, 315, 70, 329, 793, 490, 274, 877, 162, 749, 859, 370, 694, 325, 240, 216, 257, 284, 549, 209, 884, 315, 70, 329, 793, 490, 274,
812, 684, 461, 334, 376, 849, 521, 307, 291, 803, 712, 19, 877, 162, 749, 812, 684, 461, 334, 376, 849, 521, 307, 291, 803, 712, 19, 358, 399,
358, 399, 908, 103, 511, 51, 8, 517, 225, 289, 470, 637, 908, 103, 511, 51, 8, 517, 225, 289, 470, 637, 731, 66, 255, 917, 269, 463, 830, 730,
731, 66, 255, 917, 269, 463, 830, 730, 433, 848, 585, 136, 433, 848, 585, 136, 538, 906, 90, 2, 290, 743, 199, 655, 903, 329, 49, 802, 580, 355,
538, 906, 90, 2, 290, 743, 199, 655, 903, 329, 49, 802, 588, 188, 462, 10, 134, 628, 320, 479, 130, 739, 71, 263, 318, 374, 601, 192, 605, 142,
580, 355, 588, 188, 462, 10, 134, 628, 320, 479, 130, 739, 673, 687, 234, 722, 384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, 60, 732,
71, 263, 318, 374, 601, 192, 605, 142, 673, 687, 234, 722, 621, 895, 544, 261, 852, 655, 309, 697, 755, 756, 60, 231, 773, 434, 421, 726, 528,
384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, 503, 118, 49, 795, 32, 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, 73, 914,
60, 732, 621, 895, 544, 261, 852, 655, 309, 697, 755, 756, 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, 791, 893, 754, 605, 383, 228, 749,
60, 231, 773, 434, 421, 726, 528, 503, 118, 49, 795, 32, 760, 213, 54, 297, 134, 54, 834, 299, 922, 191, 910, 532, 609, 829, 189, 20, 167, 29,
144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, 73, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, 251, 688, 95, 497, 555, 642, 543,
914, 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, 307, 159, 924, 558, 648, 55, 497, 10,
791, 893, 754, 605, 383, 228, 749, 760, 213, 54, 297, 134, ],
54, 834, 299, 922, 191, 910, 532, 609, 829, 189, 20, 167, vec![
29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492, 197, 265,
251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520,
55, 497, 10], 435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, 539, 781, 408, 390, 644,
vec![352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 102, 476, 499, 290, 632, 545, 37, 858, 916, 552, 41, 542, 289, 122, 272, 383, 800, 485,
380, 350, 492, 197, 265, 920, 155, 914, 299, 229, 643, 294, 98, 752, 472, 761, 107, 784, 860, 658, 741, 290, 204, 681, 407, 855, 85, 99, 62, 482,
871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520, 435, 180, 20, 297, 451, 593, 913, 142, 808, 684, 287, 536, 561, 76, 653, 899, 729, 567, 744,
543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, 539, 390, 513, 192, 516, 258, 240, 518, 794, 395, 768, 848, 51, 610, 384, 168, 190, 826,
781, 408, 390, 644, 102, 476, 499, 290, 632, 545, 37, 858, 328, 596, 786, 303, 570, 381, 415, 641, 156, 237, 151, 429, 531, 207, 676, 710, 89,
916, 552, 41, 542, 289, 122, 272, 383, 800, 485, 98, 752, 168, 304, 402, 40, 708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, 92, 358,
472, 761, 107, 784, 860, 658, 741, 290, 204, 681, 407, 855, 785, 288, 357, 850, 836, 827, 736, 707, 94, 8, 494, 114, 521, 2, 499, 851, 543, 152,
85, 99, 62, 482, 180, 20, 297, 451, 593, 913, 142, 808, 729, 771, 95, 248, 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, 669, 45, 902,
684, 287, 536, 561, 76, 653, 899, 729, 567, 744, 390, 513, 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, 591, 452, 578, 37, 124, 298, 332, 552,
192, 516, 258, 240, 518, 794, 395, 768, 848, 51, 610, 384, 43, 427, 119, 662, 777, 475, 850, 764, 364, 578, 911, 283, 711, 472, 420, 245, 288,
168, 190, 826, 328, 596, 786, 303, 570, 381, 415, 641, 156, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, 842, 383, 721, 521, 560, 644, 714,
237, 151, 429, 531, 207, 676, 710, 89, 168, 304, 402, 40, 559, 62, 145, 873, 663, 713, 159, 672, 729, 624, 59, 193, 417, 158, 209, 563, 564, 343,
708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, 693, 109, 608, 563, 365, 181, 772, 677, 310, 248, 353, 708, 410, 579, 870, 617, 841,
92, 358, 785, 288, 357, 850, 836, 827, 736, 707, 94, 8, 632, 860, 289, 536, 35, 777, 618, 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751,
494, 114, 521, 2, 499, 851, 543, 152, 729, 771, 95, 248, 331, 247, 184, 45, 787, 680, 18, 66, 407, 369, 54, 492, 228, 613, 830, 922, 437, 519,
361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, 669, 644, 905, 789, 420, 305, 441, 207, 300, 892, 827, 141, 537, 381, 662, 513, 56, 252,
45, 902, 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, 341, 242, 797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, 665, 397, 808, 851,
591, 452, 578, 37, 124, 298, 332, 552, 43, 427, 119, 662, 309, 473, 795, 378, 31, 647, 915, 459, 806, 590, 731, 425, 216, 548, 249, 321, 881,
777, 475, 850, 764, 364, 578, 911, 283, 711, 472, 420, 245, 699, 535, 673, 782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, 660, 162, 498,
288, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, 842, 308, 155, 422, 907, 817, 187, 62, 16, 425, 535, 336, 286, 437, 375, 273, 610, 296, 183,
383, 721, 521, 560, 644, 714, 559, 62, 145, 873, 663, 713, 923, 116, 667, 751, 353, 62, 366, 691, 379, 687, 842, 37, 357, 720, 742, 330, 5, 39,
159, 672, 729, 624, 59, 193, 417, 158, 209, 563, 564, 343, 923, 311, 424, 242, 749, 321, 54, 669, 316, 342, 299, 534, 105, 667, 488, 640, 672,
693, 109, 608, 563, 365, 181, 772, 677, 310, 248, 353, 708, 576, 540, 316, 486, 721, 610, 46, 656, 447, 171, 616, 464, 190, 531, 297, 321, 762,
410, 579, 870, 617, 841, 632, 860, 289, 536, 35, 777, 618, 752, 533, 175, 134, 14, 381, 433, 717, 45, 111, 20, 596, 284, 736, 138, 646, 411, 877,
586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, 331, 669, 141, 919, 45, 780, 407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752,
247, 184, 45, 787, 680, 18, 66, 407, 369, 54, 492, 228, 768, 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121,
613, 830, 922, 437, 519, 644, 905, 789, 420, 305, 441, 207, 303, 263,
300, 892, 827, 141, 537, 381, 662, 513, 56, 252, 341, 242, ],
797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, ]
665, 397, 808, 851, 309, 473, 795, 378, 31, 647, 915, 459, });
806, 590, 731, 425, 216, 548, 249, 321, 881, 699, 535, 673,
782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, 660,
162, 498, 308, 155, 422, 907, 817, 187, 62, 16, 425, 535,
336, 286, 437, 375, 273, 610, 296, 183, 923, 116, 667, 751,
353, 62, 366, 691, 379, 687, 842, 37, 357, 720, 742, 330,
5, 39, 923, 311, 424, 242, 749, 321, 54, 669, 316, 342,
299, 534, 105, 667, 488, 640, 672, 576, 540, 316, 486, 721,
610, 46, 656, 447, 171, 616, 464, 190, 531, 297, 321, 762,
752, 533, 175, 134, 14, 381, 433, 717, 45, 111, 20, 596,
284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, 407,
164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768,
223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675,
410, 389, 244, 31, 121, 303, 263]];
}
/** /**
* Determines the number of error correction codewords for a specified error correction * Determines the number of error correction codewords for a specified error correction

View File

@@ -22,7 +22,7 @@ use std::{collections::HashMap, rc::Rc};
* *
* @author Sean Owen * @author Sean Owen
*/ */
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use crate::{ use crate::{
common::{ common::{
@@ -34,10 +34,12 @@ use crate::{
use super::{decoded_bit_stream_parser, BitMatrixParser, DataBlock, QRCodeDecoderMetaData}; use super::{decoded_bit_stream_parser, BitMatrixParser, DataBlock, QRCodeDecoderMetaData};
lazy_static! { //rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);
//rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256); static RS_DECODER: Lazy<ReedSolomonDecoder> = Lazy::new(|| {
static ref RS_DECODER : ReedSolomonDecoder = ReedSolomonDecoder::new(get_predefined_genericgf(PredefinedGenericGF::QrCodeField256)); ReedSolomonDecoder::new(get_predefined_genericgf(
} PredefinedGenericGF::QrCodeField256,
))
});
pub fn decode_bool_array(image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> { pub fn decode_bool_array(image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
decode_bool_array_with_hints(image, &HashMap::new()) decode_bool_array_with_hints(image, &HashMap::new())

View File

@@ -20,13 +20,11 @@ use crate::{common::BitMatrix, Exceptions};
use super::{ErrorCorrectionLevel, FormatInformation}; use super::{ErrorCorrectionLevel, FormatInformation};
use lazy_static::lazy_static; use once_cell::sync::Lazy;
pub type VersionRef = &'static Version; pub type VersionRef = &'static Version;
lazy_static! { static VERSIONS: Lazy<Vec<Version>> = Lazy::new(|| Version::buildVersions());
static ref VERSIONS: Vec<Version> = Version::buildVersions();
}
/** /**
* See ISO 18004:2006 Annex D. * See ISO 18004:2006 Annex D.

View File

@@ -25,14 +25,12 @@ use crate::{
EncodeHintType, EncodeHintValue, EncodeHintType, EncodeHintValue,
}; };
use encoding::EncodingRef; use encoding::EncodingRef;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use super::QRCode; use super::QRCode;
lazy_static! { static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
static ref SHIFT_JIS_CHARSET: EncodingRef = Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
encoding::label::encoding_from_whatwg_label("SJIS").unwrap();
}
/** /**
* @author satorux@google.com (Satoru Takabayashi) - creator * @author satorux@google.com (Satoru Takabayashi) - creator

View File

@@ -21,7 +21,7 @@ use std::collections::HashMap;
use encoding::EncodingRef; use encoding::EncodingRef;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use crate::{ use crate::{
@@ -35,10 +35,8 @@ use crate::{
use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode}; use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode};
lazy_static! { static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
static ref SHIFT_JIS_CHARSET: EncodingRef = Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
encoding::label::encoding_from_whatwg_label("SJIS").unwrap();
}
// The original table is defined in the table 5 of JISX0510:2004 (p.19). // The original table is defined in the table 5 of JISX0510:2004 (p.19).
const ALPHANUMERIC_TABLE: [i8; 96] = [ const ALPHANUMERIC_TABLE: [i8; 96] = [