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]
regex = "1.7.0"
fancy-regex = "0.10"
lazy_static = "1.4.0"
once_cell = "1.17.0"
encoding = "0.2"
rand = "0.8.5"
urlencoding = "2.1.2"

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,11 +23,9 @@
use super::{GeoParsedRXingResult, ParsedClientResult, ResultParser};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
lazy_static! {
static ref GEO_URL: regex::Regex = regex::Regex::new(GEO_URL_PATTERN).unwrap();
}
static GEO_URL: Lazy<regex::Regex> = Lazy::new(|| regex::Regex::new(GEO_URL_PATTERN).unwrap());
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 urlencoding::decode;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use crate::{exceptions::Exceptions, RXingResult};
@@ -92,9 +92,7 @@ use super::{
pub type ParserFunction = dyn Fn(&RXingResult) -> Option<ParsedClientResult>;
lazy_static! {
static ref DIGITS: Regex = Regex::new("\\d+").unwrap();
}
static DIGITS: Lazy<Regex> = Lazy::new(|| Regex::new("\\d+").unwrap());
// const DIGITS: &'static str = "\\d+"; //= Pattern.compile("\\d+");
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.Pattern;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
/**
* Tries to parse results that are a URI of some kind.
*
@@ -34,15 +34,15 @@ use crate::RXingResult;
use super::{ParsedClientResult, ResultParser, URIParsedRXingResult};
lazy_static! {
static ref ALLOWED_URI_CHARS: Regex =
Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile");
static ref USER_IN_HOST: Regex =
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 ref URL_WITHOUT_PROTOCOL_PATTERN: Regex =
Regex::new("([a-zA-Z0-9\\-]+\\.){1,6}[a-zA-Z]{2,}(:\\d{1,5})?(/|\\?|$)").unwrap();
}
static ALLOWED_URI_CHARS: Lazy<Regex> = Lazy::new(|| {
Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile")
});
static USER_IN_HOST: Lazy<Regex> =
Lazy::new(|| Regex::new(":/*([^/@]+)@[^/]+").expect("Regex patterns should always copile"));
static URL_WITH_PROTOCOL_PATTERN: Lazy<Regex> =
Lazy::new(|| Regex::new("[a-zA-Z][a-zA-Z0-9+-.]+:").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 USER_IN_HOST: &'static str = ":/*([^/@]+)@[^/]+";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -18,7 +18,7 @@ use crate::Exceptions;
use super::SymbolInfo;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
/**
* 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];
lazy_static! {
/**
* Precomputed polynomial factors for ECC 200.
*/
static ref FACTORS: [Vec<u32>; 16] = [
Vec::from([228, 48, 15, 111, 62]),
Vec::from([23, 68, 144, 134, 240, 92, 254]),
Vec::from([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]),
Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]),
Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]),
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([
15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172,
]),
Vec::from([
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([
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([
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([
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,
9, 5,
]),
Vec::from([
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,
147, 160, 175, 69, 213, 92, 253, 225, 19,
]),
Vec::from([
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,
62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53, 143, 46,
]),
Vec::from([
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, 218, 51,
63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47,
11, 204,
]),
Vec::from([
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,
]),
];
}
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([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]),
Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]),
Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]),
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([
15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186,
172,
]),
Vec::from([
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([
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([
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([
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, 9, 5,
]),
Vec::from([
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, 147, 160, 175, 69, 213, 92, 253, 225, 19,
]),
Vec::from([
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, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53,
143, 46,
]),
Vec::from([
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,
218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224,
124, 86, 47, 11, 204,
]),
Vec::from([
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;

View File

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

View File

@@ -19,42 +19,42 @@ use std::fmt;
use crate::{Dimension, Exceptions};
use super::SymbolShapeHint;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
lazy_static! {
pub(super) static ref PROD_SYMBOLS: Vec<SymbolInfo> = vec![
SymbolInfo::new(false, 3, 5, 8, 8, 1),
SymbolInfo::new(false, 5, 7, 10, 10, 1),
/*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1),
SymbolInfo::new(false, 8, 10, 12, 12, 1),
/*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2),
SymbolInfo::new(false, 12, 12, 14, 14, 1),
/*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1),
SymbolInfo::new(false, 18, 14, 16, 16, 1),
SymbolInfo::new(false, 22, 18, 18, 18, 1),
/*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2),
SymbolInfo::new(false, 30, 20, 20, 20, 1),
/*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2),
SymbolInfo::new(false, 36, 24, 22, 22, 1),
SymbolInfo::new(false, 44, 28, 24, 24, 1),
/*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2),
SymbolInfo::new(false, 62, 36, 14, 14, 4),
SymbolInfo::new(false, 86, 42, 16, 16, 4),
SymbolInfo::new(false, 114, 48, 18, 18, 4),
SymbolInfo::new(false, 144, 56, 20, 20, 4),
SymbolInfo::new(false, 174, 68, 22, 22, 4),
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, 368, 144, 16, 16, 16, 92, 36),
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, 696, 272, 22, 22, 16, 174, 68),
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, 1304, 496, 20, 20, 36, 163, 62),
SymbolInfo::new_symbol_info_144(),
];
}
pub(super) static PROD_SYMBOLS: Lazy<Vec<SymbolInfo>> = Lazy::new(|| {
vec![
SymbolInfo::new(false, 3, 5, 8, 8, 1),
SymbolInfo::new(false, 5, 7, 10, 10, 1),
/*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1),
SymbolInfo::new(false, 8, 10, 12, 12, 1),
/*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2),
SymbolInfo::new(false, 12, 12, 14, 14, 1),
/*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1),
SymbolInfo::new(false, 18, 14, 16, 16, 1),
SymbolInfo::new(false, 22, 18, 18, 18, 1),
/*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2),
SymbolInfo::new(false, 30, 20, 20, 20, 1),
/*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2),
SymbolInfo::new(false, 36, 24, 22, 22, 1),
SymbolInfo::new(false, 44, 28, 24, 24, 1),
/*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2),
SymbolInfo::new(false, 62, 36, 14, 14, 4),
SymbolInfo::new(false, 86, 42, 16, 16, 4),
SymbolInfo::new(false, 114, 48, 18, 18, 4),
SymbolInfo::new(false, 144, 56, 20, 20, 4),
SymbolInfo::new(false, 174, 68, 22, 22, 4),
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, 368, 144, 16, 16, 16, 92, 36),
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, 696, 272, 22, 22, 16, 174, 68),
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, 1304, 496, 20, 20, 36, 163, 62),
SymbolInfo::new_symbol_info_144(),
]
});
/**
* 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(
&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 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(
&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(
&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 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(
&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;
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 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,
@@ -59,8 +59,8 @@ const POSTCODE_3_BYTES: [[u8; 6]; 6] = [
[9, 10, 11, 12, 1, 2],
];
lazy_static! {
static ref SETS : [String;5]= [
static SETS: Lazy<[String; 5]> = Lazy::new(|| {
[
format!("\rABCDEFGHIJKLMNOPQRSTUVWXYZ{}{}{}{}{} {}\"#$%&'()*+,-./0123456789:{}{}{}{}{}" , ECI , FS , GS , RS , NS , PAD ,
SHIFTB , SHIFTC , SHIFTD , SHIFTE , LATCHB),
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 ,
"\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),
];
}
]
});
pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions> {
let mut result = String::with_capacity(144);

View File

@@ -16,7 +16,7 @@
use std::collections::HashMap;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use crate::{
common::{
@@ -39,11 +39,11 @@ const ALL: u32 = 0;
const EVEN: u32 = 1;
const ODD: u32 = 2;
lazy_static! {
static ref RS_DECODER: ReedSolomonDecoder = ReedSolomonDecoder::new(get_predefined_genericgf(
PredefinedGenericGF::MaxicodeField64
));
}
static RS_DECODER: Lazy<ReedSolomonDecoder> = Lazy::new(|| {
ReedSolomonDecoder::new(get_predefined_genericgf(
PredefinedGenericGF::MaxicodeField64,
))
});
pub fn decode(bits: BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
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 ref CODE_PATTERNS: [Vec<u32>; 107] = [
vec![2, 1, 2, 2, 2, 2], // 0
vec![2, 2, 2, 1, 2, 2],
vec![2, 2, 2, 2, 2, 1],
vec![1, 2, 1, 2, 2, 3],
vec![1, 2, 1, 3, 2, 2],
vec![1, 3, 1, 2, 2, 2], // 5
vec![1, 2, 2, 2, 1, 3],
vec![1, 2, 2, 3, 1, 2],
vec![1, 3, 2, 2, 1, 2],
vec![2, 2, 1, 2, 1, 3],
vec![2, 2, 1, 3, 1, 2], // 10
vec![2, 3, 1, 2, 1, 2],
vec![1, 1, 2, 2, 3, 2],
vec![1, 2, 2, 1, 3, 2],
vec![1, 2, 2, 2, 3, 1],
vec![1, 1, 3, 2, 2, 2], // 15
vec![1, 2, 3, 1, 2, 2],
vec![1, 2, 3, 2, 2, 1],
vec![2, 2, 3, 2, 1, 1],
vec![2, 2, 1, 1, 3, 2],
vec![2, 2, 1, 2, 3, 1], // 20
vec![2, 1, 3, 2, 1, 2],
vec![2, 2, 3, 1, 1, 2],
vec![3, 1, 2, 1, 3, 1],
vec![3, 1, 1, 2, 2, 2],
vec![3, 2, 1, 1, 2, 2], // 25
vec![3, 2, 1, 2, 2, 1],
vec![3, 1, 2, 2, 1, 2],
vec![3, 2, 2, 1, 1, 2],
vec![3, 2, 2, 2, 1, 1],
vec![2, 1, 2, 1, 2, 3], // 30
vec![2, 1, 2, 3, 2, 1],
vec![2, 3, 2, 1, 2, 1],
vec![1, 1, 1, 3, 2, 3],
vec![1, 3, 1, 1, 2, 3],
vec![1, 3, 1, 3, 2, 1], // 35
vec![1, 1, 2, 3, 1, 3],
vec![1, 3, 2, 1, 1, 3],
vec![1, 3, 2, 3, 1, 1],
vec![2, 1, 1, 3, 1, 3],
vec![2, 3, 1, 1, 1, 3], // 40
vec![2, 3, 1, 3, 1, 1],
vec![1, 1, 2, 1, 3, 3],
vec![1, 1, 2, 3, 3, 1],
vec![1, 3, 2, 1, 3, 1],
vec![1, 1, 3, 1, 2, 3], // 45
vec![1, 1, 3, 3, 2, 1],
vec![1, 3, 3, 1, 2, 1],
vec![3, 1, 3, 1, 2, 1],
vec![2, 1, 1, 3, 3, 1],
vec![2, 3, 1, 1, 3, 1], // 50
vec![2, 1, 3, 1, 1, 3],
vec![2, 1, 3, 3, 1, 1],
vec![2, 1, 3, 1, 3, 1],
vec![3, 1, 1, 1, 2, 3],
vec![3, 1, 1, 3, 2, 1], // 55
vec![3, 3, 1, 1, 2, 1],
vec![3, 1, 2, 1, 1, 3],
vec![3, 1, 2, 3, 1, 1],
vec![3, 3, 2, 1, 1, 1],
vec![3, 1, 4, 1, 1, 1], // 60
vec![2, 2, 1, 4, 1, 1],
vec![4, 3, 1, 1, 1, 1],
vec![1, 1, 1, 2, 2, 4],
vec![1, 1, 1, 4, 2, 2],
vec![1, 2, 1, 1, 2, 4], // 65
vec![1, 2, 1, 4, 2, 1],
vec![1, 4, 1, 1, 2, 2],
vec![1, 4, 1, 2, 2, 1],
vec![1, 1, 2, 2, 1, 4],
vec![1, 1, 2, 4, 1, 2], // 70
vec![1, 2, 2, 1, 1, 4],
vec![1, 2, 2, 4, 1, 1],
vec![1, 4, 2, 1, 1, 2],
vec![1, 4, 2, 2, 1, 1],
vec![2, 4, 1, 2, 1, 1], // 75
vec![2, 2, 1, 1, 1, 4],
vec![4, 1, 3, 1, 1, 1],
vec![2, 4, 1, 1, 1, 2],
vec![1, 3, 4, 1, 1, 1],
vec![1, 1, 1, 2, 4, 2], // 80
vec![1, 2, 1, 1, 4, 2],
vec![1, 2, 1, 2, 4, 1],
vec![1, 1, 4, 2, 1, 2],
vec![1, 2, 4, 1, 1, 2],
vec![1, 2, 4, 2, 1, 1], // 85
vec![4, 1, 1, 2, 1, 2],
vec![4, 2, 1, 1, 1, 2],
vec![4, 2, 1, 2, 1, 1],
vec![2, 1, 2, 1, 4, 1],
vec![2, 1, 4, 1, 2, 1], // 90
vec![4, 1, 2, 1, 2, 1],
vec![1, 1, 1, 1, 4, 3],
vec![1, 1, 1, 3, 4, 1],
vec![1, 3, 1, 1, 4, 1],
vec![1, 1, 4, 1, 1, 3], // 95
vec![1, 1, 4, 3, 1, 1],
vec![4, 1, 1, 1, 1, 3],
vec![4, 1, 1, 3, 1, 1],
vec![1, 1, 3, 1, 4, 1],
vec![1, 1, 4, 1, 3, 1], // 100
vec![3, 1, 1, 1, 4, 1],
vec![4, 1, 1, 1, 3, 1],
vec![2, 1, 1, 4, 1, 2],
vec![2, 1, 1, 2, 1, 4],
vec![2, 1, 1, 2, 3, 2], // 105
vec![2, 3, 3, 1, 1, 1, 2],
];
}
pub static CODE_PATTERNS: Lazy<[Vec<u32>; 107]> = Lazy::new(|| {
[
vec![2, 1, 2, 2, 2, 2], // 0
vec![2, 2, 2, 1, 2, 2],
vec![2, 2, 2, 2, 2, 1],
vec![1, 2, 1, 2, 2, 3],
vec![1, 2, 1, 3, 2, 2],
vec![1, 3, 1, 2, 2, 2], // 5
vec![1, 2, 2, 2, 1, 3],
vec![1, 2, 2, 3, 1, 2],
vec![1, 3, 2, 2, 1, 2],
vec![2, 2, 1, 2, 1, 3],
vec![2, 2, 1, 3, 1, 2], // 10
vec![2, 3, 1, 2, 1, 2],
vec![1, 1, 2, 2, 3, 2],
vec![1, 2, 2, 1, 3, 2],
vec![1, 2, 2, 2, 3, 1],
vec![1, 1, 3, 2, 2, 2], // 15
vec![1, 2, 3, 1, 2, 2],
vec![1, 2, 3, 2, 2, 1],
vec![2, 2, 3, 2, 1, 1],
vec![2, 2, 1, 1, 3, 2],
vec![2, 2, 1, 2, 3, 1], // 20
vec![2, 1, 3, 2, 1, 2],
vec![2, 2, 3, 1, 1, 2],
vec![3, 1, 2, 1, 3, 1],
vec![3, 1, 1, 2, 2, 2],
vec![3, 2, 1, 1, 2, 2], // 25
vec![3, 2, 1, 2, 2, 1],
vec![3, 1, 2, 2, 1, 2],
vec![3, 2, 2, 1, 1, 2],
vec![3, 2, 2, 2, 1, 1],
vec![2, 1, 2, 1, 2, 3], // 30
vec![2, 1, 2, 3, 2, 1],
vec![2, 3, 2, 1, 2, 1],
vec![1, 1, 1, 3, 2, 3],
vec![1, 3, 1, 1, 2, 3],
vec![1, 3, 1, 3, 2, 1], // 35
vec![1, 1, 2, 3, 1, 3],
vec![1, 3, 2, 1, 1, 3],
vec![1, 3, 2, 3, 1, 1],
vec![2, 1, 1, 3, 1, 3],
vec![2, 3, 1, 1, 1, 3], // 40
vec![2, 3, 1, 3, 1, 1],
vec![1, 1, 2, 1, 3, 3],
vec![1, 1, 2, 3, 3, 1],
vec![1, 3, 2, 1, 3, 1],
vec![1, 1, 3, 1, 2, 3], // 45
vec![1, 1, 3, 3, 2, 1],
vec![1, 3, 3, 1, 2, 1],
vec![3, 1, 3, 1, 2, 1],
vec![2, 1, 1, 3, 3, 1],
vec![2, 3, 1, 1, 3, 1], // 50
vec![2, 1, 3, 1, 1, 3],
vec![2, 1, 3, 3, 1, 1],
vec![2, 1, 3, 1, 3, 1],
vec![3, 1, 1, 1, 2, 3],
vec![3, 1, 1, 3, 2, 1], // 55
vec![3, 3, 1, 1, 2, 1],
vec![3, 1, 2, 1, 1, 3],
vec![3, 1, 2, 3, 1, 1],
vec![3, 3, 2, 1, 1, 1],
vec![3, 1, 4, 1, 1, 1], // 60
vec![2, 2, 1, 4, 1, 1],
vec![4, 3, 1, 1, 1, 1],
vec![1, 1, 1, 2, 2, 4],
vec![1, 1, 1, 4, 2, 2],
vec![1, 2, 1, 1, 2, 4], // 65
vec![1, 2, 1, 4, 2, 1],
vec![1, 4, 1, 1, 2, 2],
vec![1, 4, 1, 2, 2, 1],
vec![1, 1, 2, 2, 1, 4],
vec![1, 1, 2, 4, 1, 2], // 70
vec![1, 2, 2, 1, 1, 4],
vec![1, 2, 2, 4, 1, 1],
vec![1, 4, 2, 1, 1, 2],
vec![1, 4, 2, 2, 1, 1],
vec![2, 4, 1, 2, 1, 1], // 75
vec![2, 2, 1, 1, 1, 4],
vec![4, 1, 3, 1, 1, 1],
vec![2, 4, 1, 1, 1, 2],
vec![1, 3, 4, 1, 1, 1],
vec![1, 1, 1, 2, 4, 2], // 80
vec![1, 2, 1, 1, 4, 2],
vec![1, 2, 1, 2, 4, 1],
vec![1, 1, 4, 2, 1, 2],
vec![1, 2, 4, 1, 1, 2],
vec![1, 2, 4, 2, 1, 1], // 85
vec![4, 1, 1, 2, 1, 2],
vec![4, 2, 1, 1, 1, 2],
vec![4, 2, 1, 2, 1, 1],
vec![2, 1, 2, 1, 4, 1],
vec![2, 1, 4, 1, 2, 1], // 90
vec![4, 1, 2, 1, 2, 1],
vec![1, 1, 1, 1, 4, 3],
vec![1, 1, 1, 3, 4, 1],
vec![1, 3, 1, 1, 4, 1],
vec![1, 1, 4, 1, 1, 3], // 95
vec![1, 1, 4, 3, 1, 1],
vec![4, 1, 1, 1, 1, 3],
vec![4, 1, 1, 3, 1, 1],
vec![1, 1, 3, 1, 4, 1],
vec![1, 1, 4, 1, 3, 1], // 100
vec![3, 1, 1, 1, 4, 1],
vec![4, 1, 1, 1, 3, 1],
vec![2, 1, 1, 4, 1, 2],
vec![2, 1, 1, 2, 1, 4],
vec![2, 1, 1, 2, 3, 2], // 105
vec![2, 3, 3, 1, 1, 1, 2],
]
});
const MAX_AVG_VARIANCE: f32 = 0.25;
const MAX_INDIVIDUAL_VARIANCE: f32 = 0.7;

View File

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

View File

@@ -20,12 +20,10 @@ use crate::{
common::BitMatrix, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
lazy_static! {
pub static ref NUMERIC: Regex = Regex::new("[0-9]+").unwrap();
}
pub static NUMERIC: Lazy<Regex> = Lazy::new(|| Regex::new("[0-9]+").unwrap());
/**
* <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)
*/
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::{common::BitArray, Exceptions};
lazy_static! {
static ref ONE: Regex = Regex::new("1").unwrap();
static ref ZERO: Regex = Regex::new("0").unwrap();
static ref SPACE: Regex = Regex::new(" ").unwrap();
}
static ONE: Lazy<Regex> = Lazy::new(|| Regex::new("1").unwrap());
static ZERO: Lazy<Regex> = Lazy::new(|| Regex::new("0").unwrap());
static SPACE: Lazy<Regex> = Lazy::new(|| Regex::new(" ").unwrap());
/*
* 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 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> = {
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 THREE_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
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));
static ref THREE_DIGIT_DATA_LENGTH : HashMap<String,DataLength>=
{
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
});
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> = {
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
});
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>={
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
};
}
hm
});
pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Exceptions> {
if rawInformation.is_empty() {

View File

@@ -40,6 +40,8 @@ use crate::{
RXingResultMetadataType, RXingResultMetadataValue, Reader,
};
use once_cell::sync::Lazy;
use super::{bit_array_builder, decoders::abstract_expanded_decoder, ExpandedPair, ExpandedRow};
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_F: u32 = 5;
use lazy_static::lazy_static;
lazy_static! {
static ref FINDER_PATTERN_SEQUENCES: Vec<Vec<u32>> = vec![
static FINDER_PATTERN_SEQUENCES: Lazy<Vec<Vec<u32>>> = Lazy::new(|| {
vec![
vec![FINDER_PAT_A, FINDER_PAT_A],
vec![FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B],
vec![FINDER_PAT_A, FINDER_PAT_C, FINDER_PAT_B, FINDER_PAT_D],
@@ -60,7 +61,7 @@ lazy_static! {
FINDER_PAT_E,
FINDER_PAT_B,
FINDER_PAT_D,
FINDER_PAT_C
FINDER_PAT_C,
],
vec![
FINDER_PAT_A,
@@ -68,7 +69,7 @@ lazy_static! {
FINDER_PAT_B,
FINDER_PAT_D,
FINDER_PAT_D,
FINDER_PAT_F
FINDER_PAT_F,
],
vec![
FINDER_PAT_A,
@@ -77,7 +78,7 @@ lazy_static! {
FINDER_PAT_D,
FINDER_PAT_E,
FINDER_PAT_F,
FINDER_PAT_F
FINDER_PAT_F,
],
vec![
FINDER_PAT_A,
@@ -87,7 +88,7 @@ lazy_static! {
FINDER_PAT_C,
FINDER_PAT_C,
FINDER_PAT_D,
FINDER_PAT_D
FINDER_PAT_D,
],
vec![
FINDER_PAT_A,
@@ -98,7 +99,7 @@ lazy_static! {
FINDER_PAT_C,
FINDER_PAT_D,
FINDER_PAT_E,
FINDER_PAT_E
FINDER_PAT_E,
],
vec![
FINDER_PAT_A,
@@ -110,7 +111,7 @@ lazy_static! {
FINDER_PAT_D,
FINDER_PAT_E,
FINDER_PAT_F,
FINDER_PAT_F
FINDER_PAT_F,
],
vec![
FINDER_PAT_A,
@@ -123,10 +124,10 @@ lazy_static! {
FINDER_PAT_E,
FINDER_PAT_E,
FINDER_PAT_F,
FINDER_PAT_F
FINDER_PAT_F,
],
];
}
]
});
/**
* @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 lazy_static::lazy_static;
use once_cell::sync::Lazy;
lazy_static! {
pub static ref EAN_MANUFACTURER_SUPPORT: EANManufacturerOrgSupport =
EANManufacturerOrgSupport::default();
pub static ref UPC_EAN_EXTENSION_SUPPORT: UPCEANExtensionSupport =
UPCEANExtensionSupport::default();
}
pub static EAN_MANUFACTURER_SUPPORT: Lazy<EANManufacturerOrgSupport> =
Lazy::new(|| EANManufacturerOrgSupport::default());
pub static UPC_EAN_EXTENSION_SUPPORT: Lazy<UPCEANExtensionSupport> =
Lazy::new(|| UPCEANExtensionSupport::default());
// 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

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.
* This is used in the numeric compaction decode algorithm.
*/
static ref EXP900 : Vec<BigUint> = {
const EXP_LEN :usize= 16;
/**
* Table containing values for the exponent of 900.
* This is used in the numeric compaction decode algorithm.
*/
static EXP900: Lazy<Vec<BigUint>> = Lazy::new(|| {
const EXP_LEN: usize = 16;
let mut exp900 = Vec::with_capacity(EXP_LEN); //[0;16];
exp900.push(ToBigUint::to_biguint(&1).unwrap());
let nineHundred = ToBigUint::to_biguint(&900).unwrap();
exp900.push(nineHundred);
let mut i = 2;
while i < EXP_LEN {
// for (int i = 2; i < EXP900.length; i++) {
exp900.push( &exp900[i - 1] * 900_u32);
// for (int i = 2; i < EXP900.length; i++) {
exp900.push(&exp900[i - 1] * 900_u32);
i+=1;
i += 1;
}
exp900
};
}
});
// /**
// * Table containing values for the exponent of 900.

View File

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

View File

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

View File

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

View File

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

View File

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