Added error correction level to Result
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 22 Jul 2009 10:40:18 +0000 (10:40 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 22 Jul 2009 10:40:18 +0000 (10:40 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1026 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/ResultMetadataType.java
core/src/com/google/zxing/common/DecoderResult.java
core/src/com/google/zxing/datamatrix/DataMatrixReader.java
core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java
core/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java
core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java
core/src/com/google/zxing/qrcode/QRCodeReader.java
core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java
core/src/com/google/zxing/qrcode/decoder/Decoder.java
core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java

index 7e898a6..722b76d 100644 (file)
@@ -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() {
   }
 
index 137987c..ce0e3c5 100644 (file)
@@ -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;
+  }
+
 }
\ No newline at end of file
index 30a4f45..18e88b6 100644 (file)
@@ -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;
   }
 
index b5996cc..8265e86 100644 (file)
@@ -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);
   }
   
   /**
index 032b7b4..191a714 100644 (file)
@@ -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 
index d2f4d3d..2f0b4af 100644 (file)
@@ -123,7 +123,7 @@ final class DecodedBitStreamParser {
         throw ReaderException.getInstance();\r
       }\r
     }\r
-    return new DecoderResult(null, result.toString(), null);\r
+    return new DecoderResult(null, result.toString(), null, null);\r
   }\r
 \r
   /**\r
index 2c9c5f2..0341f91 100644 (file)
@@ -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;
   }
 
index 012b837..b6efa2b 100644 (file)
@@ -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,
index bcfda39..26394e5 100644 (file)
@@ -97,7 +97,7 @@ public final class Decoder {
     }\r
 \r
     // Decode the contents of that stream of bytes\r
-    return DecodedBitStreamParser.decode(resultBytes, version);\r
+    return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);\r
   }\r
 \r
   /**\r
index 7156586..7d3dd89 100644 (file)
@@ -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);
   }