update eci_string_builder

This change modifies how the ECIStringBuilder works. Perviously it encoded data as it went, whenever the eci state changed. The new method only decodes data when it is requested, simply appending bytes as it goes otherwise.

This should improve performance in a few situations.

This release also uses the ECIStringBuilder in qrcodes, which previously handled their own decoding.
This commit is contained in:
Henry Schimke
2023-03-07 17:09:42 -06:00
parent 19d5b6276c
commit d5e6a5d0a7
4 changed files with 183 additions and 146 deletions

View File

@@ -739,21 +739,21 @@ fn decodeBase256Segment(
fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Result<bool> {
let firstByte = bits.readBits(8)?;
if firstByte <= 127 {
result.appendECI(Eci::from(firstByte - 1))?;
result.append_eci(Eci::from(firstByte - 1));
return Ok(true);
}
let secondByte = bits.readBits(8)?;
if firstByte <= 191 {
result.appendECI(Eci::from((firstByte - 128) * 254 + 127 + secondByte - 1))?;
result.append_eci(Eci::from((firstByte - 128) * 254 + 127 + secondByte - 1));
return Ok((firstByte - 128) * 254 + 127 + secondByte - 1 > 900);
}
let thirdByte = bits.readBits(8)?;
result.appendECI(Eci::from(
result.append_eci(Eci::from(
(firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1,
))?;
));
Ok((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1 > 900)
}