More small changes from code inspection
[zxing.git] / core / src / com / google / zxing / datamatrix / decoder / BitMatrixParser.java
index f54e9c1..fe48302 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
@@ -26,8 +26,7 @@ final class BitMatrixParser {
 \r
   private final BitMatrix mappingBitMatrix;\r
   private final BitMatrix readMappingMatrix;\r
-  private Version version;\r
-//  private FormatInformation parsedFormatInfo;\r
+  private final Version version;\r
 \r
   /**\r
    * @param bitMatrix {@link BitMatrix} to parse\r
@@ -36,7 +35,7 @@ final class BitMatrixParser {
   BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {\r
     int dimension = bitMatrix.getDimension();\r
     if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) {\r
-      throw new ReaderException("Invalid dimension (" + dimension + ")  Must be 0 mod 2 and >= 10 and <= 144");\r
+      throw ReaderException.getInstance();\r
     }\r
     \r
     version = readVersion(bitMatrix);\r
@@ -98,19 +97,23 @@ final class BitMatrixParser {
       // Check the four corner cases\r
       if ((row == numRows) && (column == 0) && !corner1Read) {\r
         result[resultOffset++] = (byte) readCorner1(numRows, numColumns);\r
-        row -= 2; column +=2;\r
+        row -= 2;\r
+        column +=2;\r
         corner1Read = true;\r
       } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) {\r
         result[resultOffset++] = (byte) readCorner2(numRows, numColumns);\r
-        row -= 2; column +=2;\r
+        row -= 2;\r
+        column +=2;\r
         corner2Read = true;\r
       } else if ((row == numRows+4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) {\r
         result[resultOffset++] = (byte) readCorner3(numRows, numColumns);\r
-        row -= 2; column +=2;\r
+        row -= 2;\r
+        column +=2;\r
         corner3Read = true;\r
       } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) {\r
         result[resultOffset++] = (byte) readCorner4(numRows, numColumns);\r
-        row -= 2; column +=2;\r
+        row -= 2;\r
+        column +=2;\r
         corner4Read = true;\r
       } else {\r
         // Sweep upward diagonally to the right\r
@@ -118,29 +121,33 @@ final class BitMatrixParser {
           if ((row < numRows) && (column >= 0) && !readMappingMatrix.get(row, column)) {\r
             result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns);\r
           }\r
-          row -= 2; column +=2;\r
+          row -= 2;\r
+          column +=2;\r
         } while ((row >= 0) && (column < numColumns));\r
-        row += 1; column +=3;\r
+        row += 1;\r
+        column +=3;\r
         \r
-        // Sweep downward giagonally to the left\r
+        // Sweep downward diagonally to the left\r
         do {\r
           if ((row >= 0) && (column < numColumns) && !readMappingMatrix.get(row, column)) {\r
              result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns);\r
           }\r
-          row += 2; column -=2;\r
+          row += 2;\r
+          column -=2;\r
         } while ((row < numRows) && (column >= 0));\r
-        row += 3; column +=1;\r
+        row += 3;\r
+        column +=1;\r
       }\r
     } while ((row < numRows) || (column < numColumns));\r
 \r
     if (resultOffset != version.getTotalCodewords()) {\r
-      throw new ReaderException("Did not read all codewords");\r
+      throw ReaderException.getInstance();\r
     }\r
     return result;\r
   }\r
   \r
   /**\r
-   * <p>Reads a bit of the mapping matrix accounting for boundry wrapping.</p>\r
+   * <p>Reads a bit of the mapping matrix accounting for boundary wrapping.</p>\r
    * \r
    * @param row Row to read in the mapping matrix\r
    * @param column Column to read in the mapping matrix\r
@@ -149,7 +156,7 @@ final class BitMatrixParser {
    * @return value of the given bit in the mapping matrix\r
    */\r
   boolean readModule(int row, int column, int numRows, int numColumns) {\r
-    // Adjust the row and column indicies based on boundry wrapping\r
+    // Adjust the row and column indices based on boundary wrapping\r
     if (row < 0) {\r
       row += numRows;\r
       column += 4 - ((numRows + 4) & 0x07);\r
@@ -417,22 +424,22 @@ final class BitMatrixParser {
     // TODO(bbrown): Make this work with rectangular codes\r
     BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionRow);\r
     for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) {\r
+      int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;\r
       for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) {\r
+        int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;\r
         for (int i = 0; i < dataRegionSizeRows; ++i) {\r
+          int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;\r
+          int writeRowOffset = dataRegionRowOffset + i;\r
           for (int j = 0; j < dataRegionSizeColumns; ++j) {\r
-            int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;\r
             int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;\r
-            int writeRowOffset = dataRegionRow * dataRegionSizeRows + i;\r
-            int writeColumnOffset = dataRegionColumn * dataRegionSizeColumns + j;\r
-\r
             if (bitMatrix.get(readRowOffset, readColumnOffset)) {\r
+              int writeColumnOffset = dataRegionColumnOffset + j;\r
               bitMatrixWithoutAlignment.set(writeRowOffset, writeColumnOffset);\r
             }\r
           }\r
         }\r
       }\r
     }\r
-    \r
     return bitMatrixWithoutAlignment;\r
   }\r
 \r