mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
cargo fmt
This commit is contained in:
@@ -266,7 +266,7 @@ impl BitMatrix {
|
||||
pub fn set_bool(&mut self, x: u32, y: u32, value: bool) {
|
||||
if value {
|
||||
self.set(x, y)
|
||||
}else {
|
||||
} else {
|
||||
self.unset(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ impl ECIStringBuilder {
|
||||
pub fn appendECI(&mut self, value: u32) -> Result<(), Exceptions> {
|
||||
self.encodeCurrentBytesIfAny();
|
||||
let character_set_eci = CharacterSetECI::getCharacterSetECIByValue(value)?;
|
||||
|
||||
|
||||
self.current_charset = CharacterSetECI::getCharset(&character_set_eci);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -52,21 +52,28 @@ impl Decoder {
|
||||
pub fn decode(&self, bits: &BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
|
||||
let decoded = self.perform_decode(bits, false);
|
||||
if decoded.is_ok() {
|
||||
return decoded
|
||||
return decoded;
|
||||
}
|
||||
|
||||
self.perform_decode(&Self::flip_bitmatrix(bits)?, false)
|
||||
self.perform_decode(&Self::flip_bitmatrix(bits)?, false)
|
||||
}
|
||||
|
||||
fn flip_bitmatrix( bits:&BitMatrix) -> Result<BitMatrix,Exceptions>
|
||||
{
|
||||
let mut res = BitMatrix::new(bits.getHeight(), bits.getWidth())?;
|
||||
for y in 0..res.getHeight() {
|
||||
for x in 0..res.getWidth() {
|
||||
{res.set_bool(x, y, bits.get(bits.getWidth() - 1 - y, bits.getHeight() - 1 - x));}}}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
fn flip_bitmatrix(bits: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||
let mut res = BitMatrix::new(bits.getHeight(), bits.getWidth())?;
|
||||
for y in 0..res.getHeight() {
|
||||
for x in 0..res.getWidth() {
|
||||
{
|
||||
res.set_bool(
|
||||
x,
|
||||
y,
|
||||
bits.get(bits.getWidth() - 1 - y, bits.getHeight() - 1 - x),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans.
|
||||
@@ -78,7 +85,7 @@ impl Decoder {
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
pub fn decode_bools(&self, image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
|
||||
self.perform_decode(&BitMatrix::parse_bools(image),false)
|
||||
self.perform_decode(&BitMatrix::parse_bools(image), false)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +97,11 @@ impl Decoder {
|
||||
* @throws FormatException if the Data Matrix Code cannot be decoded
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
fn perform_decode(&self, bits: &BitMatrix, fix259: bool) -> Result<DecoderRXingResult, Exceptions> {
|
||||
fn perform_decode(
|
||||
&self,
|
||||
bits: &BitMatrix,
|
||||
fix259: bool,
|
||||
) -> Result<DecoderRXingResult, Exceptions> {
|
||||
// Construct a parser and read version, error-correction level
|
||||
let mut parser = BitMatrixParser::new(bits)?;
|
||||
|
||||
@@ -119,8 +130,8 @@ impl Decoder {
|
||||
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())
|
||||
} else if errors_corrected.is_err() {
|
||||
return Err(errors_corrected.err().unwrap());
|
||||
}
|
||||
for i in 0..numDataCodewords {
|
||||
// for (int i = 0; i < numDataCodewords; i++) {
|
||||
|
||||
@@ -693,8 +693,7 @@ fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Resu
|
||||
|
||||
let thirdByte = bits.readBits(8)?;
|
||||
|
||||
result
|
||||
.appendECI((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1)
|
||||
result.appendECI((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1)
|
||||
|
||||
// if bits.available() < 8 {
|
||||
// return Err(Exceptions::FormatException(None));
|
||||
|
||||
Reference in New Issue
Block a user