Small style stuff
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / Decoder.java
index 4f73245..520e076 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright 2007 Google Inc.\r
+ * Copyright 2007 ZXing authors\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 \r
 package com.google.zxing.qrcode.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.common.BitMatrix;\r
+import com.google.zxing.common.DecoderResult;\r
 import com.google.zxing.common.reedsolomon.GF256;\r
 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
  *\r
- * @author srowen@google.com (Sean Owen)\r
+ * @author Sean Owen\r
  */\r
 public final class Decoder {\r
 \r
@@ -36,35 +41,46 @@ public final class Decoder {
     rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r
   }\r
 \r
+  public DecoderResult decode(boolean[][] image)\r
+      throws ChecksumException, FormatException, NotFoundException {\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
    *\r
    * @param image booleans representing white/black QR Code modules\r
-   * @return text encoded within the QR Code\r
-   * @throws ReaderException if the QR Code cannot be decoded\r
+   * @return text and bytes encoded within the QR Code\r
+   * @throws FormatException if the QR Code cannot be decoded\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  public String decode(boolean[][] image) throws ReaderException {\r
+  public DecoderResult decode(boolean[][] image, Hashtable hints) throws ChecksumException, FormatException {\r
     int dimension = image.length;\r
     BitMatrix bits = new BitMatrix(dimension);\r
     for (int i = 0; i < dimension; i++) {\r
       for (int j = 0; j < dimension; j++) {\r
         if (image[i][j]) {\r
-          bits.set(i, j);\r
+          bits.set(j, i);\r
         }\r
       }\r
     }\r
-    return decode(bits);\r
+    return decode(bits, hints);\r
+  }\r
+\r
+  public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException {\r
+    return decode(bits, null);\r
   }\r
 \r
   /**\r
    * <p>Decodes a QR Code represented as a {@link BitMatrix}. A 1 or "true" is taken to mean a black module.</p>\r
    *\r
    * @param bits booleans representing white/black QR Code modules\r
-   * @return text encoded within the QR Code\r
-   * @throws ReaderException if the QR Code cannot be decoded\r
+   * @return text and bytes encoded within the QR Code\r
+   * @throws FormatException if the QR Code cannot be decoded\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  public String decode(BitMatrix bits) throws ReaderException {\r
+  public DecoderResult decode(BitMatrix bits, Hashtable hints) throws FormatException, ChecksumException {\r
 \r
     // Construct a parser and read version, error-correction level\r
     BitMatrixParser parser = new BitMatrixParser(bits);\r
@@ -96,7 +112,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, hints);\r
   }\r
 \r
   /**\r
@@ -105,9 +121,9 @@ public final class Decoder {
    *\r
    * @param codewordBytes data and error correction codewords\r
    * @param numDataCodewords number of codewords that are data bytes\r
-   * @throws ReaderException if error correction fails\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException {\r
+  private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {\r
     int numCodewords = codewordBytes.length;\r
     // First read into an array of ints\r
     int[] codewordsInts = new int[numCodewords];\r
@@ -118,7 +134,7 @@ public final class Decoder {
     try {\r
       rsDecoder.decode(codewordsInts, numECCodewords);\r
     } catch (ReedSolomonException rse) {\r
-      throw new ReaderException(rse.toString());\r
+      throw ChecksumException.getChecksumInstance();\r
     }\r
     // Copy back into array of bytes -- only need to worry about the bytes that were data\r
     // We don't care about errors in the error-correction codewords\r