Workaround for codes that fail to include (required) final TERMINATOR mode indicator
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / FormatInformation.java
index c72154a..c257f09 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.google.zxing.qrcode.decoder;
 
+import com.google.zxing.ReaderException;
+
 /**
  * <p>Encapsulates a QR Code's format information, including the data mask used and
  * error correction level.</p>
@@ -31,7 +33,7 @@ final class FormatInformation {
   /**
    * See ISO 18004:2006, Annex C, Table C.1
    */
-  private static final int[][] FORMAT_INFO_DECODE_LOOKUP = new int[][]{
+  private static final int[][] FORMAT_INFO_DECODE_LOOKUP = {
       {0x5412, 0x00},
       {0x5125, 0x01},
       {0x5E7C, 0x02},
@@ -66,14 +68,16 @@ final class FormatInformation {
       {0x2BED, 0x1F},
   };
 
-  /** Offset i holds the number of 1 bits in the binary representation of i */
+  /**
+   * Offset i holds the number of 1 bits in the binary representation of i
+   */
   private static final int[] BITS_SET_IN_HALF_BYTE =
       new int[]{0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
 
   private final ErrorCorrectionLevel errorCorrectionLevel;
   private final byte dataMask;
 
-  private FormatInformation(int formatInfo) {
+  private FormatInformation(int formatInfo) throws ReaderException {
     // Bits 3,4
     errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03);
     // Bottom 3 bits
@@ -83,22 +87,21 @@ final class FormatInformation {
   static int numBitsDiffering(int a, int b) {
     a ^= b; // a now has a 1 bit exactly where its bit differs with b's
     // Count bits set quickly with a series of lookups:
-    return  BITS_SET_IN_HALF_BYTE[a & 0x0F] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 4 & 0x0F)] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 8 & 0x0F)] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 12 & 0x0F)] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 16 & 0x0F)] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 20 & 0x0F)] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 24 & 0x0F)] +
-            BITS_SET_IN_HALF_BYTE[(a >>> 28 & 0x0F)];
+    return BITS_SET_IN_HALF_BYTE[a & 0x0F] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 4 & 0x0F)] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 8 & 0x0F)] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 12 & 0x0F)] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 16 & 0x0F)] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 20 & 0x0F)] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 24 & 0x0F)] +
+        BITS_SET_IN_HALF_BYTE[(a >>> 28 & 0x0F)];
   }
 
   /**
-   *
    * @param rawFormatInfo
    * @return
    */
-  static FormatInformation decodeFormatInformation(int rawFormatInfo) {
+  static FormatInformation decodeFormatInformation(int rawFormatInfo) throws ReaderException {
     FormatInformation formatInfo = doDecodeFormatInformation(rawFormatInfo);
     if (formatInfo != null) {
       return formatInfo;
@@ -109,7 +112,7 @@ final class FormatInformation {
     return doDecodeFormatInformation(rawFormatInfo ^ FORMAT_INFO_MASK_QR);
   }
 
-  private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) {
+  private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) throws ReaderException {
     // Unmask:
     int unmaskedFormatInfo = rawFormatInfo ^ FORMAT_INFO_MASK_QR;
     // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing