mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
backport changes from c++ for datamatrix
This commit is contained in:
@@ -51,6 +51,7 @@ impl DataBlock {
|
|||||||
pub fn getDataBlocks(
|
pub fn getDataBlocks(
|
||||||
rawCodewords: &[u8],
|
rawCodewords: &[u8],
|
||||||
version: &Version,
|
version: &Version,
|
||||||
|
fix259: bool,
|
||||||
) -> Result<Vec<DataBlock>, Exceptions> {
|
) -> Result<Vec<DataBlock>, Exceptions> {
|
||||||
// Figure out the number and size of data blocks used by this version
|
// Figure out the number and size of data blocks used by this version
|
||||||
let ecBlocks = version.getECBlocks();
|
let ecBlocks = version.getECBlocks();
|
||||||
@@ -121,7 +122,7 @@ impl DataBlock {
|
|||||||
// for (int i = longerBlocksNumDataCodewords; i < max; i++) {
|
// for (int i = longerBlocksNumDataCodewords; i < max; i++) {
|
||||||
for j in 0..numRXingResultBlocks {
|
for j in 0..numRXingResultBlocks {
|
||||||
// for (int j = 0; j < numRXingResultBlocks; j++) {
|
// for (int j = 0; j < numRXingResultBlocks; j++) {
|
||||||
let jOffset = if specialVersion {
|
let jOffset = if specialVersion && fix259 {
|
||||||
(j + 8) % numRXingResultBlocks
|
(j + 8) % numRXingResultBlocks
|
||||||
} else {
|
} else {
|
||||||
j
|
j
|
||||||
|
|||||||
@@ -40,6 +40,19 @@ impl Decoder {
|
|||||||
// rsDecoder = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
|
// rsDecoder = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Decodes a Data Matrix Code represented as a {@link BitMatrix}. A 1 or "true" is taken
|
||||||
|
* to mean a black module.</p>
|
||||||
|
*
|
||||||
|
* @param bits booleans representing white/black Data Matrix Code modules
|
||||||
|
* @return text and bytes encoded within the Data Matrix Code
|
||||||
|
* @throws FormatException if the Data Matrix Code cannot be decoded
|
||||||
|
* @throws ChecksumException if error correction fails
|
||||||
|
*/
|
||||||
|
pub fn decode(&self, bits: &BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
|
self.perform_decode(bits, false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans.
|
* <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans.
|
||||||
* "true" is taken to mean a black module.</p>
|
* "true" is taken to mean a black module.</p>
|
||||||
@@ -50,7 +63,7 @@ impl Decoder {
|
|||||||
* @throws ChecksumException if error correction fails
|
* @throws ChecksumException if error correction fails
|
||||||
*/
|
*/
|
||||||
pub fn decode_bools(&self, image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
|
pub fn decode_bools(&self, image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
self.decode(&BitMatrix::parse_bools(image))
|
self.perform_decode(&BitMatrix::parse_bools(image),false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +75,7 @@ impl Decoder {
|
|||||||
* @throws FormatException if the Data Matrix Code cannot be decoded
|
* @throws FormatException if the Data Matrix Code cannot be decoded
|
||||||
* @throws ChecksumException if error correction fails
|
* @throws ChecksumException if error correction fails
|
||||||
*/
|
*/
|
||||||
pub fn decode(&self, bits: &BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
|
fn perform_decode(&self, bits: &BitMatrix, fix259: bool) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
// Construct a parser and read version, error-correction level
|
// Construct a parser and read version, error-correction level
|
||||||
let mut parser = BitMatrixParser::new(bits)?;
|
let mut parser = BitMatrixParser::new(bits)?;
|
||||||
|
|
||||||
@@ -72,7 +85,7 @@ impl Decoder {
|
|||||||
let version = parser.getVersion();
|
let version = parser.getVersion();
|
||||||
|
|
||||||
// Separate into data blocks
|
// Separate into data blocks
|
||||||
let dataBlocks = DataBlock::getDataBlocks(&codewords, version)?;
|
let dataBlocks = DataBlock::getDataBlocks(&codewords, version, fix259)?;
|
||||||
|
|
||||||
// Count total number of data bytes
|
// Count total number of data bytes
|
||||||
let totalBytes = dataBlocks
|
let totalBytes = dataBlocks
|
||||||
@@ -88,7 +101,12 @@ impl Decoder {
|
|||||||
let dataBlock = &dataBlocks[j];
|
let dataBlock = &dataBlocks[j];
|
||||||
let mut codewordBytes = dataBlock.getCodewords().to_vec();
|
let mut codewordBytes = dataBlock.getCodewords().to_vec();
|
||||||
let numDataCodewords = dataBlock.getNumDataCodewords() as usize;
|
let numDataCodewords = dataBlock.getNumDataCodewords() as usize;
|
||||||
self.correctErrors(&mut codewordBytes, numDataCodewords as u32)?;
|
let errors_corrected = self.correctErrors(&mut codewordBytes, numDataCodewords as u32);
|
||||||
|
if errors_corrected.is_err() && !fix259 {
|
||||||
|
return self.perform_decode(bits, true);
|
||||||
|
}else if errors_corrected.is_err() {
|
||||||
|
return Err(errors_corrected.err().unwrap())
|
||||||
|
}
|
||||||
for i in 0..numDataCodewords {
|
for i in 0..numDataCodewords {
|
||||||
// for (int i = 0; i < numDataCodewords; i++) {
|
// for (int i = 0; i < numDataCodewords; i++) {
|
||||||
// De-interlace data blocks.
|
// De-interlace data blocks.
|
||||||
|
|||||||
@@ -139,16 +139,18 @@ pub trait BitMatrixCursor {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fn countEdges(&mut self, range: Option<i32>) -> i32 {
|
fn countEdges(&mut self, range: i32) -> i32 {
|
||||||
let mut range = if let Some(r) = range { r } else { 0 };
|
|
||||||
let mut res = 0;
|
let mut res = 0;
|
||||||
|
let mut range = range;
|
||||||
|
|
||||||
let mut steps = self.stepToEdge(Some(1), Some(range), None);
|
let mut steps;
|
||||||
|
|
||||||
while steps > 0 {
|
while {
|
||||||
|
steps = if range == 0 { 0 } else {self.stepToEdge(Some(1), Some(range), None)};
|
||||||
|
steps > 0
|
||||||
|
} {
|
||||||
range -= steps;
|
range -= steps;
|
||||||
res += 1;
|
res += 1;
|
||||||
steps = self.stepToEdge(Some(1), Some(range), None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -326,6 +326,10 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// re-evaluate line with all the points up to here before projecting
|
||||||
|
if (!line.evaluate_max_distance(Some(1.5), None))
|
||||||
|
{return Ok(false);}
|
||||||
|
|
||||||
let mut np = line.project(&self.p);
|
let mut np = line.project(&self.p);
|
||||||
// make sure we are making progress even when back-projecting:
|
// make sure we are making progress even when back-projecting:
|
||||||
// consider a 90deg corner, rotated 45deg. we step away perpendicular from the line and get
|
// consider a 90deg corner, rotated 45deg. we step away perpendicular from the line and get
|
||||||
|
|||||||
Reference in New Issue
Block a user