/*\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
/**\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
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
}\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
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