mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-25 20:02:34 +00:00
perf: code cleanup and loop fixes
This commit is contained in:
@@ -42,12 +42,11 @@ pub struct BitArray {
|
||||
|
||||
impl BitArray {
|
||||
pub fn new() -> Self {
|
||||
// Self {
|
||||
// bits: Vec::new(),
|
||||
// size: 0,
|
||||
// read_offset: 0,
|
||||
// }
|
||||
Self::default()
|
||||
Self {
|
||||
bits: Vec::new(),
|
||||
size: 0,
|
||||
read_offset: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_size(size: usize) -> Self {
|
||||
|
||||
@@ -18,8 +18,6 @@ use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use super::{CharacterSet, Eci};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
// static ENCODERS: Lazy<Vec<CharacterSet>> = Lazy::new(|| {
|
||||
// let mut enc_vec = Vec::new();
|
||||
// for name in NAMES {
|
||||
@@ -53,30 +51,28 @@ use once_cell::sync::Lazy;
|
||||
// "Shift_JIS",
|
||||
// ];
|
||||
|
||||
static ENCODERS: Lazy<Vec<CharacterSet>> = Lazy::new(|| {
|
||||
vec![
|
||||
CharacterSet::Cp437,
|
||||
CharacterSet::ISO8859_2,
|
||||
CharacterSet::ISO8859_3,
|
||||
CharacterSet::ISO8859_4,
|
||||
CharacterSet::ISO8859_5,
|
||||
// CharacterSet::ISO8859_6,
|
||||
CharacterSet::ISO8859_7,
|
||||
// CharacterSet::ISO8859_8,
|
||||
CharacterSet::ISO8859_9,
|
||||
// CharacterSet::ISO8859_10,
|
||||
// CharacterSet::ISO8859_11,
|
||||
// CharacterSet::ISO8859_13,
|
||||
// CharacterSet::ISO8859_14,
|
||||
CharacterSet::ISO8859_15,
|
||||
CharacterSet::ISO8859_16,
|
||||
CharacterSet::Shift_JIS,
|
||||
CharacterSet::Cp1250,
|
||||
CharacterSet::Cp1251,
|
||||
CharacterSet::Cp1252,
|
||||
CharacterSet::Cp1256,
|
||||
]
|
||||
});
|
||||
const ENCODERS: [CharacterSet; 14] = [
|
||||
CharacterSet::Cp437,
|
||||
CharacterSet::ISO8859_2,
|
||||
CharacterSet::ISO8859_3,
|
||||
CharacterSet::ISO8859_4,
|
||||
CharacterSet::ISO8859_5,
|
||||
// CharacterSet::ISO8859_6,
|
||||
CharacterSet::ISO8859_7,
|
||||
// CharacterSet::ISO8859_8,
|
||||
CharacterSet::ISO8859_9,
|
||||
// CharacterSet::ISO8859_10,
|
||||
// CharacterSet::ISO8859_11,
|
||||
// CharacterSet::ISO8859_13,
|
||||
// CharacterSet::ISO8859_14,
|
||||
CharacterSet::ISO8859_15,
|
||||
CharacterSet::ISO8859_16,
|
||||
CharacterSet::Shift_JIS,
|
||||
CharacterSet::Cp1250,
|
||||
CharacterSet::Cp1251,
|
||||
CharacterSet::Cp1252,
|
||||
CharacterSet::Cp1256,
|
||||
];
|
||||
|
||||
/**
|
||||
* Set of CharsetEncoders for a given input string
|
||||
@@ -144,10 +140,7 @@ impl ECIEncoderSet {
|
||||
}
|
||||
if !canEncode {
|
||||
//for the character at position i we don't yet have an encoder in the list
|
||||
for i_encoder in 0..ENCODERS.len() {
|
||||
// for encoder in ENCODERS {
|
||||
let encoder = ENCODERS.get(i_encoder).unwrap();
|
||||
// for (CharsetEncoder encoder : ENCODERS) {
|
||||
for encoder in ENCODERS.iter() {
|
||||
if encoder.encode(stringToEncode.get(i).unwrap()).is_ok() {
|
||||
//Good, we found an encoder that can encode the character. We add him to the list and continue scanning
|
||||
//the input
|
||||
@@ -172,33 +165,18 @@ impl ECIEncoderSet {
|
||||
// we need more than one single byte encoder or we need a Unicode encoder.
|
||||
// In this case we append a UTF-8 and UTF-16 encoder to the list
|
||||
// encoders = [] new CharsetEncoder[neededEncoders.size() + 2];
|
||||
encoders = Vec::new();
|
||||
// let index = 0;
|
||||
encoders = Vec::with_capacity(neededEncoders.len() + 2);
|
||||
|
||||
for encoder in neededEncoders {
|
||||
// for (CharsetEncoder encoder : neededEncoders) {
|
||||
//encoders[index++] = encoder;
|
||||
encoders.push(encoder);
|
||||
}
|
||||
encoders.extend(neededEncoders);
|
||||
|
||||
encoders.push(CharacterSet::UTF8);
|
||||
encoders.push(CharacterSet::UTF16BE);
|
||||
}
|
||||
|
||||
//Compute priorityEncoderIndex by looking up priorityCharset in encoders
|
||||
// if priorityCharset != null {
|
||||
if priorityCharset.is_some() {
|
||||
// for i in 0..encoders.len() {
|
||||
for (i, encoder) in encoders.iter().enumerate() {
|
||||
// for (int i = 0; i < encoders.length; i++) {
|
||||
// if priorityCharset.as_ref().unwrap().name() == encoder.name() {
|
||||
if priorityCharset.as_ref().unwrap() == encoder {
|
||||
priorityEncoderIndexValue = Some(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(pc) = priorityCharset.as_ref() {
|
||||
priorityEncoderIndexValue = encoders.iter().position(|enc| enc == pc);
|
||||
}
|
||||
// }
|
||||
//invariants
|
||||
assert_eq!(encoders[0], CharacterSet::ISO8859_1);
|
||||
Self {
|
||||
|
||||
@@ -206,9 +206,6 @@ impl MinimalECIInput {
|
||||
.zip(&stringToEncode)
|
||||
.take(stringToEncode.len())
|
||||
{
|
||||
// for i in 0..stringToEncode.len() {
|
||||
// for (int i = 0; i < bytes.length; i++) {
|
||||
// let c = stringToEncode.get(i).unwrap();
|
||||
*byt = if fnc1.is_some() && c == fnc1.as_ref().unwrap() {
|
||||
1000
|
||||
} else {
|
||||
@@ -332,17 +329,12 @@ impl MinimalECIInput {
|
||||
}
|
||||
}
|
||||
//optimize memory by removing edges that have been passed.
|
||||
for j in 0..encoderSet.len() {
|
||||
// for (int j = 0; j < encoderSet.length(); j++) {
|
||||
edges[i - 1][j] = None;
|
||||
}
|
||||
edges[i - 1][..encoderSet.len()].fill(None);
|
||||
}
|
||||
let mut minimalJ: i32 = -1;
|
||||
let mut minimalSize: i32 = i32::MAX;
|
||||
for j in 0..encoderSet.len() {
|
||||
// for (int j = 0; j < encoderSet.length(); j++) {
|
||||
if edges[inputLength][j].is_some() {
|
||||
let edge = edges[inputLength][j].clone().unwrap();
|
||||
if let Some(edge) = edges[inputLength][j].clone() {
|
||||
if (edge.cachedTotalSize as i32) < minimalSize {
|
||||
minimalSize = edge.cachedTotalSize as i32;
|
||||
minimalJ = j as i32;
|
||||
@@ -379,20 +371,11 @@ impl MinimalECIInput {
|
||||
c.previous.clone().unwrap().encoderIndex
|
||||
};
|
||||
if previousEncoderIndex != c.encoderIndex {
|
||||
// intsAL.splice(
|
||||
// 0..0,
|
||||
// [256 as u16 + encoderSet.getECIValue(c.encoderIndex) as u16],
|
||||
// );
|
||||
intsAL.insert(0, 256_u16 + encoderSet.get_eci(c.encoderIndex) as u16);
|
||||
}
|
||||
current = c.previous.clone();
|
||||
}
|
||||
//let mut ints = vec![0; intsAL.len()];
|
||||
// for i in 0..ints.len() {
|
||||
// // for (int i = 0; i < ints.length; i++) {
|
||||
// ints[i] = *intsAL.get(i).unwrap();
|
||||
// }
|
||||
//ints[..].copy_from_slice(&intsAL[..]);
|
||||
|
||||
intsAL
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl Quadrilateral {
|
||||
pub fn orientation(&self) -> f64 {
|
||||
let centerLine =
|
||||
(*self.top_right() + *self.bottom_right()) - (*self.top_left() + *self.bottom_left());
|
||||
if (centerLine == Point { x: 0.0, y: 0.0 }) {
|
||||
if centerLine == Point::default() {
|
||||
return 0.0;
|
||||
}
|
||||
let centerLineF = Point::normalized(centerLine);
|
||||
|
||||
@@ -89,9 +89,10 @@ impl ReedSolomonDecoder {
|
||||
let omega = &sigmaOmega[1];
|
||||
let errorLocations = self.findErrorLocations(sigma)?;
|
||||
let errorMagnitudes = self.findErrorMagnitudes(omega, &errorLocations)?;
|
||||
for i in 0..errorLocations.len() {
|
||||
for (error_location, error_magnitude) in errorLocations.iter().zip(errorMagnitudes) {
|
||||
// for i in 0..errorLocations.len() {
|
||||
//for (int i = 0; i < errorLocations.length; i++) {
|
||||
let log_value = self.field.log(errorLocations[i] as i32)?;
|
||||
let log_value = self.field.log(*error_location as i32)?;
|
||||
if log_value > received.len() as i32 - 1 {
|
||||
return Err(Exceptions::reed_solomon_with("Bad error location"));
|
||||
}
|
||||
@@ -100,7 +101,7 @@ impl ReedSolomonDecoder {
|
||||
return Err(Exceptions::reed_solomon_with("Bad error location"));
|
||||
}
|
||||
received[position as usize] =
|
||||
GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
|
||||
GenericGF::addOrSubtract(received[position as usize], error_magnitude);
|
||||
}
|
||||
Ok(errorLocations.len())
|
||||
}
|
||||
@@ -164,9 +165,8 @@ impl ReedSolomonDecoder {
|
||||
return Err(Exceptions::reed_solomon_with("sigmaTilde(0) was zero"));
|
||||
}
|
||||
|
||||
let inverse = match self.field.inverse(sigmaTildeAtZero) {
|
||||
Ok(res) => res,
|
||||
Err(_err) => return Err(Exceptions::reed_solomon_with("ArithmetricException")),
|
||||
let Ok(inverse) = self.field.inverse(sigmaTildeAtZero) else {
|
||||
return Err(Exceptions::reed_solomon_with("ArithmetricException"));
|
||||
};
|
||||
let sigma = t.multiply_with_scalar(inverse);
|
||||
let omega = r.multiply_with_scalar(inverse);
|
||||
|
||||
@@ -108,15 +108,10 @@ pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<Char
|
||||
|
||||
// for i in 0..length {
|
||||
for value in bytes.iter().take(length).copied() {
|
||||
// for (int i = 0;
|
||||
// i < length && (canBeISO88591 || canBeShiftJIS || canBeUTF8);
|
||||
// i++) {
|
||||
if !(can_be_iso88591 || can_be_shift_jis || can_be_utf8) {
|
||||
break;
|
||||
}
|
||||
|
||||
// let value = bytes[i];
|
||||
|
||||
// UTF-8 stuff
|
||||
if can_be_utf8 {
|
||||
if utf8_bytes_left > 0 {
|
||||
|
||||
@@ -26,6 +26,7 @@ use super::Version;
|
||||
*
|
||||
* @author bbrown@google.com (Brian Brown)
|
||||
*/
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct DataBlock {
|
||||
numDataCodewords: u32,
|
||||
codewords: Vec<u8>,
|
||||
@@ -65,19 +66,18 @@ impl DataBlock {
|
||||
|
||||
// Now establish DataBlocks of the appropriate size and number of data codewords
|
||||
let mut result = Vec::with_capacity(totalBlocks);
|
||||
let mut numRXingResultBlocks = 0;
|
||||
let mut numRXingResultBlocks: usize = 0;
|
||||
for ecBlock in ecBlockArray {
|
||||
for _i in 0..ecBlock.getCount() {
|
||||
// for (int i = 0; i < ecBlock.getCount(); i++) {
|
||||
let numDataCodewords = ecBlock.getDataCodewords() as usize;
|
||||
let numBlockCodewords = ecBlocks.getECCodewords() as usize + numDataCodewords;
|
||||
// result[numRXingResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
|
||||
result.push(DataBlock::new(
|
||||
let numDataCodewords = ecBlock.getDataCodewords() as usize;
|
||||
let numBlockCodewords = ecBlocks.getECCodewords() as usize + numDataCodewords;
|
||||
result.extend(vec![
|
||||
DataBlock::new(
|
||||
numDataCodewords as u32,
|
||||
vec![0; numBlockCodewords],
|
||||
));
|
||||
numRXingResultBlocks += 1;
|
||||
}
|
||||
vec![0; numBlockCodewords]
|
||||
);
|
||||
ecBlock.getCount() as usize
|
||||
]);
|
||||
numRXingResultBlocks += ecBlock.getCount() as usize;
|
||||
}
|
||||
|
||||
// All blocks have the same amount of data, except that the last n
|
||||
|
||||
@@ -100,12 +100,14 @@ impl<'a> Detector<'_> {
|
||||
))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn shiftPoint(p: Point, to: Point, div: u32) -> Point {
|
||||
let x = (to.x - p.x) / (div as f32 + 1.0);
|
||||
let y = (to.y - p.y) / (div as f32 + 1.0);
|
||||
point_f(p.x + x, p.y + y)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point {
|
||||
let mut x = p.x;
|
||||
let mut y = p.y;
|
||||
@@ -177,10 +179,7 @@ impl<'a> Detector<'_> {
|
||||
// A..D
|
||||
// : :
|
||||
// B--C
|
||||
let pointA = points[0];
|
||||
let pointB = points[1];
|
||||
let pointC = points[2];
|
||||
let pointD = points[3];
|
||||
let [pointA, pointB, pointC, pointD] = points;
|
||||
|
||||
// Transition detection on the edge is not stable.
|
||||
// To safely detect, shift the points to the module center.
|
||||
@@ -269,10 +268,7 @@ impl<'a> Detector<'_> {
|
||||
// A..D
|
||||
// | :
|
||||
// B--C
|
||||
let mut pointA = points[0];
|
||||
let mut pointB = points[1];
|
||||
let mut pointC = points[2];
|
||||
let mut pointD = points[3];
|
||||
let [mut pointA, mut pointB, mut pointC, mut pointD] = points;
|
||||
|
||||
// calculate pseudo dimensions
|
||||
let mut dimH = self.transitionsBetween(pointA, pointD) + 1;
|
||||
@@ -317,6 +313,7 @@ impl<'a> Detector<'_> {
|
||||
[pointAs, pointBs, pointCs, pointDs]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn isValid(&self, p: Point) -> bool {
|
||||
p.x >= 0.0
|
||||
&& p.x <= self.image.getWidth() as f32 - 1.0
|
||||
|
||||
@@ -54,9 +54,7 @@ fn Scan(
|
||||
let mut br = Point::default();
|
||||
let mut tr = Point::default();
|
||||
|
||||
for l in lines.iter_mut() {
|
||||
l.reset();
|
||||
}
|
||||
lines.iter_mut().for_each(|l| l.reset());
|
||||
|
||||
let [lineL, lineB, lineR, lineT] = lines;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ use crate::Exceptions;
|
||||
|
||||
use super::{high_level_encoder, Encoder};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ASCIIEncoder;
|
||||
|
||||
impl Encoder for ASCIIEncoder {
|
||||
@@ -111,8 +112,3 @@ impl ASCIIEncoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for ASCIIEncoder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ use super::{
|
||||
Encoder,
|
||||
};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Base256Encoder;
|
||||
|
||||
impl Encoder for Base256Encoder {
|
||||
fn getEncodingMode(&self) -> usize {
|
||||
BASE256_ENCODATION
|
||||
@@ -109,7 +111,7 @@ impl Base256Encoder {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
fn randomize255State(ch: char, codewordPosition: u32) -> Option<char> {
|
||||
const fn randomize255State(ch: char, codewordPosition: u32) -> Option<char> {
|
||||
let pseudoRandom = ((149 * codewordPosition) % 255) + 1;
|
||||
let tempVariable = ch as u32 + pseudoRandom;
|
||||
if tempVariable <= 255 {
|
||||
@@ -119,9 +121,3 @@ impl Base256Encoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Base256Encoder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ use super::high_level_encoder::{
|
||||
|
||||
use super::{Encoder, EncoderContext};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct C40Encoder;
|
||||
|
||||
impl Encoder for C40Encoder {
|
||||
@@ -301,9 +302,3 @@ impl C40Encoder {
|
||||
// return new String(new char[] {cw1, cw2});
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for C40Encoder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use crate::Exceptions;
|
||||
|
||||
use super::{high_level_encoder, Encoder, EncoderContext};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct EdifactEncoder;
|
||||
impl Encoder for EdifactEncoder {
|
||||
fn getEncodingMode(&self) -> usize {
|
||||
@@ -185,9 +186,3 @@ impl EdifactEncoder {
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EdifactEncoder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,10 +548,12 @@ fn getMinimumCount(mins: &[u8]) -> u32 {
|
||||
mins.iter().take(6).sum::<u8>() as u32
|
||||
}
|
||||
|
||||
pub fn isDigit(ch: char) -> bool {
|
||||
#[inline]
|
||||
pub const fn isDigit(ch: char) -> bool {
|
||||
ch.is_ascii_digit()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn isExtendedASCII(ch: char) -> bool {
|
||||
(ch as u8) >= 128 //&& (ch as u8) <= 255
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ pub fn isExtendedASCII(ch: char, fnc1: Option<char>) -> bool {
|
||||
// return ch != fnc1 && ch as u8 >= 128 && ch as u8 <= 255;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn isInC40Shift1Set(ch: char) -> bool {
|
||||
ch as u8 <= 31
|
||||
}
|
||||
@@ -606,16 +607,15 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult> {
|
||||
}
|
||||
}
|
||||
//optimize memory by removing edges that have been passed.
|
||||
for j in 0..6 {
|
||||
edges[i - 1][j] = None;
|
||||
}
|
||||
edges[i - 1][..6].fill(None);
|
||||
}
|
||||
|
||||
let mut minimalJ: i32 = -1;
|
||||
let mut minimalSize = i32::MAX;
|
||||
for j in 0..6 {
|
||||
if edges[inputLength][j].is_some() {
|
||||
let edge = edges[inputLength][j].as_ref().unwrap();
|
||||
if let Some(edge) = &edges[inputLength][j] {
|
||||
// if edges[inputLength][j].is_some() {
|
||||
// let edge = edges[inputLength][j].as_ref().unwrap();
|
||||
let size = if (1..=3).contains(&j) {
|
||||
edge.cachedTotalSize + 1
|
||||
} else {
|
||||
@@ -955,6 +955,7 @@ impl Edge {
|
||||
Self::getMinSymbolSize(self, minimum) - minimum
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn getBytes1(c: u32) -> Vec<u8> {
|
||||
// let result = vec![0u8;1];
|
||||
// result[0] = c as u8;
|
||||
@@ -962,6 +963,7 @@ impl Edge {
|
||||
vec![c as u8]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn getBytes2(c1: u32, c2: u32) -> Vec<u8> {
|
||||
// byte[] result = new byte[2];
|
||||
// result[0] = (byte) c1;
|
||||
@@ -1347,13 +1349,13 @@ impl RXingResult {
|
||||
}
|
||||
|
||||
pub fn prepend(bytes: &[u8], into: &mut Vec<u8>) -> usize {
|
||||
for i in (0..bytes.len()).rev() {
|
||||
// for (int i = bytes.length - 1; i >= 0; i--) {
|
||||
into.insert(0, bytes[i]);
|
||||
for byte in bytes.iter().rev() {
|
||||
into.insert(0, *byte);
|
||||
}
|
||||
bytes.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn randomize253State(codewordPosition: u32) -> u32 {
|
||||
let pseudoRandom = ((149 * codewordPosition) % 253) + 1;
|
||||
let tempVariable = 129 + pseudoRandom;
|
||||
|
||||
@@ -20,42 +20,39 @@ use crate::common::Result;
|
||||
use crate::{Dimension, Exceptions};
|
||||
|
||||
use super::SymbolShapeHint;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
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(),
|
||||
]
|
||||
});
|
||||
pub(super) const PROD_SYMBOLS: [SymbolInfo; 30] = [
|
||||
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.
|
||||
@@ -74,7 +71,7 @@ pub struct SymbolInfo {
|
||||
isSymbolInfo144: bool,
|
||||
}
|
||||
impl SymbolInfo {
|
||||
pub fn new(
|
||||
pub const fn new(
|
||||
rectangular: bool,
|
||||
dataCapacity: u32,
|
||||
errorCodewords: u32,
|
||||
@@ -95,7 +92,7 @@ impl SymbolInfo {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn with_details(
|
||||
pub const fn with_details(
|
||||
rectangular: bool,
|
||||
dataCapacity: u32,
|
||||
errorCodewords: u32,
|
||||
@@ -117,7 +114,7 @@ impl SymbolInfo {
|
||||
isSymbolInfo144: false,
|
||||
}
|
||||
}
|
||||
pub fn new_symbol_info_144() -> Self {
|
||||
pub const fn new_symbol_info_144() -> Self {
|
||||
let mut new_symbol = Self::with_details(false, 1558, 620, 22, 22, 36, -1, 62);
|
||||
new_symbol.isSymbolInfo144 = true;
|
||||
new_symbol
|
||||
@@ -223,7 +220,7 @@ impl fmt::Display for SymbolInfo {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct SymbolInfoLookup<'a>(Option<&'a Vec<SymbolInfo>>);
|
||||
pub struct SymbolInfoLookup<'a>(Option<&'a [SymbolInfo]>);
|
||||
impl<'a> SymbolInfoLookup<'a> {
|
||||
pub const fn new() -> Self {
|
||||
Self(None)
|
||||
@@ -233,7 +230,7 @@ impl<'a> SymbolInfoLookup<'a> {
|
||||
*
|
||||
* @param override the symbol info set to use
|
||||
*/
|
||||
pub fn overrideSymbolSet(&mut self, override_symbols: &'a Vec<SymbolInfo>) {
|
||||
pub fn overrideSymbolSet(&mut self, override_symbols: &'a [SymbolInfo]) {
|
||||
self.0 = Some(override_symbols);
|
||||
}
|
||||
|
||||
@@ -281,7 +278,7 @@ impl<'a> SymbolInfoLookup<'a> {
|
||||
fail: bool,
|
||||
// alternate_symbols_chart: Option<&'a Vec<SymbolInfo>>,
|
||||
) -> Result<Option<&'a SymbolInfo>> {
|
||||
let symbol_search_chart: &Vec<SymbolInfo> = if self.0.is_none() {
|
||||
let symbol_search_chart: &[SymbolInfo] = if self.0.is_none() {
|
||||
&PROD_SYMBOLS
|
||||
} else {
|
||||
self.0.as_ref().unwrap()
|
||||
|
||||
@@ -36,6 +36,7 @@ impl TextEncoder {
|
||||
pub fn new() -> Self {
|
||||
Self(C40Encoder::new())
|
||||
}
|
||||
|
||||
fn encodeChar(c: char, sb: &mut String) -> u32 {
|
||||
if c == ' ' {
|
||||
sb.push('\u{3}');
|
||||
|
||||
@@ -108,10 +108,6 @@ impl Reader for MaxiCodeReader {
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
impl MaxiCodeReader {
|
||||
pub const MATRIX_WIDTH: u32 = 30;
|
||||
|
||||
@@ -68,17 +68,19 @@ impl From<PointU> for Point {
|
||||
}
|
||||
|
||||
/** An alias for `Point::new`. */
|
||||
#[inline]
|
||||
pub const fn point_f(x: f32, y: f32) -> Point {
|
||||
Point::new(x, y)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn point<T>(x: T, y: T) -> PointT<T>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
PointT::new(x, y)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point {
|
||||
Point::new(x.into() as f32, y.into() as f32)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user