mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Added error correction level to Result
git-svn-id: https://zxing.googlecode.com/svn/trunk@1026 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
91d8e04d86
commit
4331605913
|
@ -51,6 +51,12 @@ public final class ResultMetadataType {
|
|||
*/
|
||||
public static final ResultMetadataType BYTE_SEGMENTS = new ResultMetadataType();
|
||||
|
||||
/**
|
||||
* Error correction level used, if applicable. The value type depends on the
|
||||
* format, but is typically a String.
|
||||
*/
|
||||
public static final ResultMetadataType ERROR_CORRECTION_LEVEL = new ResultMetadataType();
|
||||
|
||||
private ResultMetadataType() {
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
|
@ -30,14 +32,16 @@ public final class DecoderResult {
|
|||
private final byte[] rawBytes;
|
||||
private final String text;
|
||||
private final Vector byteSegments;
|
||||
private final ErrorCorrectionLevel ecLevel;
|
||||
|
||||
public DecoderResult(byte[] rawBytes, String text, Vector byteSegments) {
|
||||
public DecoderResult(byte[] rawBytes, String text, Vector byteSegments, ErrorCorrectionLevel ecLevel) {
|
||||
if (rawBytes == null && text == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
this.rawBytes = rawBytes;
|
||||
this.text = text;
|
||||
this.byteSegments = byteSegments;
|
||||
this.ecLevel = ecLevel;
|
||||
}
|
||||
|
||||
public byte[] getRawBytes() {
|
||||
|
@ -52,4 +56,8 @@ public final class DecoderResult {
|
|||
return byteSegments;
|
||||
}
|
||||
|
||||
public ErrorCorrectionLevel getECLevel() {
|
||||
return ecLevel;
|
||||
}
|
||||
|
||||
}
|
|
@ -70,6 +70,9 @@ public final class DataMatrixReader implements Reader {
|
|||
if (decoderResult.getByteSegments() != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
|
||||
}
|
||||
if (decoderResult.getECLevel() != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ final class DecodedBitStreamParser {
|
|||
if (resultTrailer.length() > 0) {
|
||||
result.append(resultTrailer.toString());
|
||||
}
|
||||
return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments);
|
||||
return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,6 +57,9 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
|
|||
if (decoderResult.getByteSegments() != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
|
||||
}
|
||||
if (decoderResult.getECLevel() != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
|
||||
}
|
||||
results.addElement(result);
|
||||
} catch (ReaderException re) {
|
||||
// ignore and continue
|
||||
|
|
|
@ -123,7 +123,7 @@ final class DecodedBitStreamParser {
|
|||
throw ReaderException.getInstance();
|
||||
}
|
||||
}
|
||||
return new DecoderResult(null, result.toString(), null);
|
||||
return new DecoderResult(null, result.toString(), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,6 +75,9 @@ public class QRCodeReader implements Reader {
|
|||
if (decoderResult.getByteSegments() != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
|
||||
}
|
||||
if (decoderResult.getECLevel() != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ final class DecodedBitStreamParser {
|
|||
private DecodedBitStreamParser() {
|
||||
}
|
||||
|
||||
static DecoderResult decode(byte[] bytes, Version version) throws ReaderException {
|
||||
static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel) throws ReaderException {
|
||||
BitSource bits = new BitSource(bytes);
|
||||
StringBuffer result = new StringBuffer();
|
||||
CharacterSetECI currentCharacterSetECI = null;
|
||||
|
@ -109,7 +109,7 @@ final class DecodedBitStreamParser {
|
|||
}
|
||||
} while (!mode.equals(Mode.TERMINATOR));
|
||||
|
||||
return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments);
|
||||
return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, ecLevel);
|
||||
}
|
||||
|
||||
private static void decodeKanjiSegment(BitSource bits,
|
||||
|
|
|
@ -97,7 +97,7 @@ public final class Decoder {
|
|||
}
|
||||
|
||||
// Decode the contents of that stream of bytes
|
||||
return DecodedBitStreamParser.decode(resultBytes, version);
|
||||
return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ public final class DecodedBitStreamParserTestCase extends TestCase {
|
|||
builder.write(0xF2, 8);
|
||||
builder.write(0xF3, 8);
|
||||
String result = DecodedBitStreamParser.decode(builder.toByteArray(),
|
||||
Version.getVersionForNumber(1)).getText();
|
||||
Version.getVersionForNumber(1), null).getText();
|
||||
assertEquals("\u00f1\u00f2\u00f3", result);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public final class DecodedBitStreamParserTestCase extends TestCase {
|
|||
builder.write(0xA2, 8);
|
||||
builder.write(0xA3, 8);
|
||||
String result = DecodedBitStreamParser.decode(builder.toByteArray(),
|
||||
Version.getVersionForNumber(1)).getText();
|
||||
Version.getVersionForNumber(1), null).getText();
|
||||
assertEquals("\uff61\uff62\uff63", result);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public final class DecodedBitStreamParserTestCase extends TestCase {
|
|||
builder.write(0xA2, 8);
|
||||
builder.write(0xA3, 8);
|
||||
String result = DecodedBitStreamParser.decode(builder.toByteArray(),
|
||||
Version.getVersionForNumber(1)).getText();
|
||||
Version.getVersionForNumber(1), null).getText();
|
||||
assertEquals("\u00ed\u00f3\u00fa", result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue