mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
fixed issue with ec results not being used
This commit is contained in:
@@ -181,7 +181,7 @@ impl StringUtils {
|
||||
break;
|
||||
}
|
||||
|
||||
let value = bytes[i] & 0xFF;
|
||||
let value = bytes[i];
|
||||
|
||||
// UTF-8 stuff
|
||||
if can_be_utf8 {
|
||||
@@ -1545,7 +1545,7 @@ impl BitSource {
|
||||
return Err(Exceptions::IllegalArgumentException(numBits.to_string()));
|
||||
}
|
||||
|
||||
let mut result:u32 = 0;
|
||||
let mut result: u32 = 0;
|
||||
|
||||
let mut num_bits = numBits;
|
||||
|
||||
@@ -1850,7 +1850,12 @@ pub struct DecoderRXingResult {
|
||||
}
|
||||
|
||||
impl DecoderRXingResult {
|
||||
pub fn new(rawBytes: Vec<u8>, text: String, byteSegments: Vec<Vec<u8>>, ecLevel: String) -> Self {
|
||||
pub fn new(
|
||||
rawBytes: Vec<u8>,
|
||||
text: String,
|
||||
byteSegments: Vec<Vec<u8>>,
|
||||
ecLevel: String,
|
||||
) -> Self {
|
||||
Self::with_all(rawBytes, text, byteSegments, ecLevel, -2, -2, 0)
|
||||
}
|
||||
|
||||
@@ -1894,7 +1899,7 @@ impl DecoderRXingResult {
|
||||
pub fn with_all(
|
||||
rawBytes: Vec<u8>,
|
||||
text: String,
|
||||
byteSegments:Vec<Vec<u8>>,
|
||||
byteSegments: Vec<Vec<u8>>,
|
||||
ecLevel: String,
|
||||
saSequence: i32,
|
||||
saParity: i32,
|
||||
@@ -2243,11 +2248,11 @@ pub trait GridSampler {
|
||||
}
|
||||
// Check and nudge points from end:
|
||||
nudged = true;
|
||||
let mut offset = points.len() - 2;
|
||||
let mut offset = points.len() as isize - 2;
|
||||
while offset >= 0 && nudged {
|
||||
// for (int offset = points.length - 2; offset >= 0 && nudged; offset -= 2) {
|
||||
let x = points[offset] as i32;
|
||||
let y = points[offset + 1] as i32;
|
||||
let x = points[offset as usize] as i32;
|
||||
let y = points[offset as usize + 1] as i32;
|
||||
if x < -1 || x > width.try_into().unwrap() || y < -1 || y > height.try_into().unwrap() {
|
||||
return Err(Exceptions::NotFoundException(
|
||||
"getNotFoundInstance".to_owned(),
|
||||
@@ -2255,20 +2260,20 @@ pub trait GridSampler {
|
||||
}
|
||||
nudged = false;
|
||||
if x == -1 {
|
||||
points[offset] = 0.0f32;
|
||||
points[offset as usize] = 0.0f32;
|
||||
nudged = true;
|
||||
} else if (x == width.try_into().unwrap()) {
|
||||
points[offset] = width as f32 - 1f32;
|
||||
} else if x == width.try_into().unwrap() {
|
||||
points[offset as usize] = width as f32 - 1f32;
|
||||
nudged = true;
|
||||
}
|
||||
if y == -1 {
|
||||
points[offset + 1] = 0.0f32;
|
||||
points[offset as usize + 1] = 0.0f32;
|
||||
nudged = true;
|
||||
} else if (y == height.try_into().unwrap()) {
|
||||
points[offset + 1] = height as f32 - 1f32;
|
||||
} else if y == height.try_into().unwrap() {
|
||||
points[offset as usize + 1] = height as f32 - 1f32;
|
||||
nudged = true;
|
||||
}
|
||||
offset += 2;
|
||||
offset += -2;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -2363,6 +2368,13 @@ impl GridSampler for DefaultGridSampler {
|
||||
let mut x = 0;
|
||||
while x < max {
|
||||
// for (int x = 0; x < max; x += 2) {
|
||||
if points[x].floor() as u32 >= image.getWidth()
|
||||
|| points[x + 1].floor() as u32 >= image.getHeight()
|
||||
{
|
||||
return Err(Exceptions::NotFoundException(
|
||||
"index out of bounds, see documentation in file for explanation".to_owned(),
|
||||
));
|
||||
}
|
||||
if image.get(points[x].floor() as u32, points[x + 1].floor() as u32) {
|
||||
// Black(-ish) pixel
|
||||
bits.set(x as u32 / 2, y);
|
||||
@@ -4127,4 +4139,4 @@ impl HybridBinarizer {
|
||||
}
|
||||
blackPoints
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,7 +701,7 @@ impl ReedSolomonDecoder {
|
||||
}
|
||||
let syndrome = match GenericGFPoly::new(self.field, &syndromeCoefficients) {
|
||||
Ok(res) => res,
|
||||
Err(fail) => {
|
||||
Err(_fail) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"IllegalArgumentException".to_owned(),
|
||||
))
|
||||
@@ -722,13 +722,13 @@ impl ReedSolomonDecoder {
|
||||
if log_value > received.len() as i32 - 1 {
|
||||
return Ok(());
|
||||
}
|
||||
let position: usize = received.len() - 1 - log_value as usize;
|
||||
let position: isize = received.len() as isize - 1 - log_value as isize;
|
||||
if position < 0 {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"Bad error location".to_owned(),
|
||||
));
|
||||
}
|
||||
received[position] = GenericGF::addOrSubtract(received[position], errorMagnitudes[i]);
|
||||
received[position as usize] = GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -774,7 +774,7 @@ impl ReedSolomonDecoder {
|
||||
let denominatorLeadingTerm = rLast.getCoefficient(rLast.getDegree());
|
||||
let dltInverse = match self.field.inverse(denominatorLeadingTerm) {
|
||||
Ok(inv) => inv,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"ArithmetricException".to_owned(),
|
||||
))
|
||||
@@ -787,7 +787,7 @@ impl ReedSolomonDecoder {
|
||||
.multiply(r.getCoefficient(r.getDegree()), dltInverse);
|
||||
q = match q.addOrSubtract(&GenericGF::buildMonomial(self.field, degreeDiff, scale)) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"IllegalArgumentException".to_owned(),
|
||||
))
|
||||
@@ -795,14 +795,14 @@ impl ReedSolomonDecoder {
|
||||
};
|
||||
r = match r.addOrSubtract(&match rLast.multiply_by_monomial(degreeDiff, scale) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"IllegalArgumentException".to_owned(),
|
||||
))
|
||||
}
|
||||
}) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"IllegalArgumentException".to_owned(),
|
||||
))
|
||||
@@ -812,7 +812,7 @@ impl ReedSolomonDecoder {
|
||||
|
||||
t = match (match q.multiply(&tLast) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"IllegalArgumentException".to_owned(),
|
||||
))
|
||||
@@ -821,7 +821,7 @@ impl ReedSolomonDecoder {
|
||||
.addOrSubtract(&tLastLast)
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"IllegalArgumentException".to_owned(),
|
||||
))
|
||||
@@ -845,7 +845,7 @@ impl ReedSolomonDecoder {
|
||||
|
||||
let inverse = match self.field.inverse(sigmaTildeAtZero) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"ArithmetricException".to_owned(),
|
||||
))
|
||||
@@ -874,7 +874,7 @@ impl ReedSolomonDecoder {
|
||||
if errorLocator.evaluateAt(i) == 0 {
|
||||
result[e] = match self.field.inverse(i.try_into().unwrap()) {
|
||||
Ok(res) => res.try_into().unwrap(),
|
||||
Err(err) => {
|
||||
Err(_err) => {
|
||||
return Err(Exceptions::ReedSolomonException(
|
||||
"ArithmetricException".to_owned(),
|
||||
))
|
||||
|
||||
@@ -197,8 +197,11 @@ fn correctErrors(codewordBytes: &mut [u8], numDataCodewords: usize) -> Result<()
|
||||
// for (int i = 0; i < numCodewords; i++) {
|
||||
codewordsInts[i] = codewordBytes[i]; // & 0xFF;
|
||||
}
|
||||
|
||||
let mut sending_code_words : Vec<i32> = codewordsInts.iter().map(|x| *x as i32).collect();
|
||||
|
||||
if let Err(e) = rsDecoder.decode(
|
||||
&mut codewordsInts.iter().map(|x| *x as i32).collect(),
|
||||
&mut sending_code_words,
|
||||
(codewordBytes.len() - numDataCodewords) as i32,
|
||||
) {
|
||||
if let Exceptions::ReedSolomonException(error_str) = e {
|
||||
@@ -210,7 +213,7 @@ fn correctErrors(codewordBytes: &mut [u8], numDataCodewords: usize) -> Result<()
|
||||
// We don't care about errors in the error-correction codewords
|
||||
for i in 0..numDataCodewords {
|
||||
// for (int i = 0; i < numDataCodewords; i++) {
|
||||
codewordBytes[i] = codewordsInts[i];
|
||||
codewordBytes[i] = sending_code_words[i] as u8;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ impl AlignmentPatternFinder {
|
||||
let centerJ = Self::centerFromEnd(stateCount, j);
|
||||
let centerI = self.crossCheckVertical(
|
||||
i,
|
||||
centerJ.floor() as u32,
|
||||
centerJ.round() as u32,
|
||||
2 * stateCount[1],
|
||||
stateCountTotal,
|
||||
);
|
||||
|
||||
@@ -462,13 +462,13 @@ impl Detector {
|
||||
// Look for an alignment pattern (3 modules in size) around where it
|
||||
// should be
|
||||
let allowance = (allowanceFactor * overallEstModuleSize) as u32;
|
||||
let alignmentAreaLeftX = 0.max(estAlignmentX - allowance);
|
||||
let alignmentAreaLeftX = 0.max(estAlignmentX as i32- allowance as i32) as u32;
|
||||
let alignmentAreaRightX = (self.image.getWidth() - 1).min(estAlignmentX + allowance);
|
||||
if ((alignmentAreaRightX - alignmentAreaLeftX) as f32) < overallEstModuleSize * 3.0 {
|
||||
return Err(Exceptions::NotFoundException("not found".to_owned()));
|
||||
}
|
||||
|
||||
let alignmentAreaTopY = 0.max(estAlignmentY - allowance);
|
||||
let alignmentAreaTopY = 0.max(estAlignmentY as i32 - allowance as i32) as u32;
|
||||
let alignmentAreaBottomY = (self.image.getHeight() - 1).min(estAlignmentY + allowance);
|
||||
if alignmentAreaBottomY - alignmentAreaTopY < overallEstModuleSize as u32 * 3 {
|
||||
return Err(Exceptions::NotFoundException("not found".to_owned()));
|
||||
|
||||
@@ -92,7 +92,7 @@ impl FinderPattern {
|
||||
combinedX,
|
||||
combinedY,
|
||||
combinedModuleSize,
|
||||
combinedCount.floor() as usize,
|
||||
combinedCount.round() as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ impl FinderPatternFinder {
|
||||
// Skip by rowSkip, but back off by stateCount[2] (size of last center
|
||||
// of pattern we saw) to be conservative, and also back off by iSkip which
|
||||
// is about to be re-added
|
||||
i += rowSkip - stateCount[2] - iSkip;
|
||||
i += (rowSkip as i32 - stateCount[2] as i32 - iSkip as i32).max(0) as u32;
|
||||
j = maxJ - 1;
|
||||
}
|
||||
}
|
||||
@@ -620,7 +620,7 @@ impl FinderPatternFinder {
|
||||
return (((fnp.getX() - center.getX().abs())
|
||||
- (fnp.getY() - center.getY()).abs())
|
||||
/ 2.0)
|
||||
.floor() as u32;
|
||||
.round() as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user