Issue 331
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 29 Jan 2010 10:27:07 +0000 (10:27 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 29 Jan 2010 10:27:07 +0000 (10:27 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1191 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/DecodeHintType.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

index 2c863dd..20b922c 100644 (file)
@@ -52,6 +52,11 @@ public final class DecodeHintType {
    */
   public static final DecodeHintType TRY_HARDER = new DecodeHintType();
 
+  /**
+   * Specifies what character encoding to use when decoding, where applicable (type String)
+   */
+  public static final DecodeHintType CHARACTER_SET = new DecodeHintType();
+
   /**
    * Allowed lengths of encoded data -- reject anything else. Maps to an int[].
    */
index 0341f91..52002ae 100644 (file)
@@ -63,11 +63,11 @@ public class QRCodeReader implements Reader {
     ResultPoint[] points;
     if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
       BitMatrix bits = extractPureBits(image.getBlackMatrix());
-      decoderResult = decoder.decode(bits);
+      decoderResult = decoder.decode(bits, hints);
       points = NO_POINTS;
     } else {
       DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
-      decoderResult = decoder.decode(detectorResult.getBits());
+      decoderResult = decoder.decode(detectorResult.getBits(), hints);
       points = detectorResult.getPoints();
     }
 
@@ -81,6 +81,10 @@ public class QRCodeReader implements Reader {
     return result;
   }
 
+  public void reset() {
+    // do nothing
+  }
+
   /**
    * This method detects a barcode in a "pure" image -- that is, pure monochrome image
    * which contains only an unrotated, unskewed, image of a barcode, with some white border
index dc6ad78..55ff636 100644 (file)
 
 package com.google.zxing.qrcode.decoder;
 
+import com.google.zxing.DecodeHintType;
 import com.google.zxing.ReaderException;
 import com.google.zxing.common.BitSource;
 import com.google.zxing.common.CharacterSetECI;
 import com.google.zxing.common.DecoderResult;
 
 import java.io.UnsupportedEncodingException;
+import java.util.Hashtable;
 import java.util.Vector;
 
 /**
@@ -57,7 +59,8 @@ final class DecodedBitStreamParser {
   private DecodedBitStreamParser() {
   }
 
-  static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel) throws ReaderException {
+  static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Hashtable hints)
+      throws ReaderException {
     BitSource bits = new BitSource(bytes);
     StringBuffer result = new StringBuffer(50);
     CharacterSetECI currentCharacterSetECI = null;
@@ -99,7 +102,7 @@ final class DecodedBitStreamParser {
           } else if (mode.equals(Mode.ALPHANUMERIC)) {
             decodeAlphanumericSegment(bits, result, count, fc1InEffect);
           } else if (mode.equals(Mode.BYTE)) {
-            decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments);
+            decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
           } else if (mode.equals(Mode.KANJI)) {
             decodeKanjiSegment(bits, result, count);
           } else {
@@ -147,7 +150,8 @@ final class DecodedBitStreamParser {
                                         StringBuffer result,
                                         int count,
                                         CharacterSetECI currentCharacterSetECI,
-                                        Vector byteSegments) throws ReaderException {
+                                        Vector byteSegments,
+                                        Hashtable hints) throws ReaderException {
     byte[] readBytes = new byte[count];
     if (count << 3 > bits.available()) {
       throw ReaderException.getInstance();
@@ -162,7 +166,7 @@ final class DecodedBitStreamParser {
     // upon decoding. I have seen ISO-8859-1 used as well as
     // Shift_JIS -- without anything like an ECI designator to
     // give a hint.
-      encoding = guessEncoding(readBytes);
+      encoding = guessEncoding(readBytes, hints);
     } else {
       encoding = currentCharacterSetECI.getEncodingName();
     }
@@ -240,7 +244,13 @@ final class DecodedBitStreamParser {
     }
   }
 
-  private static String guessEncoding(byte[] bytes) {
+  private static String guessEncoding(byte[] bytes, Hashtable hints) {
+    if (hints != null) {
+      String characterSet = (String) hints.get(DecodeHintType.CHARACTER_SET);
+      if (characterSet != null) {
+        return characterSet;
+      }
+    }
     if (ASSUME_SHIFT_JIS) {
       return SHIFT_JIS;
     }
index 26394e5..6a576f8 100644 (file)
@@ -23,6 +23,8 @@ import com.google.zxing.common.reedsolomon.GF256;
 import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;\r
 import com.google.zxing.common.reedsolomon.ReedSolomonException;\r
 \r
+import java.util.Hashtable;\r
+\r
 /**\r
  * <p>The main class which implements QR Code decoding -- as opposed to locating and extracting\r
  * the QR Code from an image.</p>\r
@@ -37,6 +39,10 @@ public final class Decoder {
     rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r
   }\r
 \r
+  public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+    return decode(image, null);\r
+  }\r
+\r
   /**\r
    * <p>Convenience method that can decode a QR Code represented as a 2D array of booleans.\r
    * "true" is taken to mean a black module.</p>\r
@@ -45,7 +51,7 @@ public final class Decoder {
    * @return text and bytes encoded within the QR Code\r
    * @throws ReaderException if the QR Code cannot be decoded\r
    */\r
-  public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+  public DecoderResult decode(boolean[][] image, Hashtable hints) throws ReaderException {\r
     int dimension = image.length;\r
     BitMatrix bits = new BitMatrix(dimension);\r
     for (int i = 0; i < dimension; i++) {\r
@@ -55,7 +61,11 @@ public final class Decoder {
         }\r
       }\r
     }\r
-    return decode(bits);\r
+    return decode(bits, hints);\r
+  }\r
+\r
+  public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+    return decode(bits, null);\r
   }\r
 \r
   /**\r
@@ -65,7 +75,7 @@ public final class Decoder {
    * @return text and bytes encoded within the QR Code\r
    * @throws ReaderException if the QR Code cannot be decoded\r
    */\r
-  public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+  public DecoderResult decode(BitMatrix bits, Hashtable hints) throws ReaderException {\r
 \r
     // Construct a parser and read version, error-correction level\r
     BitMatrixParser parser = new BitMatrixParser(bits);\r
@@ -97,7 +107,7 @@ public final class Decoder {
     }\r
 \r
     // Decode the contents of that stream of bytes\r
-    return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);\r
+    return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints);\r
   }\r
 \r
   /**\r