Add minimal support for FNC1 mode in QR Code
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / DataMask.java
index 68f1b67..7f1aec7 100755 (executable)
@@ -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
 package com.google.zxing.qrcode.decoder;\r
 \r
 /**\r
- * Encapsulates data masks for the data bits in a QR code, per ISO 18004:2006 6.8. Implementations\r
+ * <p>Encapsulates data masks for the data bits in a QR code, per ISO 18004:2006 6.8. Implementations\r
  * of this class can un-mask a raw BitMatrix. For simplicity, they will unmask the entire BitMatrix,\r
  * including areas used for finder patterns, timing patterns, etc. These areas should be unused\r
- * after the point they are unmasked anyway.\r
+ * after the point they are unmasked anyway.</p>\r
  *\r
- * Note that the diagram in section 6.8.1 is misleading since it indicates that i is column position\r
- * and j is row position. In fact, as the text says, i is row position and j is column position.\r
+ * <p>Note that the diagram in section 6.8.1 is misleading since it indicates that i is column position\r
+ * and j is row position. In fact, as the text says, i is row position and j is column position.</p>\r
  *\r
  * @author srowen@google.com (Sean Owen)\r
  */\r
@@ -32,7 +32,7 @@ abstract class DataMask {
   /**\r
    * See ISO 18004:2006 6.8.1\r
    */\r
-  private static final DataMask[] DATA_MASKS = new DataMask[]{\r
+  private static final DataMask[] DATA_MASKS = {\r
       new DataMask000(),\r
       new DataMask001(),\r
       new DataMask010(),\r
@@ -46,8 +46,20 @@ abstract class DataMask {
   private DataMask() {\r
   }\r
 \r
+  /**\r
+   * <p>Implementations of this method reverse the data masking process applied to a QR Code and\r
+   * make its bits ready to read.</p>\r
+   *\r
+   * @param bits representation of QR Code bits from {@link com.google.zxing.common.BitMatrix#getBits()}\r
+   * @param dimension dimension of QR Code, represented by bits, being unmasked\r
+   */\r
   abstract void unmaskBitMatrix(int[] bits, int dimension);\r
 \r
+  /**\r
+   * @param reference a value between 0 and 7 indicating one of the eight possible\r
+   * data mask patterns a QR Code may use\r
+   * @return {@link DataMask} encapsulating the data mask pattern\r
+   */\r
   static DataMask forReference(int reference) {\r
     if (reference < 0 || reference > 7) {\r
       throw new IllegalArgumentException();\r
@@ -72,7 +84,7 @@ abstract class DataMask {
   }\r
 \r
   /**\r
-   * 001: mask bits for which j mod 2 == 0\r
+   * 001: mask bits for which i mod 2 == 0\r
    */\r
   private static class DataMask001 extends DataMask {\r
     void unmaskBitMatrix(int[] bits, int dimension) {\r
@@ -153,9 +165,9 @@ abstract class DataMask {
       int count = 0;\r
       int offset = 0;\r
       for (int j = 0; j < dimension; j++) {\r
-        int jComponent = j / 3;\r
+        int jComponentParity = (j / 3) & 0x01;\r
         for (int i = 0; i < dimension; i++) {\r
-          if (((i >> 1 + jComponent) & 0x01) == 0) {\r
+          if (((i >> 1) & 0x01) == jComponentParity) {\r
             bitMask |= 1 << count;\r
           }\r
           if (++count == 32) {\r